Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: ui/base/dialogs/select_file_dialog_mac.mm

Issue 10829053: mac: Switch to "new" (10.6) block-based panel apis (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/dialogs/select_file_dialog_mac.mm
diff --git a/ui/base/dialogs/select_file_dialog_mac.mm b/ui/base/dialogs/select_file_dialog_mac.mm
index 11c0dd53c54a50c688dd8cd223bcd9378a1e82d8..5ad303850e89c29e2ea55d03e446c5ebf388d910 100644
--- a/ui/base/dialogs/select_file_dialog_mac.mm
+++ b/ui/base/dialogs/select_file_dialog_mac.mm
@@ -48,8 +48,9 @@ class SelectFileDialogImpl;
- (id)initWithSelectFileDialogImpl:(SelectFileDialogImpl*)s;
- (void)endedPanel:(NSSavePanel*)panel
- withReturn:(int)returnCode
- context:(void*)context;
+ didCancel:(bool)did_cancel
+ type:(ui::SelectFileDialog::Type)type
+ parentWindow:(NSWindow*)parentWindow;
// NSSavePanel delegate method
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename;
@@ -77,11 +78,6 @@ class SelectFileDialogImpl : public ui::SelectFileDialog {
bool ShouldEnableFilename(NSSavePanel* dialog, NSString* filename);
- struct SheetContext {
- Type type;
- NSWindow* owning_window;
- };
-
protected:
// SelectFileDialog implementation.
// |params| is user data we pass back via the Listener interface.
@@ -151,7 +147,7 @@ void SelectFileDialogImpl::FileWasSelected(NSSavePanel* dialog,
if (!listener_)
return;
- if (was_cancelled) {
+ if (was_cancelled || files.empty()) {
listener_->FileSelectionCanceled(params);
} else {
if (is_multi) {
@@ -254,28 +250,22 @@ void SelectFileDialogImpl::SelectFileImpl(
file_types ? file_types->extensions.size() > 1 : true;
if (!default_extension.empty())
- [dialog setRequiredFileType:base::SysUTF8ToNSString(default_extension)];
+ [dialog setAllowedFileTypes:@[base::SysUTF8ToNSString(default_extension)]];
params_map_[dialog] = params;
type_map_[dialog] = type;
- SheetContext* context = new SheetContext;
-
- // |context| should never be NULL, but we are seeing indications otherwise.
- // This CHECK is here to confirm if we are actually getting NULL
- // |context|s. http://crbug.com/58959
- CHECK(context);
- context->type = type;
- context->owning_window = owning_window;
-
if (type == SELECT_SAVEAS_FILE) {
[dialog setCanSelectHiddenExtension:YES];
- [dialog beginSheetForDirectory:default_dir
- file:default_filename
- modalForWindow:owning_window
- modalDelegate:bridge_.get()
- didEndSelector:@selector(endedPanel:withReturn:context:)
- contextInfo:context];
+ [dialog setDirectoryURL:[NSURL fileURLWithPath:default_dir]];
+ [dialog setNameFieldStringValue:default_filename];
+ [dialog beginSheetModalForWindow:owning_window
+ completionHandler:^(NSInteger result) {
+ [bridge_.get() endedPanel:dialog
+ didCancel:result != NSFileHandlingPanelOKButton
+ type:type
+ parentWindow:owning_window];
+ }];
Avi (use Gerrit) 2012/07/27 14:36:01 This code (from -setDirectoryURL down to here)...
} else {
NSOpenPanel* open_dialog = (NSOpenPanel*)dialog;
@@ -296,13 +286,16 @@ void SelectFileDialogImpl::SelectFileImpl(
}
[open_dialog setDelegate:bridge_.get()];
- [open_dialog beginSheetForDirectory:default_dir
- file:default_filename
- types:allowed_file_types
- modalForWindow:owning_window
- modalDelegate:bridge_.get()
- didEndSelector:@selector(endedPanel:withReturn:context:)
- contextInfo:context];
+ [open_dialog setAllowedFileTypes:allowed_file_types];
+ [open_dialog setDirectoryURL:[NSURL fileURLWithPath:default_dir]];
+ [open_dialog setNameFieldStringValue:default_filename];
+ [open_dialog beginSheetModalForWindow:owning_window
+ completionHandler:^(NSInteger result) {
+ [bridge_.get() endedPanel:dialog
+ didCancel:result != NSFileHandlingPanelOKButton
+ type:type
+ parentWindow:owning_window];
+ }];
Avi (use Gerrit) 2012/07/27 14:36:01 ...and this code here are identical. Consolidate t
Nico 2012/07/27 14:48:43 Done.
}
}
@@ -374,28 +367,15 @@ bool SelectFileDialogImpl::HasMultipleFileTypeChoicesImpl() {
}
- (void)endedPanel:(NSSavePanel*)panel
- withReturn:(int)returnCode
- context:(void*)context {
- // |context| should never be NULL, but we are seeing indications otherwise.
- // This CHECK is here to confirm if we are actually getting NULL
- // |context|s. http://crbug.com/58959
- CHECK(context);
-
+ didCancel:(bool)did_cancel
+ type:(ui::SelectFileDialog::Type)type
+ parentWindow:(NSWindow*)parentWindow {
int index = 0;
- SelectFileDialogImpl::SheetContext* context_struct =
- (SelectFileDialogImpl::SheetContext*)context;
-
- ui::SelectFileDialog::Type type = context_struct->type;
- NSWindow* parentWindow = context_struct->owning_window;
- delete context_struct;
-
- bool isMulti = type == ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE;
-
std::vector<FilePath> paths;
- bool did_cancel = returnCode == NSCancelButton;
if (!did_cancel) {
if (type == ui::SelectFileDialog::SELECT_SAVEAS_FILE) {
- paths.push_back(FilePath(base::SysNSStringToUTF8([panel filename])));
+ if ([[panel URL] isFileURL])
+ paths.push_back(FilePath(base::SysNSStringToUTF8([[panel URL] path])));
NSView* accessoryView = [panel accessoryView];
if (accessoryView) {
@@ -409,12 +389,14 @@ bool SelectFileDialogImpl::HasMultipleFileTypeChoicesImpl() {
}
} else {
CHECK([panel isKindOfClass:[NSOpenPanel class]]);
- NSArray* filenames = [static_cast<NSOpenPanel*>(panel) filenames];
- for (NSString* filename in filenames)
- paths.push_back(FilePath(base::SysNSStringToUTF8(filename)));
+ NSArray* urls = [static_cast<NSOpenPanel*>(panel) URLs];
+ for (NSURL* url in urls)
+ if ([url isFileURL])
+ paths.push_back(FilePath(base::SysNSStringToUTF8([url path])));
}
}
+ bool isMulti = type == ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE;
selectFileDialogImpl_->FileWasSelected(panel,
parentWindow,
did_cancel,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698