🍎 add default button index for osx
This commit is contained in:
parent
5514e89276
commit
f1edd5f26f
4 changed files with 28 additions and 9 deletions
|
@ -41,6 +41,7 @@ namespace {
|
||||||
|
|
||||||
void ShowMessageBox(int type,
|
void ShowMessageBox(int type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int default_button_index,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
int options,
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
@ -54,11 +55,11 @@ void ShowMessageBox(int type,
|
||||||
if (mate::Converter<atom::MessageBoxCallback>::FromV8(args->isolate(),
|
if (mate::Converter<atom::MessageBoxCallback>::FromV8(args->isolate(),
|
||||||
peek,
|
peek,
|
||||||
&callback)) {
|
&callback)) {
|
||||||
atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, cancel_id,
|
atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, default_button_index,
|
||||||
options, title, message, detail, icon, callback);
|
cancel_id, options, title, message, detail, icon, callback);
|
||||||
} else {
|
} else {
|
||||||
int chosen = atom::ShowMessageBox(window, (atom::MessageBoxType)type,
|
int chosen = atom::ShowMessageBox(window, (atom::MessageBoxType)type,
|
||||||
buttons, cancel_id, options, title,
|
buttons, default_button_index, cancel_id, options, title,
|
||||||
message, detail, icon);
|
message, detail, icon);
|
||||||
args->Return(chosen);
|
args->Return(chosen);
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,7 @@ module.exports =
|
||||||
options.message ?= ''
|
options.message ?= ''
|
||||||
options.detail ?= ''
|
options.detail ?= ''
|
||||||
options.icon ?= null
|
options.icon ?= null
|
||||||
|
options.defaultButtonIndex ?= -1
|
||||||
|
|
||||||
# Choose a default button to get selected when dialog is cancelled.
|
# Choose a default button to get selected when dialog is cancelled.
|
||||||
unless options.cancelId?
|
unless options.cancelId?
|
||||||
|
@ -108,6 +109,7 @@ module.exports =
|
||||||
|
|
||||||
binding.showMessageBox messageBoxType,
|
binding.showMessageBox messageBoxType,
|
||||||
options.buttons,
|
options.buttons,
|
||||||
|
options.defaultButtonIndex,
|
||||||
options.cancelId,
|
options.cancelId,
|
||||||
flags,
|
flags,
|
||||||
options.title,
|
options.title,
|
||||||
|
|
|
@ -38,6 +38,7 @@ int ShowMessageBox(NativeWindow* parent_window,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
|
int default_button_index,
|
||||||
int options,
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
|
@ -47,6 +48,7 @@ int ShowMessageBox(NativeWindow* parent_window,
|
||||||
void ShowMessageBox(NativeWindow* parent_window,
|
void ShowMessageBox(NativeWindow* parent_window,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int default_button_index,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
int options,
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
|
|
@ -54,6 +54,7 @@ namespace {
|
||||||
NSAlert* CreateNSAlert(NativeWindow* parent_window,
|
NSAlert* CreateNSAlert(NativeWindow* parent_window,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int default_button_index,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail) {
|
const std::string& detail) {
|
||||||
|
@ -78,8 +79,17 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window,
|
||||||
// An empty title causes crash on OS X.
|
// An empty title causes crash on OS X.
|
||||||
if (buttons[i].empty())
|
if (buttons[i].empty())
|
||||||
title = @"(empty)";
|
title = @"(empty)";
|
||||||
|
|
||||||
NSButton* button = [alert addButtonWithTitle:title];
|
NSButton* button = [alert addButtonWithTitle:title];
|
||||||
[button setTag:i];
|
[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;
|
return alert;
|
||||||
|
@ -94,6 +104,7 @@ void SetReturnCode(int* ret_code, int result) {
|
||||||
int ShowMessageBox(NativeWindow* parent_window,
|
int ShowMessageBox(NativeWindow* parent_window,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int default_button_index,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
int options,
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
@ -101,7 +112,8 @@ int ShowMessageBox(NativeWindow* parent_window,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
const gfx::ImageSkia& icon) {
|
const gfx::ImageSkia& icon) {
|
||||||
NSAlert* alert = CreateNSAlert(
|
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
|
// Use runModal for synchronous alert without parent, since we don't have a
|
||||||
// window to wait for.
|
// window to wait for.
|
||||||
|
@ -127,6 +139,7 @@ int ShowMessageBox(NativeWindow* parent_window,
|
||||||
void ShowMessageBox(NativeWindow* parent_window,
|
void ShowMessageBox(NativeWindow* parent_window,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int default_button_index,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
int options,
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
@ -135,7 +148,8 @@ void ShowMessageBox(NativeWindow* parent_window,
|
||||||
const gfx::ImageSkia& icon,
|
const gfx::ImageSkia& icon,
|
||||||
const MessageBoxCallback& callback) {
|
const MessageBoxCallback& callback) {
|
||||||
NSAlert* alert = CreateNSAlert(
|
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
|
ModalDelegate* delegate = [[ModalDelegate alloc] initWithCallback:callback
|
||||||
andAlert:alert
|
andAlert:alert
|
||||||
callEndModal:false];
|
callEndModal:false];
|
||||||
|
|
Loading…
Reference in a new issue