From ca1b8ada99d504f36f1810a7434639874ba7b147 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 18 May 2013 10:47:06 +0800 Subject: [PATCH] dialog.showMessageBox doesn't require window as parameter any more. --- browser/api/atom_api_dialog.cc | 32 ++++++++++++-------------------- browser/api/lib/dialog.coffee | 8 +++----- browser/message_box.h | 5 +---- browser/message_box_mac.mm | 3 +-- 4 files changed, 17 insertions(+), 31 deletions(-) diff --git a/browser/api/atom_api_dialog.cc b/browser/api/atom_api_dialog.cc index 2fa01fd114f..6ba1e64d08d 100644 --- a/browser/api/atom_api_dialog.cc +++ b/browser/api/atom_api_dialog.cc @@ -28,34 +28,26 @@ base::FilePath V8ValueToFilePath(v8::Handle path) { v8::Handle ShowMessageBox(const v8::Arguments &args) { v8::HandleScope scope; - if (!args[0]->IsObject() || // window - !args[1]->IsNumber() || // type - !args[2]->IsArray() || // buttons - !args[3]->IsString() || // title - !args[4]->IsString() || // message - !args[5]->IsString()) // detail + if (!args[0]->IsNumber() || // type + !args[1]->IsArray() || // buttons + !args[2]->IsString() || // title + !args[3]->IsString() || // message + !args[4]->IsString()) // detail return node::ThrowTypeError("Bad argument"); - Window* window = Window::Unwrap(args[0]->ToObject()); - if (!window || !window->window()) - return node::ThrowError("Invalid window"); - - gfx::NativeWindow owning_window = window->window()->GetNativeWindow(); - - MessageBoxType type = (MessageBoxType)(args[1]->IntegerValue()); + MessageBoxType type = (MessageBoxType)(args[0]->IntegerValue()); std::vector buttons; - v8::Handle v8_buttons = v8::Handle::Cast(args[2]); + v8::Handle v8_buttons = v8::Handle::Cast(args[1]); for (uint32_t i = 0; i < v8_buttons->Length(); ++i) buttons.push_back(*v8::String::Utf8Value(v8_buttons->Get(i))); - std::string title(*v8::String::Utf8Value(args[3])); - std::string message(*v8::String::Utf8Value(args[4])); - std::string detail(*v8::String::Utf8Value(args[5])); + std::string title(*v8::String::Utf8Value(args[2])); + std::string message(*v8::String::Utf8Value(args[3])); + std::string detail(*v8::String::Utf8Value(args[4])); - int result = atom::ShowMessageBox( - owning_window, type, buttons, title, message, detail); - return v8::Integer::New(result); + int chosen = atom::ShowMessageBox(type, buttons, title, message, detail); + return scope.Close(v8::Integer::New(chosen)); } FileDialog::FileDialog(v8::Handle wrapper) diff --git a/browser/api/lib/dialog.coffee b/browser/api/lib/dialog.coffee index f87884c9e58..afd98d9a0ba 100644 --- a/browser/api/lib/dialog.coffee +++ b/browser/api/lib/dialog.coffee @@ -68,10 +68,8 @@ module.exports = openMultiFiles: (args...) -> selectFileWrap args..., 4, 'Open Files' - showMessageBox: (window, options) -> - throw new TypeError('Need Window object') unless window.constructor is BrowserWindow - - options = {} unless options? + showMessageBox: (options) -> + options = type: 'none' unless options? options.type = options.type ? 'none' options.type = messageBoxTypes.indexOf options.type throw new TypeError('Invalid message box type') unless options.type > -1 @@ -82,7 +80,7 @@ module.exports = options.message = options.message ? '' options.detail = options.detail ? '' - binding.showMessageBox window, options.type, options.buttons, + binding.showMessageBox options.type, options.buttons, String(options.title), String(options.message), String(options.detail) diff --git a/browser/message_box.h b/browser/message_box.h index 65ca6da3f9b..eef4180d633 100644 --- a/browser/message_box.h +++ b/browser/message_box.h @@ -8,8 +8,6 @@ #include #include -#include "ui/gfx/native_widget_types.h" - namespace atom { enum MessageBoxType { @@ -18,8 +16,7 @@ enum MessageBoxType { MESSAGE_BOX_TYPE_WARNING }; -int ShowMessageBox(gfx::NativeWindow parent, - MessageBoxType type, +int ShowMessageBox(MessageBoxType type, const std::vector& buttons, const std::string& title, const std::string& message, diff --git a/browser/message_box_mac.mm b/browser/message_box_mac.mm index d03fe0efa75..79dba234eaa 100644 --- a/browser/message_box_mac.mm +++ b/browser/message_box_mac.mm @@ -10,8 +10,7 @@ namespace atom { -int ShowMessageBox(gfx::NativeWindow parent, - MessageBoxType type, +int ShowMessageBox(MessageBoxType type, const std::vector& buttons, const std::string& title, const std::string& message,