Browse Source

Final cleanup

Cheng Zhao 9 years ago
parent
commit
001b4a3179
2 changed files with 20 additions and 13 deletions
  1. 2 1
      atom/browser/api/lib/dialog.coffee
  2. 18 12
      atom/browser/ui/message_box_win.cc

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

@@ -113,4 +113,5 @@ module.exports =
     binding.showErrorBox args...
 
 # Mark standard asynchronous functions.
-v8Util.setHiddenValue f, 'asynchronous', true for k, f of module.exports
+for api in ['showMessageBox', 'showOpenDialog', 'showSaveDialog']
+  v8Util.setHiddenValue module.exports[api], 'asynchronous', true

+ 18 - 12
atom/browser/ui/message_box_win.cc

@@ -4,12 +4,12 @@
 
 #include "atom/browser/ui/message_box.h"
 
-#include <map>
-#include <vector>
-
 #include <windows.h>
 #include <commctrl.h>
 
+#include <map>
+#include <vector>
+
 #include "atom/browser/native_window_views.h"
 #include "base/callback.h"
 #include "base/strings/string_util.h"
@@ -76,17 +76,18 @@ int ShowMessageBoxUTF16(HWND parent,
                         const base::string16& message,
                         const base::string16& detail,
                         const gfx::ImageSkia& icon) {
-  TASKDIALOG_FLAGS flags = TDF_SIZE_TO_CONTENT |  // show all content.
-                           TDF_USE_COMMAND_LINKS;  // custom buttons as links.
+  TASKDIALOG_FLAGS flags = TDF_SIZE_TO_CONTENT;  // show all content.
   if (cancel_id != 0)
     flags |= TDF_ALLOW_DIALOG_CANCELLATION;  // allow dialog to be cancelled.
 
   TASKDIALOGCONFIG config = { 0 };
-  config.cbSize         = sizeof(config);
-  config.hwndParent     = parent;
-  config.hInstance      = GetModuleHandle(NULL);
-  config.dwFlags        = flags;
-  config.pszWindowTitle = title.c_str();
+  config.cbSize     = sizeof(config);
+  config.hwndParent = parent;
+  config.hInstance  = GetModuleHandle(NULL);
+  config.dwFlags    = flags;
+
+  if (!title.empty())
+    config.pszWindowTitle = title.c_str();
 
   base::win::ScopedHICON hicon;
   if (!icon.isNull()) {
@@ -121,8 +122,11 @@ int ShowMessageBoxUTF16(HWND parent,
   std::map<int, int> id_map;
   std::vector<TASKDIALOG_BUTTON> dialog_buttons;
   MapToCommonID(buttons, &id_map, &config.dwCommonButtons, &dialog_buttons);
-  config.pButtons = &dialog_buttons.front();
-  config.cButtons = dialog_buttons.size();
+  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.
+  }
 
   int id = 0;
   TaskDialogIndirect(&config, &id, NULL, NULL);
@@ -207,6 +211,8 @@ void ShowMessageBox(NativeWindow* parent,
 }
 
 void ShowErrorBox(const base::string16& title, const base::string16& content) {
+  ShowMessageBoxUTF16(NULL, MESSAGE_BOX_TYPE_ERROR, {}, 0, L"Error", title,
+                      content, gfx::ImageSkia());
 }
 
 }  // namespace atom