mac: Make ShowOpenDialog able to be shown as sheet.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 23 Sep 2013 08:27:22 +0000 (16:27 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 23 Sep 2013 08:27:22 +0000 (16:27 +0800)
browser/api/atom_api_dialog.cc
browser/ui/file_dialog.h
browser/ui/file_dialog_mac.mm

index 298cba4..75d31d0 100644 (file)
@@ -124,7 +124,11 @@ v8::Handle<v8::Value> ShowOpenDialog(const v8::Arguments &args) {
   int properties = args[2]->IntegerValue();
 
   std::vector<base::FilePath> 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<v8::Array> result = v8::Array::New(paths.size());
index 67b526f..77e5ac4 100644 (file)
@@ -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<base::FilePath>* paths);
 
-bool ShowSaveDialog(atom::NativeWindow* window,
+bool ShowSaveDialog(atom::NativeWindow* parent_window,
                     const std::string& title,
                     const base::FilePath& default_path,
                     base::FilePath* path);
index d51be89..54a901c 100644 (file)
@@ -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<base::FilePath>* 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];