Add cancelId option for showMessageBox
This commit is contained in:
parent
083d0b8b60
commit
b158427271
6 changed files with 27 additions and 10 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 cancel_id,
|
||||||
const std::vector<std::string>& texts,
|
const std::vector<std::string>& texts,
|
||||||
const gfx::ImageSkia& icon,
|
const gfx::ImageSkia& icon,
|
||||||
atom::NativeWindow* window,
|
atom::NativeWindow* window,
|
||||||
|
@ -57,11 +58,12 @@ 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, title,
|
atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, cancel_id,
|
||||||
message, detail, icon, callback);
|
title, message, detail, icon, callback);
|
||||||
} else {
|
} else {
|
||||||
int chosen = atom::ShowMessageBox(window, (atom::MessageBoxType)type,
|
int chosen = atom::ShowMessageBox(window, (atom::MessageBoxType)type,
|
||||||
buttons, title, message, detail, icon);
|
buttons, cancel_id, title, message,
|
||||||
|
detail, icon);
|
||||||
args->Return(chosen);
|
args->Return(chosen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,9 +92,11 @@ module.exports =
|
||||||
options.message ?= ''
|
options.message ?= ''
|
||||||
options.detail ?= ''
|
options.detail ?= ''
|
||||||
options.icon ?= null
|
options.icon ?= null
|
||||||
|
options.cancelId ?= 0
|
||||||
|
|
||||||
binding.showMessageBox messageBoxType,
|
binding.showMessageBox messageBoxType,
|
||||||
options.buttons,
|
options.buttons,
|
||||||
|
options.cancelId,
|
||||||
[options.title, options.message, options.detail],
|
[options.title, options.message, options.detail],
|
||||||
options.icon,
|
options.icon,
|
||||||
window,
|
window,
|
||||||
|
|
|
@ -32,6 +32,7 @@ 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,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
@ -40,6 +41,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 cancel_id,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
|
|
@ -29,12 +29,13 @@ class GtkMessageBox {
|
||||||
GtkMessageBox(NativeWindow* parent_window,
|
GtkMessageBox(NativeWindow* parent_window,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int cancel_id,
|
||||||
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)
|
||||||
: dialog_scope_(parent_window),
|
: dialog_scope_(parent_window),
|
||||||
cancel_id_(0) {
|
cancel_id_(cancel_id) {
|
||||||
// Create dialog.
|
// Create dialog.
|
||||||
dialog_ = gtk_message_dialog_new(
|
dialog_ = gtk_message_dialog_new(
|
||||||
nullptr, // parent
|
nullptr, // parent
|
||||||
|
@ -163,29 +164,31 @@ void GtkMessageBox::OnResponseDialog(GtkWidget* widget, int response) {
|
||||||
int ShowMessageBox(NativeWindow* parent,
|
int ShowMessageBox(NativeWindow* parent,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int cancel_id,
|
||||||
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) {
|
||||||
return GtkMessageBox(parent, type, buttons, title, message, detail,
|
return GtkMessageBox(parent, type, buttons, cancel_id, title, message, detail,
|
||||||
icon).RunSynchronous();
|
icon).RunSynchronous();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowMessageBox(NativeWindow* parent,
|
void ShowMessageBox(NativeWindow* parent,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int cancel_id,
|
||||||
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) {
|
||||||
(new GtkMessageBox(parent, type, buttons, title, message, detail,
|
(new GtkMessageBox(parent, type, buttons, cancel_id, title, message, detail,
|
||||||
icon))->RunAsynchronous(callback);
|
icon))->RunAsynchronous(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowErrorBox(const base::string16& title, const base::string16& content) {
|
void ShowErrorBox(const base::string16& title, const base::string16& content) {
|
||||||
if (Browser::Get()->is_ready()) {
|
if (Browser::Get()->is_ready()) {
|
||||||
GtkMessageBox(nullptr, MESSAGE_BOX_TYPE_ERROR, { "OK" }, "Error",
|
GtkMessageBox(nullptr, MESSAGE_BOX_TYPE_ERROR, { "OK" }, 0, "Error",
|
||||||
base::UTF16ToUTF8(title).c_str(),
|
base::UTF16ToUTF8(title).c_str(),
|
||||||
base::UTF16ToUTF8(content).c_str(),
|
base::UTF16ToUTF8(content).c_str(),
|
||||||
gfx::ImageSkia()).RunSynchronous();
|
gfx::ImageSkia()).RunSynchronous();
|
||||||
|
|
|
@ -94,6 +94,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 cancel_id,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
@ -125,6 +126,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 cancel_id,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
|
|
@ -43,6 +43,7 @@ class MessageDialog : public views::WidgetDelegate,
|
||||||
MessageDialog(NativeWindow* parent_window,
|
MessageDialog(NativeWindow* parent_window,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int cancel_id,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
@ -85,6 +86,7 @@ class MessageDialog : public views::WidgetDelegate,
|
||||||
gfx::ImageSkia icon_;
|
gfx::ImageSkia icon_;
|
||||||
|
|
||||||
bool delete_on_close_;
|
bool delete_on_close_;
|
||||||
|
int cancel_id_;
|
||||||
int result_;
|
int result_;
|
||||||
base::string16 title_;
|
base::string16 title_;
|
||||||
|
|
||||||
|
@ -125,12 +127,14 @@ class MessageDialogClientView : public views::ClientView {
|
||||||
MessageDialog::MessageDialog(NativeWindow* parent_window,
|
MessageDialog::MessageDialog(NativeWindow* parent_window,
|
||||||
MessageBoxType type,
|
MessageBoxType type,
|
||||||
const std::vector<std::string>& buttons,
|
const std::vector<std::string>& buttons,
|
||||||
|
int cancel_id,
|
||||||
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)
|
||||||
: icon_(icon),
|
: icon_(icon),
|
||||||
delete_on_close_(false),
|
delete_on_close_(false),
|
||||||
|
cancel_id_(cancel_id),
|
||||||
result_(-1),
|
result_(-1),
|
||||||
title_(base::UTF8ToUTF16(title)),
|
title_(base::UTF8ToUTF16(title)),
|
||||||
parent_(parent_window),
|
parent_(parent_window),
|
||||||
|
@ -211,7 +215,7 @@ int MessageDialog::GetResult() const {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return cancel_id_;
|
||||||
} else {
|
} else {
|
||||||
return result_;
|
return result_;
|
||||||
}
|
}
|
||||||
|
@ -337,12 +341,13 @@ void MessageDialog::ButtonPressed(views::Button* sender,
|
||||||
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,
|
||||||
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) {
|
||||||
MessageDialog dialog(
|
MessageDialog dialog(
|
||||||
parent_window, type, buttons, title, message, detail, icon);
|
parent_window, type, buttons, cancel_id, title, message, detail, icon);
|
||||||
{
|
{
|
||||||
base::MessageLoop::ScopedNestableTaskAllower allow(
|
base::MessageLoop::ScopedNestableTaskAllower allow(
|
||||||
base::MessageLoopForUI::current());
|
base::MessageLoopForUI::current());
|
||||||
|
@ -357,6 +362,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 cancel_id,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail,
|
const std::string& detail,
|
||||||
|
@ -364,7 +370,7 @@ void ShowMessageBox(NativeWindow* parent_window,
|
||||||
const MessageBoxCallback& callback) {
|
const MessageBoxCallback& callback) {
|
||||||
// The dialog would be deleted when the dialog is closed.
|
// The dialog would be deleted when the dialog is closed.
|
||||||
MessageDialog* dialog = new MessageDialog(
|
MessageDialog* dialog = new MessageDialog(
|
||||||
parent_window, type, buttons, title, message, detail, icon);
|
parent_window, type, buttons, cancel_id, title, message, detail, icon);
|
||||||
dialog->set_callback(callback);
|
dialog->set_callback(callback);
|
||||||
dialog->Show();
|
dialog->Show();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue