]> khamidou — GitHub mirrors - electron.git/commitdiff
Enable taking window as parameter in dialog.showOpenDialog.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 23 Sep 2013 08:36:33 +0000 (16:36 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 23 Sep 2013 08:36:33 +0000 (16:36 +0800)
browser/api/atom_api_dialog.cc
browser/api/lib/dialog.coffee

index 75d31d088fdde172976a0c80f72a8badff6cbe32..89b83ce9e2c15161e1a8d860e3fa7c5e7b5a7605 100644 (file)
@@ -119,12 +119,21 @@ v8::Handle<v8::Value> ShowOpenDialog(const v8::Arguments &args) {
       !args[2]->IsNumber())    // properties
     return node::ThrowTypeError("Bad argument");
 
+  NativeWindow* native_window = NULL;
+  if (args[3]->IsObject()) {
+    Window* window = Window::Unwrap<Window>(args[3]->ToObject());
+    if (!window || !window->window())
+      return node::ThrowError("Invalid window");
+
+    native_window = window->window();
+  }
+
   std::string title(*v8::String::Utf8Value(args[0]));
   base::FilePath default_path(V8ValueToFilePath(args[1]));
   int properties = args[2]->IntegerValue();
 
   std::vector<base::FilePath> paths;
-  if (!file_dialog::ShowOpenDialog(NULL,
+  if (!file_dialog::ShowOpenDialog(native_window,
                                    title,
                                    default_path,
                                    properties,
index 7011de205b31b91e17b5e998cb282f34ba5b08ad..760d633be0e850dea79f09503524cf63d0770a6a 100644 (file)
@@ -7,7 +7,13 @@ fileDialogProperties =
 messageBoxTypes = ['none', 'info', 'warning']
 
 module.exports =
-  showOpenDialog: (options) ->
+  showOpenDialog: (window, options, callback) ->
+    if window? and window.constructor isnt BrowserWindow
+      # Shift.
+      callback = options
+      options = window
+      window = null
+
     options = title: 'Open', properties: ['openFile'] unless options?
     options.properties = options.properties ? ['openFile']
     throw new TypeError('Properties need to be array') unless Array.isArray options.properties
@@ -19,7 +25,10 @@ module.exports =
     options.title = options.title ? ''
     options.defaultPath = options.defaultPath ? ''
 
-    binding.showOpenDialog options.title, options.defaultPath, properties
+    binding.showOpenDialog options.title,
+                           options.defaultPath,
+                           properties,
+                           window
 
   showSaveDialog: (window, options) ->
     throw new TypeError('Invalid window') unless window?.constructor is BrowserWindow