Merge pull request #2146 from atom/cancel-id
Add "cancelId" option for showMessageBox
This commit is contained in:
commit
fdc01b8ba8
7 changed files with 52 additions and 28 deletions
|
@ -41,6 +41,7 @@ namespace {
|
|||
|
||||
void ShowMessageBox(int type,
|
||||
const std::vector<std::string>& buttons,
|
||||
int cancel_id,
|
||||
const std::vector<std::string>& texts,
|
||||
const gfx::ImageSkia& icon,
|
||||
atom::NativeWindow* window,
|
||||
|
@ -57,11 +58,12 @@ void ShowMessageBox(int type,
|
|||
if (mate::Converter<atom::MessageBoxCallback>::FromV8(args->isolate(),
|
||||
peek,
|
||||
&callback)) {
|
||||
atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, title,
|
||||
message, detail, icon, callback);
|
||||
atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, cancel_id,
|
||||
title, message, detail, icon, callback);
|
||||
} else {
|
||||
int chosen = atom::ShowMessageBox(window, (atom::MessageBoxType)type,
|
||||
buttons, title, message, detail, icon);
|
||||
buttons, cancel_id, title, message,
|
||||
detail, icon);
|
||||
args->Return(chosen);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,8 +93,23 @@ module.exports =
|
|||
options.detail ?= ''
|
||||
options.icon ?= null
|
||||
|
||||
# Choose a default button to get selected when dialog is cancelled.
|
||||
unless options.cancelId?
|
||||
options.cancelId = 0
|
||||
for text, i in options.buttons
|
||||
if text.toLowerCase() in ['cancel', 'no']
|
||||
options.cancelId = i
|
||||
break
|
||||
|
||||
# On OS X the "Cancel" is always get selected when dialog is cancelled.
|
||||
if process.platform is 'darwin'
|
||||
for text, i in options.buttons when text is 'Cancel'
|
||||
options.cancelId = i
|
||||
break
|
||||
|
||||
binding.showMessageBox messageBoxType,
|
||||
options.buttons,
|
||||
options.cancelId,
|
||||
[options.title, options.message, options.detail],
|
||||
options.icon,
|
||||
window,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue