]> khamidou — GitHub mirrors - electron.git/commitdiff
gtk: Map dialog type to message box type
authorCheng Zhao <zcbenz@gmail.com>
Tue, 7 Jul 2015 08:52:53 +0000 (16:52 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 7 Jul 2015 09:21:30 +0000 (17:21 +0800)
atom/browser/api/lib/dialog.coffee
atom/browser/ui/message_box.h
atom/browser/ui/message_box_gtk.cc
docs/api/dialog.md

index 95ecf99d3e03a05c96ce3045ae2258aac3eed4c4..d95fa7426ac53545cfe9e1187de3c0ee0e54f04e 100644 (file)
@@ -9,7 +9,7 @@ fileDialogProperties =
   multiSelections: 1 << 2
   createDirectory: 1 << 3
 
-messageBoxTypes = ['none', 'info', 'warning']
+messageBoxTypes = ['none', 'info', 'warning', 'error', 'question']
 
 parseArgs = (window, options, callback) ->
   unless window is null or window?.constructor is BrowserWindow
index 04792085b7ae7b91210e28a3d7202515cad9133d..acd1e3926b34bff51d89e4f9a65e774521c2a964 100644 (file)
@@ -22,7 +22,9 @@ class NativeWindow;
 enum MessageBoxType {
   MESSAGE_BOX_TYPE_NONE = 0,
   MESSAGE_BOX_TYPE_INFORMATION,
-  MESSAGE_BOX_TYPE_WARNING
+  MESSAGE_BOX_TYPE_WARNING,
+  MESSAGE_BOX_TYPE_ERROR,
+  MESSAGE_BOX_TYPE_QUESTION,
 };
 
 typedef base::Callback<void(int code)> MessageBoxCallback;
index 571cab5c81c497a2d991a4ec8abb099aa3663d3c..27a15d9553ce2b2e564f86a224b03e3207efb62f 100644 (file)
@@ -41,7 +41,7 @@ class GtkMessageBox {
         nullptr,  // parent
         modal ? GTK_DIALOG_MODAL :   // modal dialog
                 static_cast<GtkDialogFlags>(0),  // no flags
-        GTK_MESSAGE_OTHER,  // no icon
+        GetMessageType(type),  // type
         GTK_BUTTONS_NONE,  // no buttons
         "%s", message.c_str());
     gtk_message_dialog_format_secondary_text(
@@ -75,6 +75,21 @@ class GtkMessageBox {
     gtk_widget_destroy(dialog_);
   }
 
+  GtkMessageType GetMessageType(MessageBoxType type) {
+    switch (type) {
+      case MESSAGE_BOX_TYPE_INFORMATION:
+        return GTK_MESSAGE_INFO;
+      case MESSAGE_BOX_TYPE_WARNING:
+        return GTK_MESSAGE_WARNING;
+      case MESSAGE_BOX_TYPE_QUESTION:
+        return GTK_MESSAGE_QUESTION;
+      case MESSAGE_BOX_TYPE_ERROR:
+        return GTK_MESSAGE_ERROR;
+      default:
+        return GTK_MESSAGE_OTHER;
+    }
+  }
+
   const char* TranslateToStock(int id, const std::string& text) {
     std::string lower = base::StringToLowerASCII(text);
     if (lower == "cancel") {
index f8058649ae577221578ff63ac633556c16d5b84c..30689d95863019e90201686cd341ab258e8a111a 100644 (file)
@@ -70,7 +70,7 @@ will be passed via `callback(filename)`
 
 * `browserWindow` BrowserWindow
 * `options` Object
-  * `type` String - Can be `"none"`, `"info"` or `"warning"`
+  * `type` String - Can be `"none"`, `"info"`, `"error"`, `"question"` or `"warning"`
   * `buttons` Array - Array of texts for buttons
   * `title` String - Title of the message box, some platforms will not show it
   * `message` String - Content of the message box