Browse Source

Add cancelId option for showMessageBox

Cheng Zhao 9 years ago
parent
commit
b158427271

+ 5 - 3
atom/browser/api/atom_api_dialog.cc

@@ -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);
   }
 }

+ 2 - 0
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,

+ 2 - 0
atom/browser/ui/message_box.h

@@ -32,6 +32,7 @@ typedef base::Callback<void(int code)> MessageBoxCallback;
 int ShowMessageBox(NativeWindow* parent_window,
                    MessageBoxType type,
                    const std::vector<std::string>& 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<std::string>& buttons,
+                    int cancel_id,
                     const std::string& title,
                     const std::string& message,
                     const std::string& detail,

+ 7 - 4
atom/browser/ui/message_box_gtk.cc

@@ -29,12 +29,13 @@ class GtkMessageBox {
   GtkMessageBox(NativeWindow* parent_window,
                 MessageBoxType type,
                 const std::vector<std::string>& 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<std::string>& 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<std::string>& 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();

+ 2 - 0
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<std::string>& 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<std::string>& buttons,
+                    int cancel_id,
                     const std::string& title,
                     const std::string& message,
                     const std::string& detail,

+ 9 - 3
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<std::string>& 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<std::string>& 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<std::string>& 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<std::string>& 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();
 }