Browse Source

Add noLink option for showMessageBox

Cheng Zhao 9 years ago
parent
commit
cc2a9f617d

+ 6 - 1
atom/browser/api/lib/dialog.coffee

@@ -11,6 +11,9 @@ fileDialogProperties =
 
 messageBoxTypes = ['none', 'info', 'warning', 'error', 'question']
 
+messageBoxOptions =
+  noLink: 1 << 0
+
 parseArgs = (window, options, callback) ->
   unless window is null or window?.constructor is BrowserWindow
     # Shift.
@@ -101,10 +104,12 @@ module.exports =
           options.cancelId = i
           break
 
+    flags = if options.noLink then messageBoxOptions.noLink else 0
+
     binding.showMessageBox messageBoxType,
                            options.buttons,
                            options.cancelId,
-                           0,
+                           flags,
                            options.title,
                            options.message,
                            options.detail,

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

@@ -28,8 +28,8 @@ enum MessageBoxType {
 };
 
 enum MessageBoxOptions {
-  MESSAGE_BOX_NONE     = 0,
-  MESSAGE_BOX_NO_LINKS = 1 << 0,
+  MESSAGE_BOX_NONE    = 0,
+  MESSAGE_BOX_NO_LINK = 1 << 0,
 };
 
 typedef base::Callback<void(int code)> MessageBoxCallback;

+ 5 - 2
atom/browser/ui/message_box_win.cc

@@ -72,6 +72,7 @@ int ShowMessageBoxUTF16(HWND parent,
                         MessageBoxType type,
                         const std::vector<base::string16>& buttons,
                         int cancel_id,
+                        int options,
                         const base::string16& title,
                         const base::string16& message,
                         const base::string16& detail,
@@ -126,7 +127,8 @@ int ShowMessageBoxUTF16(HWND parent,
   if (dialog_buttons.size() > 0) {
     config.pButtons = &dialog_buttons.front();
     config.cButtons = dialog_buttons.size();
-    config.dwFlags |= TDF_USE_COMMAND_LINKS;  // custom buttons as links.
+    if (!(options & MESSAGE_BOX_NO_LINK))
+      config.dwFlags |= TDF_USE_COMMAND_LINKS;  // custom buttons as links.
   }
 
   int id = 0;
@@ -181,6 +183,7 @@ int ShowMessageBox(NativeWindow* parent,
                              type,
                              utf16_buttons,
                              cancel_id,
+                             options,
                              base::UTF8ToUTF16(title),
                              base::UTF8ToUTF16(message),
                              base::UTF8ToUTF16(detail),
@@ -214,7 +217,7 @@ void ShowMessageBox(NativeWindow* parent,
 }
 
 void ShowErrorBox(const base::string16& title, const base::string16& content) {
-  ShowMessageBoxUTF16(NULL, MESSAGE_BOX_TYPE_ERROR, {}, 0, L"Error", title,
+  ShowMessageBoxUTF16(NULL, MESSAGE_BOX_TYPE_ERROR, {}, 0, 0, L"Error", title,
                       content, gfx::ImageSkia());
 }
 

+ 6 - 1
docs/api/dialog.md

@@ -80,7 +80,12 @@ will be passed via `callback(filename)`
     instead of clicking the buttons of the dialog. By default it is the index
     of the buttons that have "cancel" or "no" as label, or 0 if there is no such
     buttons. On OS X and Windows the index of "Cancel" button will always be
-    used as `cancelId`, not matter whether it is already specified.
+    used as `cancelId`, not matter whether it is already specified
+  * `noLink` Boolean - On Windows Electron would try to figure out which ones of
+    the `buttons` are common buttons (like "Cancel" or "Yes"), and show the
+    others as command links in the dialog, this can make the dialog appear in
+    the style of modern Windows apps. If you don't like this behavior, you can
+    specify `noLink` to `true`
 * `callback` Function
 
 Shows a message box, it will block until the message box is closed. It returns