]> khamidou — GitHub mirrors - electron.git/commitdiff
Allow showing message dialog as sheet.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 7 Jun 2013 07:59:12 +0000 (15:59 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 7 Jun 2013 07:59:12 +0000 (15:59 +0800)
browser/api/atom_api_dialog.cc
browser/api/lib/dialog.coffee
browser/message_box.h
browser/message_box_mac.mm

index 2288f98f456ab795dccc3f0ab152cd0968ae40d8..37633872732296fd0646164fdf53152b365328ee 100644 (file)
@@ -49,6 +49,15 @@ v8::Handle<v8::Value> ShowMessageBox(const v8::Arguments &args) {
       !args[4]->IsString())    // detail
     return node::ThrowTypeError("Bad argument");
 
+  NativeWindow* native_window = NULL;
+  if (args[5]->IsObject()) {
+    Window* window = Window::Unwrap<Window>(args[5]->ToObject());
+    if (!window || !window->window())
+      return node::ThrowError("Invalid window");
+
+    native_window = window->window();
+  }
+
   MessageBoxType type = (MessageBoxType)(args[0]->IntegerValue());
 
   std::vector<std::string> buttons;
@@ -60,7 +69,8 @@ v8::Handle<v8::Value> ShowMessageBox(const v8::Arguments &args) {
   std::string message(*v8::String::Utf8Value(args[3]));
   std::string detail(*v8::String::Utf8Value(args[4]));
 
-  int chosen = atom::ShowMessageBox(type, buttons, title, message, detail);
+  int chosen = atom::ShowMessageBox(
+      native_window, type, buttons, title, message, detail);
   return scope.Close(v8::Integer::New(chosen));
 }
 
index f439e79d35fbfa8b9e335f2f3246f3c29fb8917c..fa606e1ddbdd0b2ce909db53b086f00746c957a6 100644 (file)
@@ -30,7 +30,11 @@ module.exports =
 
     binding.showSaveDialog window, options.title, options.defaultPath
 
-  showMessageBox: (options) ->
+  showMessageBox: (window, options) ->
+    if window?.constructor isnt BrowserWindow
+      options = window
+      window = null
+
     options = type: 'none' unless options?
     options.type = options.type ? 'none'
     options.type = messageBoxTypes.indexOf options.type
@@ -42,7 +46,9 @@ module.exports =
     options.message = options.message ? ''
     options.detail = options.detail ? ''
 
-    binding.showMessageBox options.type, options.buttons,
+    binding.showMessageBox options.type,
+                           options.buttons,
                            String(options.title),
                            String(options.message),
-                           String(options.detail)
+                           String(options.detail),
+                           window
index eef4180d6333fa27cd4b975b8b17e4010b3e4153..02094bedc9c3c8c3165049303cff01c3f621cb3c 100644 (file)
 
 namespace atom {
 
+class NativeWindow;
+
 enum MessageBoxType {
   MESSAGE_BOX_TYPE_NONE = 0,
   MESSAGE_BOX_TYPE_INFORMATION,
   MESSAGE_BOX_TYPE_WARNING
 };
 
-int ShowMessageBox(MessageBoxType type,
+int ShowMessageBox(NativeWindow* parent_window,
+                   MessageBoxType type,
                    const std::vector<std::string>& buttons,
                    const std::string& title,
                    const std::string& message,
index 79dba234eaa15d45b15d5df949bb574c7da9504b..2272f8a587027c96077a844ece03424ac11e5230 100644 (file)
@@ -7,10 +7,13 @@
 #import <Cocoa/Cocoa.h>
 
 #include "base/strings/sys_string_conversions.h"
+#include "browser/native_window.h"
+#include "browser/nsalert_synchronous_sheet.h"
 
 namespace atom {
 
-int ShowMessageBox(MessageBoxType type,
+int ShowMessageBox(NativeWindow* parent_window,
+                   MessageBoxType type,
                    const std::vector<std::string>& buttons,
                    const std::string& title,
                    const std::string& message,
@@ -37,7 +40,10 @@ int ShowMessageBox(MessageBoxType type,
     [button setTag:i];
   }
 
-  return [alert runModal];
+  if (parent_window)
+    return [alert runModalSheetForWindow:parent_window->GetNativeWindow()];
+  else
+    return [alert runModal];
 }
 
 }  // namespace atom