From f1edd5f26f38e28c53b3e2d5148dcc9081d57a23 Mon Sep 17 00:00:00 2001 From: leethomas Date: Thu, 7 Jan 2016 20:46:45 -0800 Subject: [PATCH 1/7] :apple: add default button index for osx --- atom/browser/api/atom_api_dialog.cc | 7 ++++--- atom/browser/api/lib/dialog.coffee | 10 ++++++---- atom/browser/ui/message_box.h | 2 ++ atom/browser/ui/message_box_mac.mm | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/atom/browser/api/atom_api_dialog.cc b/atom/browser/api/atom_api_dialog.cc index 40ee4d0d9b51..e8c1ae3ba99f 100644 --- a/atom/browser/api/atom_api_dialog.cc +++ b/atom/browser/api/atom_api_dialog.cc @@ -41,6 +41,7 @@ namespace { void ShowMessageBox(int type, const std::vector& buttons, + int default_button_index, int cancel_id, int options, const std::string& title, @@ -54,11 +55,11 @@ void ShowMessageBox(int type, if (mate::Converter::FromV8(args->isolate(), peek, &callback)) { - atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, cancel_id, - options, title, message, detail, icon, callback); + atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, default_button_index, + cancel_id, options, title, message, detail, icon, callback); } else { int chosen = atom::ShowMessageBox(window, (atom::MessageBoxType)type, - buttons, cancel_id, options, title, + buttons, default_button_index, cancel_id, options, title, message, detail, icon); args->Return(chosen); } diff --git a/atom/browser/api/lib/dialog.coffee b/atom/browser/api/lib/dialog.coffee index f10ce58c17f5..03deb548cc76 100644 --- a/atom/browser/api/lib/dialog.coffee +++ b/atom/browser/api/lib/dialog.coffee @@ -91,10 +91,11 @@ module.exports = throw new TypeError('Buttons need to be array') unless Array.isArray options.buttons - options.title ?= '' - options.message ?= '' - options.detail ?= '' - options.icon ?= null + options.title ?= '' + options.message ?= '' + options.detail ?= '' + options.icon ?= null + options.defaultButtonIndex ?= -1 # Choose a default button to get selected when dialog is cancelled. unless options.cancelId? @@ -108,6 +109,7 @@ module.exports = binding.showMessageBox messageBoxType, options.buttons, + options.defaultButtonIndex, options.cancelId, flags, options.title, diff --git a/atom/browser/ui/message_box.h b/atom/browser/ui/message_box.h index 92052d3de4a4..cef3c79dc4aa 100644 --- a/atom/browser/ui/message_box.h +++ b/atom/browser/ui/message_box.h @@ -38,6 +38,7 @@ int ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, int cancel_id, + int default_button_index, int options, const std::string& title, const std::string& message, @@ -47,6 +48,7 @@ int ShowMessageBox(NativeWindow* parent_window, void ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int default_button_index, int cancel_id, int options, const std::string& title, diff --git a/atom/browser/ui/message_box_mac.mm b/atom/browser/ui/message_box_mac.mm index e518af653da4..f9a4f9aff0b7 100644 --- a/atom/browser/ui/message_box_mac.mm +++ b/atom/browser/ui/message_box_mac.mm @@ -54,6 +54,7 @@ namespace { NSAlert* CreateNSAlert(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int default_button_index, const std::string& title, const std::string& message, const std::string& detail) { @@ -78,8 +79,17 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window, // An empty title causes crash on OS X. if (buttons[i].empty()) title = @"(empty)"; + NSButton* button = [alert addButtonWithTitle:title]; [button setTag:i]; + + if (i == (size_t)default_button_index) { + // focus the button at default_button_index if the user opted to do so. + // The first button added gets set as the default selected. + // So remove that default, and make the requested button the default + [[[alert buttons] objectAtIndex:0] setKeyEquivalent:@""]; + [button setKeyEquivalent:@"\r"]; + } } return alert; @@ -94,6 +104,7 @@ void SetReturnCode(int* ret_code, int result) { int ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int default_button_index, int cancel_id, int options, const std::string& title, @@ -101,7 +112,8 @@ int ShowMessageBox(NativeWindow* parent_window, const std::string& detail, const gfx::ImageSkia& icon) { NSAlert* alert = CreateNSAlert( - parent_window, type, buttons, title, message, detail); + parent_window, type, buttons, default_button_index, title, message, + detail); // Use runModal for synchronous alert without parent, since we don't have a // window to wait for. @@ -127,6 +139,7 @@ int ShowMessageBox(NativeWindow* parent_window, void ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int default_button_index, int cancel_id, int options, const std::string& title, @@ -135,7 +148,8 @@ void ShowMessageBox(NativeWindow* parent_window, const gfx::ImageSkia& icon, const MessageBoxCallback& callback) { NSAlert* alert = CreateNSAlert( - parent_window, type, buttons, title, message, detail); + parent_window, type, buttons, default_button_index, title, message, + detail); ModalDelegate* delegate = [[ModalDelegate alloc] initWithCallback:callback andAlert:alert callEndModal:false]; From 22c455175aac98e8027ba4f2965c3e526ac84fe9 Mon Sep 17 00:00:00 2001 From: leethomas Date: Thu, 7 Jan 2016 21:23:15 -0800 Subject: [PATCH 2/7] :penguin: add default button index for linux/gtk --- atom/browser/ui/message_box_gtk.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/atom/browser/ui/message_box_gtk.cc b/atom/browser/ui/message_box_gtk.cc index de8d994e5bca..65f557901fd0 100644 --- a/atom/browser/ui/message_box_gtk.cc +++ b/atom/browser/ui/message_box_gtk.cc @@ -29,6 +29,7 @@ class GtkMessageBox { GtkMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int default_button_index, int cancel_id, const std::string& title, const std::string& message, @@ -60,9 +61,16 @@ class GtkMessageBox { // Add buttons. for (size_t i = 0; i < buttons.size(); ++i) { - gtk_dialog_add_button(GTK_DIALOG(dialog_), + if (i == (size_t)default_button_index) { + GtkWidget* button = gtk_dialog_add_button(GTK_DIALOG(dialog_), + TranslateToStock(i, buttons[i]), + i); + gtk_widget_grab_focus(button); + } else { + gtk_dialog_add_button(GTK_DIALOG(dialog_), TranslateToStock(i, buttons[i]), i); + } } // Parent window. @@ -161,19 +169,21 @@ void GtkMessageBox::OnResponseDialog(GtkWidget* widget, int response) { int ShowMessageBox(NativeWindow* parent, MessageBoxType type, const std::vector& buttons, + int default_button_index, int cancel_id, int options, const std::string& title, const std::string& message, const std::string& detail, const gfx::ImageSkia& icon) { - return GtkMessageBox(parent, type, buttons, cancel_id, title, message, detail, + return GtkMessageBox(parent, type, buttons, default_button_index, cancel_id, title, message, detail, icon).RunSynchronous(); } void ShowMessageBox(NativeWindow* parent, MessageBoxType type, const std::vector& buttons, + int default_button_index, int cancel_id, int options, const std::string& title, @@ -181,13 +191,13 @@ void ShowMessageBox(NativeWindow* parent, const std::string& detail, const gfx::ImageSkia& icon, const MessageBoxCallback& callback) { - (new GtkMessageBox(parent, type, buttons, cancel_id, title, message, detail, + (new GtkMessageBox(parent, type, buttons, default_button_index, cancel_id, title, message, detail, icon))->RunAsynchronous(callback); } void ShowErrorBox(const base::string16& title, const base::string16& content) { if (Browser::Get()->is_ready()) { - GtkMessageBox(nullptr, MESSAGE_BOX_TYPE_ERROR, { "OK" }, 0, "Error", + GtkMessageBox(nullptr, MESSAGE_BOX_TYPE_ERROR, { "OK" }, -1, 0, "Error", base::UTF16ToUTF8(title).c_str(), base::UTF16ToUTF8(content).c_str(), gfx::ImageSkia()).RunSynchronous(); From c4c145ef6a8c340510f349ce4bc8cec335effc0b Mon Sep 17 00:00:00 2001 From: leethomas Date: Thu, 7 Jan 2016 22:10:34 -0800 Subject: [PATCH 3/7] :memo: add defaultButtonIndex to dialog docs --- docs/api/dialog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api/dialog.md b/docs/api/dialog.md index 80a5289e93f5..ecab70a59153 100644 --- a/docs/api/dialog.md +++ b/docs/api/dialog.md @@ -87,6 +87,7 @@ will be passed via `callback(filename)` `"warning"`. On Windows, "question" displays the same icon as "info", unless you set an icon using the "icon" option. * `buttons` Array - Array of texts for buttons. + * `defaultButtonIndex` Integer - Index of the button in the buttons array which will be selected by default when the message box opens. * `title` String - Title of the message box, some platforms will not show it. * `message` String - Content of the message box. * `detail` String - Extra information of the message. From dfce803045ebca20bf55c207bc9396d3430ad050 Mon Sep 17 00:00:00 2001 From: leethomas Date: Thu, 7 Jan 2016 22:34:16 -0800 Subject: [PATCH 4/7] :checkered_flag: update windows message_box function signatures to accept default_button_index....and do nothing with it --- atom/browser/api/atom_api_dialog.cc | 9 +++++---- atom/browser/ui/message_box_gtk.cc | 8 ++++---- atom/browser/ui/message_box_win.cc | 17 +++++++++++------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/atom/browser/api/atom_api_dialog.cc b/atom/browser/api/atom_api_dialog.cc index e8c1ae3ba99f..0ec9f1905806 100644 --- a/atom/browser/api/atom_api_dialog.cc +++ b/atom/browser/api/atom_api_dialog.cc @@ -55,12 +55,13 @@ void ShowMessageBox(int type, if (mate::Converter::FromV8(args->isolate(), peek, &callback)) { - atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, default_button_index, - cancel_id, options, title, message, detail, icon, callback); + atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, + default_button_index, cancel_id, options, title, + message, detail, icon, callback); } else { int chosen = atom::ShowMessageBox(window, (atom::MessageBoxType)type, - buttons, default_button_index, cancel_id, options, title, - message, detail, icon); + buttons, default_button_index, cancel_id, + options, title, message, detail, icon); args->Return(chosen); } } diff --git a/atom/browser/ui/message_box_gtk.cc b/atom/browser/ui/message_box_gtk.cc index 65f557901fd0..cf227d4e672f 100644 --- a/atom/browser/ui/message_box_gtk.cc +++ b/atom/browser/ui/message_box_gtk.cc @@ -176,8 +176,8 @@ int ShowMessageBox(NativeWindow* parent, const std::string& message, const std::string& detail, const gfx::ImageSkia& icon) { - return GtkMessageBox(parent, type, buttons, default_button_index, cancel_id, title, message, detail, - icon).RunSynchronous(); + return GtkMessageBox(parent, type, buttons, default_button_index, cancel_id, + title, message, detail, icon).RunSynchronous(); } void ShowMessageBox(NativeWindow* parent, @@ -191,8 +191,8 @@ void ShowMessageBox(NativeWindow* parent, const std::string& detail, const gfx::ImageSkia& icon, const MessageBoxCallback& callback) { - (new GtkMessageBox(parent, type, buttons, default_button_index, cancel_id, title, message, detail, - icon))->RunAsynchronous(callback); + (new GtkMessageBox(parent, type, buttons, default_button_index, cancel_id, + title, message, detail, icon))->RunAsynchronous(callback); } void ShowErrorBox(const base::string16& title, const base::string16& content) { diff --git a/atom/browser/ui/message_box_win.cc b/atom/browser/ui/message_box_win.cc index 656be9f10bb2..7ee72e64d2f2 100644 --- a/atom/browser/ui/message_box_win.cc +++ b/atom/browser/ui/message_box_win.cc @@ -72,6 +72,7 @@ void MapToCommonID(const std::vector& buttons, int ShowMessageBoxUTF16(HWND parent, MessageBoxType type, const std::vector& buttons, + int default_button_index, int cancel_id, int options, const base::string16& title, @@ -156,6 +157,7 @@ void RunMessageBoxInNewThread(base::Thread* thread, NativeWindow* parent, MessageBoxType type, const std::vector& buttons, + int default_button_index, int cancel_id, int options, const std::string& title, @@ -163,8 +165,8 @@ void RunMessageBoxInNewThread(base::Thread* thread, const std::string& detail, const gfx::ImageSkia& icon, const MessageBoxCallback& callback) { - int result = ShowMessageBox(parent, type, buttons, cancel_id, options, title, - message, detail, icon); + int result = ShowMessageBox(parent, type, buttons, default_button_index, + cancel_id, options, title, message, detail, icon); content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); content::BrowserThread::DeleteSoon( @@ -176,6 +178,7 @@ void RunMessageBoxInNewThread(base::Thread* thread, int ShowMessageBox(NativeWindow* parent, MessageBoxType type, const std::vector& buttons, + int default_button_index, int cancel_id, int options, const std::string& title, @@ -194,6 +197,7 @@ int ShowMessageBox(NativeWindow* parent, return ShowMessageBoxUTF16(hwnd_parent, type, utf16_buttons, + default_button_index, cancel_id, options, base::UTF8ToUTF16(title), @@ -205,6 +209,7 @@ int ShowMessageBox(NativeWindow* parent, void ShowMessageBox(NativeWindow* parent, MessageBoxType type, const std::vector& buttons, + int default_button_index, int cancel_id, int options, const std::string& title, @@ -224,13 +229,13 @@ void ShowMessageBox(NativeWindow* parent, unretained->message_loop()->PostTask( FROM_HERE, base::Bind(&RunMessageBoxInNewThread, base::Unretained(unretained), - parent, type, buttons, cancel_id, options, title, message, - detail, icon, callback)); + parent, type, buttons, default_button_index, + cancel_id, options, title, message, detail, icon, callback)); } void ShowErrorBox(const base::string16& title, const base::string16& content) { - ShowMessageBoxUTF16(NULL, MESSAGE_BOX_TYPE_ERROR, {}, 0, 0, L"Error", title, - content, gfx::ImageSkia()); + ShowMessageBoxUTF16(NULL, MESSAGE_BOX_TYPE_ERROR, {}, -1, 0, 0, L"Error", + title, content, gfx::ImageSkia()); } } // namespace atom From ae5c6add11b8b4b5c1e5e8ade63d2e3d25b04977 Mon Sep 17 00:00:00 2001 From: leethomas Date: Sun, 10 Jan 2016 15:33:27 -0800 Subject: [PATCH 5/7] rename all references to default_button_index -> default_id to keep consistent with cancel_id --- atom/browser/api/atom_api_dialog.cc | 6 +++--- atom/browser/api/lib/dialog.coffee | 4 ++-- atom/browser/ui/message_box.h | 4 ++-- atom/browser/ui/message_box_gtk.cc | 12 ++++++------ atom/browser/ui/message_box_mac.mm | 14 +++++++------- atom/browser/ui/message_box_win.cc | 14 +++++++------- docs/api/dialog.md | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/atom/browser/api/atom_api_dialog.cc b/atom/browser/api/atom_api_dialog.cc index 0ec9f1905806..3ff53352cba1 100644 --- a/atom/browser/api/atom_api_dialog.cc +++ b/atom/browser/api/atom_api_dialog.cc @@ -41,7 +41,7 @@ namespace { void ShowMessageBox(int type, const std::vector& buttons, - int default_button_index, + int default_id, int cancel_id, int options, const std::string& title, @@ -56,11 +56,11 @@ void ShowMessageBox(int type, peek, &callback)) { atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, - default_button_index, cancel_id, options, title, + default_id, cancel_id, options, title, message, detail, icon, callback); } else { int chosen = atom::ShowMessageBox(window, (atom::MessageBoxType)type, - buttons, default_button_index, cancel_id, + buttons, default_id, cancel_id, options, title, message, detail, icon); args->Return(chosen); } diff --git a/atom/browser/api/lib/dialog.coffee b/atom/browser/api/lib/dialog.coffee index 03deb548cc76..2768fe096a05 100644 --- a/atom/browser/api/lib/dialog.coffee +++ b/atom/browser/api/lib/dialog.coffee @@ -95,7 +95,7 @@ module.exports = options.message ?= '' options.detail ?= '' options.icon ?= null - options.defaultButtonIndex ?= -1 + options.defaultId ?= -1 # Choose a default button to get selected when dialog is cancelled. unless options.cancelId? @@ -109,7 +109,7 @@ module.exports = binding.showMessageBox messageBoxType, options.buttons, - options.defaultButtonIndex, + options.defaultId, options.cancelId, flags, options.title, diff --git a/atom/browser/ui/message_box.h b/atom/browser/ui/message_box.h index cef3c79dc4aa..d2eb70bcd938 100644 --- a/atom/browser/ui/message_box.h +++ b/atom/browser/ui/message_box.h @@ -38,7 +38,7 @@ int ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, int cancel_id, - int default_button_index, + int default_id, int options, const std::string& title, const std::string& message, @@ -48,7 +48,7 @@ int ShowMessageBox(NativeWindow* parent_window, void ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, - int default_button_index, + int default_id, int cancel_id, int options, const std::string& title, diff --git a/atom/browser/ui/message_box_gtk.cc b/atom/browser/ui/message_box_gtk.cc index cf227d4e672f..fe1068effd7c 100644 --- a/atom/browser/ui/message_box_gtk.cc +++ b/atom/browser/ui/message_box_gtk.cc @@ -29,7 +29,7 @@ class GtkMessageBox { GtkMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, - int default_button_index, + int default_id, int cancel_id, const std::string& title, const std::string& message, @@ -61,7 +61,7 @@ class GtkMessageBox { // Add buttons. for (size_t i = 0; i < buttons.size(); ++i) { - if (i == (size_t)default_button_index) { + if (i == (size_t)default_id) { GtkWidget* button = gtk_dialog_add_button(GTK_DIALOG(dialog_), TranslateToStock(i, buttons[i]), i); @@ -169,21 +169,21 @@ void GtkMessageBox::OnResponseDialog(GtkWidget* widget, int response) { int ShowMessageBox(NativeWindow* parent, MessageBoxType type, const std::vector& buttons, - int default_button_index, + int default_id, int cancel_id, int options, const std::string& title, const std::string& message, const std::string& detail, const gfx::ImageSkia& icon) { - return GtkMessageBox(parent, type, buttons, default_button_index, cancel_id, + return GtkMessageBox(parent, type, buttons, default_id, cancel_id, title, message, detail, icon).RunSynchronous(); } void ShowMessageBox(NativeWindow* parent, MessageBoxType type, const std::vector& buttons, - int default_button_index, + int default_id, int cancel_id, int options, const std::string& title, @@ -191,7 +191,7 @@ void ShowMessageBox(NativeWindow* parent, const std::string& detail, const gfx::ImageSkia& icon, const MessageBoxCallback& callback) { - (new GtkMessageBox(parent, type, buttons, default_button_index, cancel_id, + (new GtkMessageBox(parent, type, buttons, default_id, cancel_id, title, message, detail, icon))->RunAsynchronous(callback); } diff --git a/atom/browser/ui/message_box_mac.mm b/atom/browser/ui/message_box_mac.mm index f9a4f9aff0b7..79c60b5ffe3c 100644 --- a/atom/browser/ui/message_box_mac.mm +++ b/atom/browser/ui/message_box_mac.mm @@ -54,7 +54,7 @@ namespace { NSAlert* CreateNSAlert(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, - int default_button_index, + int default_id, const std::string& title, const std::string& message, const std::string& detail) { @@ -83,8 +83,8 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window, NSButton* button = [alert addButtonWithTitle:title]; [button setTag:i]; - if (i == (size_t)default_button_index) { - // focus the button at default_button_index if the user opted to do so. + if (i == (size_t)default_id) { + // focus the button at default_id if the user opted to do so. // The first button added gets set as the default selected. // So remove that default, and make the requested button the default [[[alert buttons] objectAtIndex:0] setKeyEquivalent:@""]; @@ -104,7 +104,7 @@ void SetReturnCode(int* ret_code, int result) { int ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, - int default_button_index, + int default_id, int cancel_id, int options, const std::string& title, @@ -112,7 +112,7 @@ int ShowMessageBox(NativeWindow* parent_window, const std::string& detail, const gfx::ImageSkia& icon) { NSAlert* alert = CreateNSAlert( - parent_window, type, buttons, default_button_index, title, message, + parent_window, type, buttons, default_id, title, message, detail); // Use runModal for synchronous alert without parent, since we don't have a @@ -139,7 +139,7 @@ int ShowMessageBox(NativeWindow* parent_window, void ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, - int default_button_index, + int default_id, int cancel_id, int options, const std::string& title, @@ -148,7 +148,7 @@ void ShowMessageBox(NativeWindow* parent_window, const gfx::ImageSkia& icon, const MessageBoxCallback& callback) { NSAlert* alert = CreateNSAlert( - parent_window, type, buttons, default_button_index, title, message, + parent_window, type, buttons, default_id, title, message, detail); ModalDelegate* delegate = [[ModalDelegate alloc] initWithCallback:callback andAlert:alert diff --git a/atom/browser/ui/message_box_win.cc b/atom/browser/ui/message_box_win.cc index 7ee72e64d2f2..58287dd5b7d5 100644 --- a/atom/browser/ui/message_box_win.cc +++ b/atom/browser/ui/message_box_win.cc @@ -72,7 +72,7 @@ void MapToCommonID(const std::vector& buttons, int ShowMessageBoxUTF16(HWND parent, MessageBoxType type, const std::vector& buttons, - int default_button_index, + int default_id, int cancel_id, int options, const base::string16& title, @@ -157,7 +157,7 @@ void RunMessageBoxInNewThread(base::Thread* thread, NativeWindow* parent, MessageBoxType type, const std::vector& buttons, - int default_button_index, + int default_id, int cancel_id, int options, const std::string& title, @@ -165,7 +165,7 @@ void RunMessageBoxInNewThread(base::Thread* thread, const std::string& detail, const gfx::ImageSkia& icon, const MessageBoxCallback& callback) { - int result = ShowMessageBox(parent, type, buttons, default_button_index, + int result = ShowMessageBox(parent, type, buttons, default_id, cancel_id, options, title, message, detail, icon); content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); @@ -178,7 +178,7 @@ void RunMessageBoxInNewThread(base::Thread* thread, int ShowMessageBox(NativeWindow* parent, MessageBoxType type, const std::vector& buttons, - int default_button_index, + int default_id, int cancel_id, int options, const std::string& title, @@ -197,7 +197,7 @@ int ShowMessageBox(NativeWindow* parent, return ShowMessageBoxUTF16(hwnd_parent, type, utf16_buttons, - default_button_index, + default_id, cancel_id, options, base::UTF8ToUTF16(title), @@ -209,7 +209,7 @@ int ShowMessageBox(NativeWindow* parent, void ShowMessageBox(NativeWindow* parent, MessageBoxType type, const std::vector& buttons, - int default_button_index, + int default_id, int cancel_id, int options, const std::string& title, @@ -229,7 +229,7 @@ void ShowMessageBox(NativeWindow* parent, unretained->message_loop()->PostTask( FROM_HERE, base::Bind(&RunMessageBoxInNewThread, base::Unretained(unretained), - parent, type, buttons, default_button_index, + parent, type, buttons, default_id, cancel_id, options, title, message, detail, icon, callback)); } diff --git a/docs/api/dialog.md b/docs/api/dialog.md index ecab70a59153..519f89b9c5df 100644 --- a/docs/api/dialog.md +++ b/docs/api/dialog.md @@ -87,7 +87,7 @@ will be passed via `callback(filename)` `"warning"`. On Windows, "question" displays the same icon as "info", unless you set an icon using the "icon" option. * `buttons` Array - Array of texts for buttons. - * `defaultButtonIndex` Integer - Index of the button in the buttons array which will be selected by default when the message box opens. + * `defaultId` Integer - Index of the button in the buttons array which will be selected by default when the message box opens. * `title` String - Title of the message box, some platforms will not show it. * `message` String - Content of the message box. * `detail` String - Extra information of the message. From 803b06b7de60261df72233b130bb9ef4cfa875eb Mon Sep 17 00:00:00 2001 From: leethomas Date: Sun, 10 Jan 2016 15:55:26 -0800 Subject: [PATCH 6/7] :checkered_flag: support defaultId for dialog boxes on Windows --- atom/browser/ui/message_box_win.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/atom/browser/ui/message_box_win.cc b/atom/browser/ui/message_box_win.cc index 58287dd5b7d5..253733de59df 100644 --- a/atom/browser/ui/message_box_win.cc +++ b/atom/browser/ui/message_box_win.cc @@ -84,10 +84,11 @@ int ShowMessageBoxUTF16(HWND parent, TDF_ALLOW_DIALOG_CANCELLATION; // Allow canceling the dialog. TASKDIALOGCONFIG config = { 0 }; - config.cbSize = sizeof(config); - config.hwndParent = parent; - config.hInstance = GetModuleHandle(NULL); - config.dwFlags = flags; + config.cbSize = sizeof(config); + config.hwndParent = parent; + config.hInstance = GetModuleHandle(NULL); + config.dwFlags = flags; + config.nDefaultButton = default_id ? (kIDStart + default_id) : 0; // TaskDialogIndirect doesn't allow empty name, if we set empty title it // will show "electron.exe" in title. From fee301e768be445b16698833111b263d8d8cd87b Mon Sep 17 00:00:00 2001 From: leethomas Date: Sun, 10 Jan 2016 19:15:40 -0800 Subject: [PATCH 7/7] follow style guidelines --- atom/browser/api/lib/dialog.coffee | 8 ++++---- atom/browser/ui/message_box_mac.mm | 4 ++-- docs/api/dialog.md | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/atom/browser/api/lib/dialog.coffee b/atom/browser/api/lib/dialog.coffee index 2768fe096a05..2daf346db468 100644 --- a/atom/browser/api/lib/dialog.coffee +++ b/atom/browser/api/lib/dialog.coffee @@ -91,10 +91,10 @@ module.exports = throw new TypeError('Buttons need to be array') unless Array.isArray options.buttons - options.title ?= '' - options.message ?= '' - options.detail ?= '' - options.icon ?= null + options.title ?= '' + options.message ?= '' + options.detail ?= '' + options.icon ?= null options.defaultId ?= -1 # Choose a default button to get selected when dialog is cancelled. diff --git a/atom/browser/ui/message_box_mac.mm b/atom/browser/ui/message_box_mac.mm index 79c60b5ffe3c..3acc46ec82f1 100644 --- a/atom/browser/ui/message_box_mac.mm +++ b/atom/browser/ui/message_box_mac.mm @@ -84,9 +84,9 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window, [button setTag:i]; if (i == (size_t)default_id) { - // focus the button at default_id if the user opted to do so. + // Focus the button at default_id if the user opted to do so. // The first button added gets set as the default selected. - // So remove that default, and make the requested button the default + // So remove that default, and make the requested button the default. [[[alert buttons] objectAtIndex:0] setKeyEquivalent:@""]; [button setKeyEquivalent:@"\r"]; } diff --git a/docs/api/dialog.md b/docs/api/dialog.md index 519f89b9c5df..84a22ef692b3 100644 --- a/docs/api/dialog.md +++ b/docs/api/dialog.md @@ -87,7 +87,8 @@ will be passed via `callback(filename)` `"warning"`. On Windows, "question" displays the same icon as "info", unless you set an icon using the "icon" option. * `buttons` Array - Array of texts for buttons. - * `defaultId` Integer - Index of the button in the buttons array which will be selected by default when the message box opens. + * `defaultId` Integer - Index of the button in the buttons array which will + be selected by default when the message box opens. * `title` String - Title of the message box, some platforms will not show it. * `message` String - Content of the message box. * `detail` String - Extra information of the message.