| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 virtual void ListenerDestroyed() OVERRIDE; | 68 virtual void ListenerDestroyed() OVERRIDE; |
| 69 | 69 |
| 70 // Callback from ObjC bridge. | 70 // Callback from ObjC bridge. |
| 71 void FileWasSelected(NSSavePanel* dialog, | 71 void FileWasSelected(NSSavePanel* dialog, |
| 72 NSWindow* parent_window, | 72 NSWindow* parent_window, |
| 73 bool was_cancelled, | 73 bool was_cancelled, |
| 74 bool is_multi, | 74 bool is_multi, |
| 75 const std::vector<base::FilePath>& files, | 75 const std::vector<base::FilePath>& files, |
| 76 int index); | 76 int index); |
| 77 | 77 |
| 78 bool ShouldEnableFilename(NSSavePanel* dialog, NSString* filename); | |
| 79 | |
| 80 protected: | 78 protected: |
| 81 // SelectFileDialog implementation. | 79 // SelectFileDialog implementation. |
| 82 // |params| is user data we pass back via the Listener interface. | 80 // |params| is user data we pass back via the Listener interface. |
| 83 virtual void SelectFileImpl( | 81 virtual void SelectFileImpl( |
| 84 Type type, | 82 Type type, |
| 85 const base::string16& title, | 83 const base::string16& title, |
| 86 const base::FilePath& default_path, | 84 const base::FilePath& default_path, |
| 87 const FileTypeInfo* file_types, | 85 const FileTypeInfo* file_types, |
| 88 int file_type_index, | 86 int file_type_index, |
| 89 const base::FilePath::StringType& default_extension, | 87 const base::FilePath::StringType& default_extension, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 listener_->FileSelectionCanceled(params); | 150 listener_->FileSelectionCanceled(params); |
| 153 } else { | 151 } else { |
| 154 if (is_multi) { | 152 if (is_multi) { |
| 155 listener_->MultiFilesSelected(files, params); | 153 listener_->MultiFilesSelected(files, params); |
| 156 } else { | 154 } else { |
| 157 listener_->FileSelected(files[0], index, params); | 155 listener_->FileSelected(files[0], index, params); |
| 158 } | 156 } |
| 159 } | 157 } |
| 160 } | 158 } |
| 161 | 159 |
| 162 bool SelectFileDialogImpl::ShouldEnableFilename(NSSavePanel* dialog, | |
| 163 NSString* filename) { | |
| 164 // If this is a single/multiple open file dialog, disable selecting packages. | |
| 165 if (type_map_[dialog] != SELECT_OPEN_FILE && | |
| 166 type_map_[dialog] != SELECT_OPEN_MULTI_FILE) | |
| 167 return true; | |
| 168 | |
| 169 return ![[NSWorkspace sharedWorkspace] isFilePackageAtPath:filename]; | |
| 170 } | |
| 171 | |
| 172 void SelectFileDialogImpl::SelectFileImpl( | 160 void SelectFileDialogImpl::SelectFileImpl( |
| 173 Type type, | 161 Type type, |
| 174 const base::string16& title, | 162 const base::string16& title, |
| 175 const base::FilePath& default_path, | 163 const base::FilePath& default_path, |
| 176 const FileTypeInfo* file_types, | 164 const FileTypeInfo* file_types, |
| 177 int file_type_index, | 165 int file_type_index, |
| 178 const base::FilePath::StringType& default_extension, | 166 const base::FilePath::StringType& default_extension, |
| 179 gfx::NativeWindow owning_window, | 167 gfx::NativeWindow owning_window, |
| 180 void* params) { | 168 void* params) { |
| 181 DCHECK(type == SELECT_FOLDER || | 169 DCHECK(type == SELECT_FOLDER || |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 selectFileDialogImpl_->FileWasSelected(panel, | 408 selectFileDialogImpl_->FileWasSelected(panel, |
| 421 parentWindow, | 409 parentWindow, |
| 422 did_cancel, | 410 did_cancel, |
| 423 isMulti, | 411 isMulti, |
| 424 paths, | 412 paths, |
| 425 index); | 413 index); |
| 426 [panel release]; | 414 [panel release]; |
| 427 } | 415 } |
| 428 | 416 |
| 429 - (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url { | 417 - (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url { |
| 430 if (![url isFileURL]) | 418 return [url isFileURL]; |
| 431 return NO; | |
| 432 return selectFileDialogImpl_->ShouldEnableFilename(sender, [url path]); | |
| 433 } | 419 } |
| 434 | 420 |
| 435 @end | 421 @end |
| 436 | 422 |
| 437 namespace ui { | 423 namespace ui { |
| 438 | 424 |
| 439 SelectFileDialog* CreateMacSelectFileDialog( | 425 SelectFileDialog* CreateMacSelectFileDialog( |
| 440 SelectFileDialog::Listener* listener, | 426 SelectFileDialog::Listener* listener, |
| 441 SelectFilePolicy* policy) { | 427 SelectFilePolicy* policy) { |
| 442 return new SelectFileDialogImpl(listener, policy); | 428 return new SelectFileDialogImpl(listener, policy); |
| 443 } | 429 } |
| 444 | 430 |
| 445 } // namespace ui | 431 } // namespace ui |
| OLD | NEW |