From: leethomas Date: Fri, 8 Jan 2016 04:46:45 +0000 (-0800) Subject: :apple: add default button index for osx X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f1edd5f26f38e28c53b3e2d5148dcc9081d57a23;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git :apple: add default button index for osx --- diff --git a/atom/browser/api/atom_api_dialog.cc b/atom/browser/api/atom_api_dialog.cc index 40ee4d0..e8c1ae3 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 f10ce58..03deb54 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 92052d3..cef3c79 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 e518af6..f9a4f9a 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];