diff --git a/atom/browser/api/atom_api_dialog.cc b/atom/browser/api/atom_api_dialog.cc index 02d820bdeb5f..b5fd655d6f26 100644 --- a/atom/browser/api/atom_api_dialog.cc +++ b/atom/browser/api/atom_api_dialog.cc @@ -41,6 +41,7 @@ namespace { void ShowMessageBox(int type, const std::vector& buttons, + int cancel_id, const std::vector& texts, const gfx::ImageSkia& icon, atom::NativeWindow* window, @@ -57,11 +58,12 @@ void ShowMessageBox(int type, if (mate::Converter::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); } } diff --git a/atom/browser/api/lib/dialog.coffee b/atom/browser/api/lib/dialog.coffee index d95fa7426ac5..9c1c1934759e 100644 --- a/atom/browser/api/lib/dialog.coffee +++ b/atom/browser/api/lib/dialog.coffee @@ -92,9 +92,11 @@ module.exports = options.message ?= '' options.detail ?= '' options.icon ?= null + options.cancelId ?= 0 binding.showMessageBox messageBoxType, options.buttons, + options.cancelId, [options.title, options.message, options.detail], options.icon, window, diff --git a/atom/browser/ui/message_box.h b/atom/browser/ui/message_box.h index acd1e3926b34..817da2c56998 100644 --- a/atom/browser/ui/message_box.h +++ b/atom/browser/ui/message_box.h @@ -32,6 +32,7 @@ typedef base::Callback MessageBoxCallback; int ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int cancel_id, const std::string& title, const std::string& message, const std::string& detail, @@ -40,6 +41,7 @@ int ShowMessageBox(NativeWindow* parent_window, void ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int cancel_id, const std::string& title, const std::string& message, const std::string& detail, diff --git a/atom/browser/ui/message_box_gtk.cc b/atom/browser/ui/message_box_gtk.cc index 626f16704dde..f5a29f42c073 100644 --- a/atom/browser/ui/message_box_gtk.cc +++ b/atom/browser/ui/message_box_gtk.cc @@ -29,12 +29,13 @@ class GtkMessageBox { GtkMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int cancel_id, const std::string& title, const std::string& message, const std::string& detail, const gfx::ImageSkia& icon) : dialog_scope_(parent_window), - cancel_id_(0) { + cancel_id_(cancel_id) { // Create dialog. dialog_ = gtk_message_dialog_new( nullptr, // parent @@ -163,29 +164,31 @@ void GtkMessageBox::OnResponseDialog(GtkWidget* widget, int response) { int ShowMessageBox(NativeWindow* parent, MessageBoxType type, const std::vector& buttons, + int cancel_id, const std::string& title, const std::string& message, const std::string& detail, const gfx::ImageSkia& icon) { - return GtkMessageBox(parent, type, buttons, title, message, detail, + return GtkMessageBox(parent, type, buttons, cancel_id, title, message, detail, icon).RunSynchronous(); } void ShowMessageBox(NativeWindow* parent, MessageBoxType type, const std::vector& buttons, + int cancel_id, const std::string& title, const std::string& message, const std::string& detail, const gfx::ImageSkia& icon, const MessageBoxCallback& callback) { - (new GtkMessageBox(parent, type, buttons, title, message, detail, + (new GtkMessageBox(parent, type, buttons, cancel_id, title, message, detail, icon))->RunAsynchronous(callback); } void ShowErrorBox(const base::string16& title, const base::string16& content) { 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(content).c_str(), gfx::ImageSkia()).RunSynchronous(); diff --git a/atom/browser/ui/message_box_mac.mm b/atom/browser/ui/message_box_mac.mm index b3af25311eaf..8fe3b7d060c3 100644 --- a/atom/browser/ui/message_box_mac.mm +++ b/atom/browser/ui/message_box_mac.mm @@ -94,6 +94,7 @@ void SetReturnCode(int* ret_code, int result) { int ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int cancel_id, const std::string& title, const std::string& message, const std::string& detail, @@ -125,6 +126,7 @@ int ShowMessageBox(NativeWindow* parent_window, void ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int cancel_id, const std::string& title, const std::string& message, const std::string& detail, diff --git a/atom/browser/ui/message_box_win.cc b/atom/browser/ui/message_box_win.cc index 508d6eb233d9..cd2c11048210 100644 --- a/atom/browser/ui/message_box_win.cc +++ b/atom/browser/ui/message_box_win.cc @@ -43,6 +43,7 @@ class MessageDialog : public views::WidgetDelegate, MessageDialog(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int cancel_id, const std::string& title, const std::string& message, const std::string& detail, @@ -85,6 +86,7 @@ class MessageDialog : public views::WidgetDelegate, gfx::ImageSkia icon_; bool delete_on_close_; + int cancel_id_; int result_; base::string16 title_; @@ -125,12 +127,14 @@ class MessageDialogClientView : public views::ClientView { MessageDialog::MessageDialog(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int cancel_id, const std::string& title, const std::string& message, const std::string& detail, const gfx::ImageSkia& icon) : icon_(icon), delete_on_close_(false), + cancel_id_(cancel_id), result_(-1), title_(base::UTF8ToUTF16(title)), parent_(parent_window), @@ -211,7 +215,7 @@ int MessageDialog::GetResult() const { return i; } - return 0; + return cancel_id_; } else { return result_; } @@ -337,12 +341,13 @@ void MessageDialog::ButtonPressed(views::Button* sender, int ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int cancel_id, const std::string& title, const std::string& message, const std::string& detail, const gfx::ImageSkia& icon) { 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::MessageLoopForUI::current()); @@ -357,6 +362,7 @@ int ShowMessageBox(NativeWindow* parent_window, void ShowMessageBox(NativeWindow* parent_window, MessageBoxType type, const std::vector& buttons, + int cancel_id, const std::string& title, const std::string& message, const std::string& detail, @@ -364,7 +370,7 @@ void ShowMessageBox(NativeWindow* parent_window, const MessageBoxCallback& callback) { // The dialog would be deleted when the dialog is closed. 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->Show(); }