]> khamidou — GitHub mirrors - electron.git/commitdiff
Set default cancelId in JavaScript
authorCheng Zhao <zcbenz@gmail.com>
Tue, 7 Jul 2015 10:33:11 +0000 (18:33 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 7 Jul 2015 10:39:08 +0000 (18:39 +0800)
atom/browser/api/lib/dialog.coffee
atom/browser/ui/message_box_gtk.cc
atom/browser/ui/message_box_win.cc

index 9c1c1934759e3ec35cc0d723ec0ba5a32a2329be..3dbd80a25ef35724471452dbf97c7eb3cce34aa6 100644 (file)
@@ -92,7 +92,13 @@ module.exports =
     options.message ?= ''
     options.detail ?= ''
     options.icon ?= null
-    options.cancelId ?= 0
+
+    unless options.cancelId?
+      options.cancelId = 0
+      for text, i in options.buttons
+        if text.toLowerCase() in ['cancel', 'no']
+          options.cancelId = i
+          break
 
     binding.showMessageBox messageBoxType,
                            options.buttons,
index f5a29f42c073dc2b28c68f6c6ade06951df70635..07695d49845c7889196bf5f4af65d7ed99019c76 100644 (file)
@@ -93,19 +93,16 @@ class GtkMessageBox {
 
   const char* TranslateToStock(int id, const std::string& text) {
     std::string lower = base::StringToLowerASCII(text);
-    if (lower == "cancel") {
-      cancel_id_ = id;
+    if (lower == "cancel")
       return GTK_STOCK_CANCEL;
-    } else if (lower == "no") {
-      cancel_id_ = id;
+    else if (lower == "no")
       return GTK_STOCK_NO;
-    } else if (lower == "ok") {
+    else if (lower == "ok")
       return GTK_STOCK_OK;
-    } else if (lower == "yes") {
+    else if (lower == "yes")
       return GTK_STOCK_YES;
-    } else {
+    else
       return text.c_str();
-    }
   }
 
   void Show() {
index cd2c1104821088f04103a054e78c3d411eacbb73..e613b9aeb00b034559cdefe96185d6effed57629 100644 (file)
@@ -207,18 +207,10 @@ void MessageDialog::Close() {
 }
 
 int MessageDialog::GetResult() const {
-  // When the dialog is closed without choosing anything, we think the user
-  // chose 'Cancel', otherwise we think the default behavior is chosen.
-  if (result_ == -1) {
-    for (size_t i = 0; i < buttons_.size(); ++i)
-      if (LowerCaseEqualsASCII(buttons_[i]->GetText(), "cancel")) {
-        return i;
-      }
-
+  if (result_ == -1)
     return cancel_id_;
-  } else {
+  else
     return result_;
-  }
 }
 
 ////////////////////////////////////////////////////////////////////////////////