]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix style issues of #4029
authorCheng Zhao <zcbenz@gmail.com>
Mon, 11 Jan 2016 13:12:07 +0000 (21:12 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 11 Jan 2016 13:12:07 +0000 (21:12 +0800)
atom/browser/api/atom_api_dialog.cc
atom/browser/ui/message_box_gtk.cc
atom/browser/ui/message_box_mac.mm
atom/browser/ui/message_box_win.cc

index 3ff53352cba196968768df2b5d8aad0267429c12..0a544c56468cb67dce5793a15535a772bc2b17de 100644 (file)
@@ -57,7 +57,7 @@ void ShowMessageBox(int type,
                                                         &callback)) {
     atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons,
                          default_id, cancel_id, options, title,
-                        message, detail, icon, callback);
+                         message, detail, icon, callback);
   } else {
     int chosen = atom::ShowMessageBox(window, (atom::MessageBoxType)type,
                                       buttons, default_id, cancel_id,
index fe1068effd7c7f3fd0c2d1582e5bde5a47df17e6..9615e958b27574e5f8858752525848079860ba19 100644 (file)
@@ -61,16 +61,10 @@ class GtkMessageBox {
 
     // Add buttons.
     for (size_t i = 0; i < buttons.size(); ++i) {
-      if (i == (size_t)default_id) {
-        GtkWidget* button = gtk_dialog_add_button(GTK_DIALOG(dialog_),
-                              TranslateToStock(i, buttons[i]),
-                              i);
+      GtkWidget* button = gtk_dialog_add_button(
+          GTK_DIALOG(dialog_), TranslateToStock(i, buttons[i]), i);
+      if (static_cast<int>(i) == default_id)
         gtk_widget_grab_focus(button);
-      } else {
-          gtk_dialog_add_button(GTK_DIALOG(dialog_),
-                            TranslateToStock(i, buttons[i]),
-                            i);
-      }
     }
 
     // Parent window.
@@ -177,7 +171,7 @@ int ShowMessageBox(NativeWindow* parent,
                    const std::string& detail,
                    const gfx::ImageSkia& icon) {
   return GtkMessageBox(parent, type, buttons, default_id, cancel_id,
-                      title, message, detail, icon).RunSynchronous();
+                       title, message, detail, icon).RunSynchronous();
 }
 
 void ShowMessageBox(NativeWindow* parent,
@@ -192,7 +186,7 @@ void ShowMessageBox(NativeWindow* parent,
                     const gfx::ImageSkia& icon,
                     const MessageBoxCallback& callback) {
   (new GtkMessageBox(parent, type, buttons, default_id, cancel_id,
-                    title, message, detail, icon))->RunAsynchronous(callback);
+                     title, message, detail, icon))->RunAsynchronous(callback);
 }
 
 void ShowErrorBox(const base::string16& title, const base::string16& content) {
index 3acc46ec82f1506fe81eb4f45c3f60bf7470f46c..f9e9718ebf55ee3a674e8dc640719b0eeffada8a 100644 (file)
@@ -79,17 +79,17 @@ NSAlert* CreateNSAlert(NativeWindow* parent_window,
     // An empty title causes crash on OS X.
     if (buttons[i].empty())
       title = @"(empty)";
-
     NSButton* button = [alert addButtonWithTitle:title];
     [button setTag:i];
+  }
 
-    if (i == (size_t)default_id) {
-      // Focus the button at default_id if the user opted to do so.
-      // The first button added gets set as the default selected.
-      // So remove that default, and make the requested button the default.
-      [[[alert buttons] objectAtIndex:0] setKeyEquivalent:@""];
-      [button setKeyEquivalent:@"\r"];
-    }
+  NSArray* ns_buttons = [alert buttons];
+  if (default_id >= 0 && default_id < static_cast<int>([ns_buttons count])) {
+    // Focus the button at default_id if the user opted to do so.
+    // The first button added gets set as the default selected.
+    // So remove that default, and make the requested button the default.
+    [[ns_buttons objectAtIndex:0] setKeyEquivalent:@""];
+    [[ns_buttons objectAtIndex:default_id] setKeyEquivalent:@"\r"];
   }
 
   return alert;
index 253733de59dfd6b02ef22ed3dde7cb7bdef30d69..2847ae21a1649fa500e352ca2e8848d82ac59131 100644 (file)
@@ -84,11 +84,13 @@ int ShowMessageBoxUTF16(HWND parent,
       TDF_ALLOW_DIALOG_CANCELLATION;  // Allow canceling the dialog.
 
   TASKDIALOGCONFIG config = { 0 };
-  config.cbSize           = sizeof(config);
-  config.hwndParent       = parent;
-  config.hInstance        = GetModuleHandle(NULL);
-  config.dwFlags          = flags;
-  config.nDefaultButton   = default_id ? (kIDStart + default_id) : 0;
+  config.cbSize     = sizeof(config);
+  config.hwndParent = parent;
+  config.hInstance  = GetModuleHandle(NULL);
+  config.dwFlags    = flags;
+
+  if (default_id > 0)
+    config.nDefaultButton = kIDStart + default_id;
 
   // TaskDialogIndirect doesn't allow empty name, if we set empty title it
   // will show "electron.exe" in title.
@@ -230,13 +232,13 @@ void ShowMessageBox(NativeWindow* parent,
   unretained->message_loop()->PostTask(
       FROM_HERE,
       base::Bind(&RunMessageBoxInNewThread, base::Unretained(unretained),
-                 parent, type, buttons, default_id,
-                 cancel_id, options, title, message, detail, icon, callback));
+                 parent, type, buttons, default_id, cancel_id, options, title,
+                 message, detail, icon, callback));
 }
 
 void ShowErrorBox(const base::string16& title, const base::string16& content) {
   ShowMessageBoxUTF16(NULL, MESSAGE_BOX_TYPE_ERROR, {}, -1, 0, 0, L"Error",
-                                        title, content, gfx::ImageSkia());
+                      title, content, gfx::ImageSkia());
 }
 
 }  // namespace atom