From 76ac8f2719725643939065177130c5df883953cb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Sep 2013 16:36:33 +0800 Subject: [PATCH] Enable taking window as parameter in dialog.showOpenDialog. --- browser/api/atom_api_dialog.cc | 11 ++++++++++- browser/api/lib/dialog.coffee | 13 +++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/browser/api/atom_api_dialog.cc b/browser/api/atom_api_dialog.cc index 75d31d0..89b83ce 100644 --- a/browser/api/atom_api_dialog.cc +++ b/browser/api/atom_api_dialog.cc @@ -119,12 +119,21 @@ v8::Handle 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(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 paths; - if (!file_dialog::ShowOpenDialog(NULL, + if (!file_dialog::ShowOpenDialog(native_window, title, default_path, properties, diff --git a/browser/api/lib/dialog.coffee b/browser/api/lib/dialog.coffee index 7011de2..760d633 100644 --- a/browser/api/lib/dialog.coffee +++ b/browser/api/lib/dialog.coffee @@ -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 -- 2.7.4