OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/shell_dialogs/select_file_dialog.h" | 5 #include "ui/shell_dialogs/select_file_dialog.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 #include <CoreServices/CoreServices.h> | 8 #include <CoreServices/CoreServices.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 SelectFileDialogImpl* selectFileDialogImpl_; // WEAK; owns us | 45 SelectFileDialogImpl* selectFileDialogImpl_; // WEAK; owns us |
46 } | 46 } |
47 | 47 |
48 - (id)initWithSelectFileDialogImpl:(SelectFileDialogImpl*)s; | 48 - (id)initWithSelectFileDialogImpl:(SelectFileDialogImpl*)s; |
49 - (void)endedPanel:(NSSavePanel*)panel | 49 - (void)endedPanel:(NSSavePanel*)panel |
50 didCancel:(bool)did_cancel | 50 didCancel:(bool)did_cancel |
51 type:(ui::SelectFileDialog::Type)type | 51 type:(ui::SelectFileDialog::Type)type |
52 parentWindow:(NSWindow*)parentWindow; | 52 parentWindow:(NSWindow*)parentWindow; |
53 | 53 |
54 // NSSavePanel delegate method | 54 // NSSavePanel delegate method |
55 - (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename; | 55 - (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url; |
56 | 56 |
57 @end | 57 @end |
58 | 58 |
59 // Implementation of SelectFileDialog that shows Cocoa dialogs for choosing a | 59 // Implementation of SelectFileDialog that shows Cocoa dialogs for choosing a |
60 // file or folder. | 60 // file or folder. |
61 class SelectFileDialogImpl : public ui::SelectFileDialog { | 61 class SelectFileDialogImpl : public ui::SelectFileDialog { |
62 public: | 62 public: |
63 explicit SelectFileDialogImpl(Listener* listener, | 63 explicit SelectFileDialogImpl(Listener* listener, |
64 ui::SelectFilePolicy* policy); | 64 ui::SelectFilePolicy* policy); |
65 | 65 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (is_multi) { | 154 if (is_multi) { |
155 listener_->MultiFilesSelected(files, params); | 155 listener_->MultiFilesSelected(files, params); |
156 } else { | 156 } else { |
157 listener_->FileSelected(files[0], index, params); | 157 listener_->FileSelected(files[0], index, params); |
158 } | 158 } |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 bool SelectFileDialogImpl::ShouldEnableFilename(NSSavePanel* dialog, | 162 bool SelectFileDialogImpl::ShouldEnableFilename(NSSavePanel* dialog, |
163 NSString* filename) { | 163 NSString* filename) { |
164 // If this is a single open file dialog, disable selecting packages. | 164 // If this is a single/multiple open file dialog, disable selecting packages. |
165 if (type_map_[dialog] != SELECT_OPEN_FILE) | 165 if (type_map_[dialog] != SELECT_OPEN_FILE && |
| 166 type_map_[dialog] != SELECT_OPEN_MULTI_FILE) |
166 return true; | 167 return true; |
167 | 168 |
168 return ![[NSWorkspace sharedWorkspace] isFilePackageAtPath:filename]; | 169 return ![[NSWorkspace sharedWorkspace] isFilePackageAtPath:filename]; |
169 } | 170 } |
170 | 171 |
171 void SelectFileDialogImpl::SelectFileImpl( | 172 void SelectFileDialogImpl::SelectFileImpl( |
172 Type type, | 173 Type type, |
173 const base::string16& title, | 174 const base::string16& title, |
174 const base::FilePath& default_path, | 175 const base::FilePath& default_path, |
175 const FileTypeInfo* file_types, | 176 const FileTypeInfo* file_types, |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 bool isMulti = type == ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE; | 419 bool isMulti = type == ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE; |
419 selectFileDialogImpl_->FileWasSelected(panel, | 420 selectFileDialogImpl_->FileWasSelected(panel, |
420 parentWindow, | 421 parentWindow, |
421 did_cancel, | 422 did_cancel, |
422 isMulti, | 423 isMulti, |
423 paths, | 424 paths, |
424 index); | 425 index); |
425 [panel release]; | 426 [panel release]; |
426 } | 427 } |
427 | 428 |
428 - (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename { | 429 - (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url { |
429 return selectFileDialogImpl_->ShouldEnableFilename(sender, filename); | 430 if (![url isFileURL]) |
| 431 return NO; |
| 432 return selectFileDialogImpl_->ShouldEnableFilename(sender, [url path]); |
430 } | 433 } |
431 | 434 |
432 @end | 435 @end |
433 | 436 |
434 namespace ui { | 437 namespace ui { |
435 | 438 |
436 SelectFileDialog* CreateMacSelectFileDialog( | 439 SelectFileDialog* CreateMacSelectFileDialog( |
437 SelectFileDialog::Listener* listener, | 440 SelectFileDialog::Listener* listener, |
438 SelectFilePolicy* policy) { | 441 SelectFilePolicy* policy) { |
439 return new SelectFileDialogImpl(listener, policy); | 442 return new SelectFileDialogImpl(listener, policy); |
440 } | 443 } |
441 | 444 |
442 } // namespace ui | 445 } // namespace ui |
OLD | NEW |