From a4262bc39d98870f87107c83d33ca1cddbab0127 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Sep 2013 16:27:22 +0800 Subject: [PATCH] mac: Make ShowOpenDialog able to be shown as sheet. --- browser/api/atom_api_dialog.cc | 6 +++++- browser/ui/file_dialog.h | 5 +++-- browser/ui/file_dialog_mac.mm | 20 ++++++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/browser/api/atom_api_dialog.cc b/browser/api/atom_api_dialog.cc index 298cba49ca..75d31d088f 100644 --- a/browser/api/atom_api_dialog.cc +++ b/browser/api/atom_api_dialog.cc @@ -124,7 +124,11 @@ v8::Handle ShowOpenDialog(const v8::Arguments &args) { int properties = args[2]->IntegerValue(); std::vector paths; - if (!file_dialog::ShowOpenDialog(title, default_path, properties, &paths)) + if (!file_dialog::ShowOpenDialog(NULL, + title, + default_path, + properties, + &paths)) return v8::Undefined(); v8::Handle result = v8::Array::New(paths.size()); diff --git a/browser/ui/file_dialog.h b/browser/ui/file_dialog.h index 67b526f785..77e5ac4607 100644 --- a/browser/ui/file_dialog.h +++ b/browser/ui/file_dialog.h @@ -23,12 +23,13 @@ enum FileDialogProperty { FILE_DIALOG_CREATE_DIRECTORY = 8, }; -bool ShowOpenDialog(const std::string& title, +bool ShowOpenDialog(atom::NativeWindow* parent_window, + const std::string& title, const base::FilePath& default_path, int properties, std::vector* paths); -bool ShowSaveDialog(atom::NativeWindow* window, +bool ShowSaveDialog(atom::NativeWindow* parent_window, const std::string& title, const base::FilePath& default_path, base::FilePath* path); diff --git a/browser/ui/file_dialog_mac.mm b/browser/ui/file_dialog_mac.mm index d51be89a23..54a901cf2a 100644 --- a/browser/ui/file_dialog_mac.mm +++ b/browser/ui/file_dialog_mac.mm @@ -43,7 +43,8 @@ void SetupDialog(NSSavePanel* dialog, } // namespace -bool ShowOpenDialog(const std::string& title, +bool ShowOpenDialog(atom::NativeWindow* parent_window, + const std::string& title, const base::FilePath& default_path, int properties, std::vector* paths) { @@ -60,7 +61,22 @@ bool ShowOpenDialog(const std::string& title, if (properties & FILE_DIALOG_MULTI_SELECTIONS) [dialog setAllowsMultipleSelection:YES]; - if ([dialog runModal] == NSFileHandlingPanelCancelButton) + __block int chosen = -1; + + if (parent_window == NULL) { + chosen = [dialog runModal]; + } else { + NSWindow* window = parent_window->GetNativeWindow(); + + [dialog beginSheetModalForWindow:window + completionHandler:^(NSInteger c) { + chosen = c; + [NSApp stopModal]; + }]; + [NSApp runModalForWindow:window]; + } + + if (chosen == NSFileHandlingPanelCancelButton) return false; NSArray* urls = [dialog URLs];