Merge pull request #2307 from atom/dialog-options

Add "noLink" option for showMessageBox
This commit is contained in:
Cheng Zhao 2015-07-23 17:59:09 +08:00
commit de17894fce
8 changed files with 52 additions and 21 deletions

View file

@ -42,28 +42,24 @@ namespace {
void ShowMessageBox(int type,
const std::vector<std::string>& buttons,
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,
atom::NativeWindow* window,
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();
atom::MessageBoxCallback callback;
if (mate::Converter<atom::MessageBoxCallback>::FromV8(args->isolate(),
peek,
&callback)) {
atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, cancel_id,
title, message, detail, icon, callback);
options, title, message, detail, icon, callback);
} else {
int chosen = atom::ShowMessageBox(window, (atom::MessageBoxType)type,
buttons, cancel_id, title, message,
detail, icon);
buttons, cancel_id, options, title,
message, detail, icon);
args->Return(chosen);
}
}

View file

@ -11,6 +11,9 @@ fileDialogProperties =
messageBoxTypes = ['none', 'info', 'warning', 'error', 'question']
messageBoxOptions =
noLink: 1 << 0
parseArgs = (window, options, callback) ->
unless window is null or window?.constructor is BrowserWindow
# Shift.
@ -101,10 +104,15 @@ module.exports =
options.cancelId = i
break
flags = if options.noLink then messageBoxOptions.noLink else 0
binding.showMessageBox messageBoxType,
options.buttons,
options.cancelId,
[options.title, options.message, options.detail],
flags,
options.title,
options.message,
options.detail,
options.icon,
window,
callback

View file

@ -27,12 +27,18 @@ enum MessageBoxType {
MESSAGE_BOX_TYPE_QUESTION,
};
enum MessageBoxOptions {
MESSAGE_BOX_NONE = 0,
MESSAGE_BOX_NO_LINK = 1 << 0,
};
typedef base::Callback<void(int code)> MessageBoxCallback;
int ShowMessageBox(NativeWindow* parent_window,
MessageBoxType type,
const std::vector<std::string>& buttons,
int cancel_id,
int options,
const std::string& title,
const std::string& message,
const std::string& detail,
@ -42,6 +48,7 @@ void ShowMessageBox(NativeWindow* parent_window,
MessageBoxType type,
const std::vector<std::string>& buttons,
int cancel_id,
int options,
const std::string& title,
const std::string& message,
const std::string& detail,

View file

@ -162,6 +162,7 @@ int ShowMessageBox(NativeWindow* parent,
MessageBoxType type,
const std::vector<std::string>& buttons,
int cancel_id,
int options,
const std::string& title,
const std::string& message,
const std::string& detail,
@ -174,6 +175,7 @@ void ShowMessageBox(NativeWindow* parent,
MessageBoxType type,
const std::vector<std::string>& buttons,
int cancel_id,
int options,
const std::string& title,
const std::string& message,
const std::string& detail,

View file

@ -95,6 +95,7 @@ int ShowMessageBox(NativeWindow* parent_window,
MessageBoxType type,
const std::vector<std::string>& buttons,
int cancel_id,
int options,
const std::string& title,
const std::string& message,
const std::string& detail,
@ -127,6 +128,7 @@ void ShowMessageBox(NativeWindow* parent_window,
MessageBoxType type,
const std::vector<std::string>& buttons,
int cancel_id,
int options,
const std::string& title,
const std::string& message,
const std::string& detail,

View file

@ -72,6 +72,7 @@ int ShowMessageBoxUTF16(HWND parent,
MessageBoxType type,
const std::vector<base::string16>& buttons,
int cancel_id,
int options,
const base::string16& title,
const base::string16& message,
const base::string16& detail,
@ -122,11 +123,17 @@ int ShowMessageBoxUTF16(HWND parent,
// and custom buttons in pButtons.
std::map<int, int> id_map;
std::vector<TASKDIALOG_BUTTON> dialog_buttons;
MapToCommonID(buttons, &id_map, &config.dwCommonButtons, &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);
}
if (dialog_buttons.size() > 0) {
config.pButtons = &dialog_buttons.front();
config.cButtons = dialog_buttons.size();
config.dwFlags |= TDF_USE_COMMAND_LINKS; // custom buttons as links.
if (!(options & MESSAGE_BOX_NO_LINK))
config.dwFlags |= TDF_USE_COMMAND_LINKS; // custom buttons as links.
}
int id = 0;
@ -144,13 +151,14 @@ void RunMessageBoxInNewThread(base::Thread* thread,
MessageBoxType type,
const std::vector<std::string>& buttons,
int cancel_id,
int options,
const std::string& title,
const std::string& message,
const std::string& detail,
const gfx::ImageSkia& icon,
const MessageBoxCallback& callback) {
int result = ShowMessageBox(parent, type, buttons, cancel_id, title, message,
detail, icon);
int result = ShowMessageBox(parent, type, buttons, cancel_id, options, title,
message, detail, icon);
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE, base::Bind(callback, result));
content::BrowserThread::DeleteSoon(
@ -163,6 +171,7 @@ int ShowMessageBox(NativeWindow* parent,
MessageBoxType type,
const std::vector<std::string>& buttons,
int cancel_id,
int options,
const std::string& title,
const std::string& message,
const std::string& detail,
@ -180,6 +189,7 @@ int ShowMessageBox(NativeWindow* parent,
type,
utf16_buttons,
cancel_id,
options,
base::UTF8ToUTF16(title),
base::UTF8ToUTF16(message),
base::UTF8ToUTF16(detail),
@ -190,6 +200,7 @@ void ShowMessageBox(NativeWindow* parent,
MessageBoxType type,
const std::vector<std::string>& buttons,
int cancel_id,
int options,
const std::string& title,
const std::string& message,
const std::string& detail,
@ -207,12 +218,12 @@ void ShowMessageBox(NativeWindow* parent,
unretained->message_loop()->PostTask(
FROM_HERE,
base::Bind(&RunMessageBoxInNewThread, base::Unretained(unretained),
parent, type, buttons, cancel_id, title, message, detail, icon,
callback));
parent, type, buttons, cancel_id, options, title, message,
detail, icon, callback));
}
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());
}