Merge pull request #2307 from atom/dialog-options
Add "noLink" option for showMessageBox
This commit is contained in:
commit
de17894fce
8 changed files with 52 additions and 21 deletions
|
@ -42,28 +42,24 @@ namespace {
|
||||||
void ShowMessageBox(int type,
|
void ShowMessageBox(int type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
const std::vector<std::string>& texts,
|
int options,
|
||||||
|
const std::string& title,
|
||||||
|
const std::string& message,
|
||||||
|
const std::string& detail,
|
||||||
const gfx::ImageSkia& icon,
|
const gfx::ImageSkia& icon,
|
||||||
atom::NativeWindow* window,
|
atom::NativeWindow* window,
|
||||||
mate::Arguments* args) {
|
mate::Arguments* args) {
|
||||||
// FIXME We are exceeding the parameters limit of base::Bind here, so we have
|
|
||||||
// to pass some parameters in an array. We should remove this once we have
|
|
||||||
// variadic template support in base::Bind.
|
|
||||||
const std::string& title = texts[0];
|
|
||||||
const std::string& message = texts[1];
|
|
||||||
const std::string& detail = texts[2];
|
|
||||||
|
|
||||||
v8::Local<v8::Value> peek = args->PeekNext();
|
v8::Local<v8::Value> peek = args->PeekNext();
|
||||||
atom::MessageBoxCallback callback;
|
atom::MessageBoxCallback callback;
|
||||||
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, cancel_id,
|
||||||
title, message, detail, icon, callback);
|
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, title, message,
|
buttons, cancel_id, options, title,
|
||||||
detail, icon);
|
message, detail, icon);
|
||||||
args->Return(chosen);
|
args->Return(chosen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,9 @@ fileDialogProperties =
|
||||||
|
|
||||||
messageBoxTypes = ['none', 'info', 'warning', 'error', 'question']
|
messageBoxTypes = ['none', 'info', 'warning', 'error', 'question']
|
||||||
|
|
||||||
|
messageBoxOptions =
|
||||||
|
noLink: 1 << 0
|
||||||
|
|
||||||
parseArgs = (window, options, callback) ->
|
parseArgs = (window, options, callback) ->
|
||||||
unless window is null or window?.constructor is BrowserWindow
|
unless window is null or window?.constructor is BrowserWindow
|
||||||
# Shift.
|
# Shift.
|
||||||
|
@ -101,10 +104,15 @@ module.exports =
|
||||||
options.cancelId = i
|
options.cancelId = i
|
||||||
break
|
break
|
||||||
|
|
||||||
|
flags = if options.noLink then messageBoxOptions.noLink else 0
|
||||||
|
|
||||||
binding.showMessageBox messageBoxType,
|
binding.showMessageBox messageBoxType,
|
||||||
options.buttons,
|
options.buttons,
|
||||||
options.cancelId,
|
options.cancelId,
|
||||||
[options.title, options.message, options.detail],
|
flags,
|
||||||
|
options.title,
|
||||||
|
options.message,
|
||||||
|
options.detail,
|
||||||
options.icon,
|
options.icon,
|
||||||
window,
|
window,
|
||||||
callback
|
callback
|
||||||
|
|
|
@ -27,12 +27,18 @@ enum MessageBoxType {
|
||||||
MESSAGE_BOX_TYPE_QUESTION,
|
MESSAGE_BOX_TYPE_QUESTION,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum MessageBoxOptions {
|
||||||
|
MESSAGE_BOX_NONE = 0,
|
||||||
|
MESSAGE_BOX_NO_LINK = 1 << 0,
|
||||||
|
};
|
||||||
|
|
||||||
typedef base::Callback<void(int code)> MessageBoxCallback;
|
typedef base::Callback<void(int code)> MessageBoxCallback;
|
||||||
|
|
||||||
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 cancel_id,
|
int cancel_id,
|
||||||
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
@ -42,6 +48,7 @@ void 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 options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
|
|
@ -162,6 +162,7 @@ int ShowMessageBox(NativeWindow* parent,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
@ -174,6 +175,7 @@ void ShowMessageBox(NativeWindow* parent,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
|
|
@ -95,6 +95,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 options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
@ -127,6 +128,7 @@ void 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 options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
|
|
@ -72,6 +72,7 @@ int ShowMessageBoxUTF16(HWND parent,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<base::string16>& buttons,
|
const std::vector<base::string16>& buttons,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
|
int options,
|
||||||
const base::string16& title,
|
const base::string16& title,
|
||||||
const base::string16& message,
|
const base::string16& message,
|
||||||
const base::string16& detail,
|
const base::string16& detail,
|
||||||
|
@ -122,10 +123,16 @@ int ShowMessageBoxUTF16(HWND parent,
|
||||||
// and custom buttons in pButtons.
|
// and custom buttons in pButtons.
|
||||||
std::map<int, int> id_map;
|
std::map<int, int> id_map;
|
||||||
std::vector<TASKDIALOG_BUTTON> dialog_buttons;
|
std::vector<TASKDIALOG_BUTTON> dialog_buttons;
|
||||||
|
if (options & MESSAGE_BOX_NO_LINK) {
|
||||||
|
for (size_t i = 0; i < buttons.size(); ++i)
|
||||||
|
dialog_buttons.push_back({i + kIDStart, buttons[i].c_str()});
|
||||||
|
} else {
|
||||||
MapToCommonID(buttons, &id_map, &config.dwCommonButtons, &dialog_buttons);
|
MapToCommonID(buttons, &id_map, &config.dwCommonButtons, &dialog_buttons);
|
||||||
|
}
|
||||||
if (dialog_buttons.size() > 0) {
|
if (dialog_buttons.size() > 0) {
|
||||||
config.pButtons = &dialog_buttons.front();
|
config.pButtons = &dialog_buttons.front();
|
||||||
config.cButtons = dialog_buttons.size();
|
config.cButtons = dialog_buttons.size();
|
||||||
|
if (!(options & MESSAGE_BOX_NO_LINK))
|
||||||
config.dwFlags |= TDF_USE_COMMAND_LINKS; // custom buttons as links.
|
config.dwFlags |= TDF_USE_COMMAND_LINKS; // custom buttons as links.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,13 +151,14 @@ void RunMessageBoxInNewThread(base::Thread* thread,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
const gfx::ImageSkia& icon,
|
const gfx::ImageSkia& icon,
|
||||||
const MessageBoxCallback& callback) {
|
const MessageBoxCallback& callback) {
|
||||||
int result = ShowMessageBox(parent, type, buttons, cancel_id, title, message,
|
int result = ShowMessageBox(parent, type, buttons, cancel_id, options, title,
|
||||||
detail, icon);
|
message, detail, icon);
|
||||||
content::BrowserThread::PostTask(
|
content::BrowserThread::PostTask(
|
||||||
content::BrowserThread::UI, FROM_HERE, base::Bind(callback, result));
|
content::BrowserThread::UI, FROM_HERE, base::Bind(callback, result));
|
||||||
content::BrowserThread::DeleteSoon(
|
content::BrowserThread::DeleteSoon(
|
||||||
|
@ -163,6 +171,7 @@ int ShowMessageBox(NativeWindow* parent,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
@ -180,6 +189,7 @@ int ShowMessageBox(NativeWindow* parent,
|
||||||
type,
|
type,
|
||||||
utf16_buttons,
|
utf16_buttons,
|
||||||
cancel_id,
|
cancel_id,
|
||||||
|
options,
|
||||||
base::UTF8ToUTF16(title),
|
base::UTF8ToUTF16(title),
|
||||||
base::UTF8ToUTF16(message),
|
base::UTF8ToUTF16(message),
|
||||||
base::UTF8ToUTF16(detail),
|
base::UTF8ToUTF16(detail),
|
||||||
|
@ -190,6 +200,7 @@ void ShowMessageBox(NativeWindow* parent,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
int cancel_id,
|
int cancel_id,
|
||||||
|
int options,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
@ -207,12 +218,12 @@ void ShowMessageBox(NativeWindow* parent,
|
||||||
unretained->message_loop()->PostTask(
|
unretained->message_loop()->PostTask(
|
||||||
FROM_HERE,
|
FROM_HERE,
|
||||||
base::Bind(&RunMessageBoxInNewThread, base::Unretained(unretained),
|
base::Bind(&RunMessageBoxInNewThread, base::Unretained(unretained),
|
||||||
parent, type, buttons, cancel_id, title, message, detail, icon,
|
parent, type, buttons, cancel_id, options, title, message,
|
||||||
callback));
|
detail, icon, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowErrorBox(const base::string16& title, const base::string16& content) {
|
void ShowErrorBox(const base::string16& title, const base::string16& content) {
|
||||||
ShowMessageBoxUTF16(NULL, MESSAGE_BOX_TYPE_ERROR, {}, 0, L"Error", title,
|
ShowMessageBoxUTF16(NULL, MESSAGE_BOX_TYPE_ERROR, {}, 0, 0, L"Error", title,
|
||||||
content, gfx::ImageSkia());
|
content, gfx::ImageSkia());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,12 @@ will be passed via `callback(filename)`
|
||||||
instead of clicking the buttons of the dialog. By default it is the index
|
instead of clicking the buttons of the dialog. By default it is the index
|
||||||
of the buttons that have "cancel" or "no" as label, or 0 if there is no such
|
of the buttons that have "cancel" or "no" as label, or 0 if there is no such
|
||||||
buttons. On OS X and Windows the index of "Cancel" button will always be
|
buttons. On OS X and Windows the index of "Cancel" button will always be
|
||||||
used as `cancelId`, not matter whether it is already specified.
|
used as `cancelId`, not matter whether it is already specified
|
||||||
|
* `noLink` Boolean - On Windows Electron would try to figure out which ones of
|
||||||
|
the `buttons` are common buttons (like "Cancel" or "Yes"), and show the
|
||||||
|
others as command links in the dialog, this can make the dialog appear in
|
||||||
|
the style of modern Windows apps. If you don't like this behavior, you can
|
||||||
|
specify `noLink` to `true`
|
||||||
* `callback` Function
|
* `callback` Function
|
||||||
|
|
||||||
Shows a message box, it will block until the message box is closed. It returns
|
Shows a message box, it will block until the message box is closed. It returns
|
||||||
|
|
2
vendor/native_mate
vendored
2
vendor/native_mate
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 41cd6d13c9c9be164f427864277f3cc36b69eb39
|
Subproject commit 656e403f0102c59428261c1eaad22912d2bbd3c5
|
Loading…
Add table
Add a link
Reference in a new issue