void ShowMessageBox(int type,
const std::vector<std::string>& buttons,
+ int default_button_index,
int cancel_id,
int options,
const std::string& title,
if (mate::Converter<atom::MessageBoxCallback>::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);
}
MessageBoxType type,
const std::vector<std::string>& buttons,
int cancel_id,
+ int default_button_index,
int options,
const std::string& title,
const std::string& message,
void ShowMessageBox(NativeWindow* parent_window,
MessageBoxType type,
const std::vector<std::string>& buttons,
+ int default_button_index,
int cancel_id,
int options,
const std::string& title,
NSAlert* CreateNSAlert(NativeWindow* parent_window,
MessageBoxType type,
const std::vector<std::string>& buttons,
+ int default_button_index,
const std::string& title,
const std::string& message,
const std::string& detail) {
// 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;
int ShowMessageBox(NativeWindow* parent_window,
MessageBoxType type,
const std::vector<std::string>& buttons,
+ int default_button_index,
int cancel_id,
int options,
const std::string& title,
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.
void ShowMessageBox(NativeWindow* parent_window,
MessageBoxType type,
const std::vector<std::string>& buttons,
+ int default_button_index,
int cancel_id,
int options,
const std::string& title,
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];