]> khamidou — GitHub mirrors - electron.git/commitdiff
Seperate linux's implementation of message box
authorCheng Zhao <zcbenz@gmail.com>
Tue, 7 Jul 2015 07:02:27 +0000 (15:02 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 7 Jul 2015 07:12:08 +0000 (15:12 +0800)
atom/browser/ui/message_box_gtk.cc [new file with mode: 0644]
atom/browser/ui/message_box_win.cc [moved from atom/browser/ui/message_box_views.cc with 90% similarity]
filenames.gypi

diff --git a/atom/browser/ui/message_box_gtk.cc b/atom/browser/ui/message_box_gtk.cc
new file mode 100644 (file)
index 0000000..90a8d4a
--- /dev/null
@@ -0,0 +1,63 @@
+// Copyright (c) 2015 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/browser/ui/message_box.h"
+
+#include <gtk/gtk.h>
+
+#include "atom/browser/browser.h"
+#include "base/callback.h"
+#include "base/strings/utf_string_conversions.h"
+
+#define ANSI_FOREGROUND_RED   "\x1b[31m"
+#define ANSI_FOREGROUND_BLACK "\x1b[30m"
+#define ANSI_TEXT_BOLD        "\x1b[1m"
+#define ANSI_BACKGROUND_GRAY  "\x1b[47m"
+#define ANSI_RESET            "\x1b[0m"
+
+namespace atom {
+
+int ShowMessageBox(NativeWindow* parent_window,
+                   MessageBoxType type,
+                   const std::vector<std::string>& buttons,
+                   const std::string& title,
+                   const std::string& message,
+                   const std::string& detail,
+                   const gfx::ImageSkia& icon) {
+  return 0;
+}
+
+void ShowMessageBox(NativeWindow* parent_window,
+                    MessageBoxType type,
+                    const std::vector<std::string>& buttons,
+                    const std::string& title,
+                    const std::string& message,
+                    const std::string& detail,
+                    const gfx::ImageSkia& icon,
+                    const MessageBoxCallback& callback) {
+  callback.Run(0);
+}
+
+void ShowErrorBox(const base::string16& title, const base::string16& content) {
+  if (Browser::Get()->is_ready()) {
+    GtkWidget* dialog = gtk_message_dialog_new(
+        NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+        "%s", base::UTF16ToUTF8(title).c_str());
+    gtk_message_dialog_format_secondary_text(
+        GTK_MESSAGE_DIALOG(dialog),
+        "%s", base::UTF16ToUTF8(content).c_str());
+    gtk_dialog_run(GTK_DIALOG(dialog));
+    gtk_widget_destroy(dialog);
+  } else {
+    fprintf(stderr,
+            ANSI_TEXT_BOLD ANSI_BACKGROUND_GRAY
+            ANSI_FOREGROUND_RED  "%s\n"
+            ANSI_FOREGROUND_BLACK "%s"
+            ANSI_RESET "\n",
+            base::UTF16ToUTF8(title).c_str(),
+            base::UTF16ToUTF8(content).c_str());
+  }
+}
+
+}  // namespace atom
similarity index 90%
rename from atom/browser/ui/message_box_views.cc
rename to atom/browser/ui/message_box_win.cc
index 6e1cc9daa2ba654b8c7ca32e76ed24a78c373daf..508d6eb233d9d1c4d241118ec1d0be6b1f66805a 100644 (file)
@@ -4,10 +4,6 @@
 
 #include "atom/browser/ui/message_box.h"
 
-#if defined(USE_X11)
-#include <gtk/gtk.h>
-#endif
-
 #include "atom/browser/native_window.h"
 #include "base/callback.h"
 #include "base/message_loop/message_loop.h"
 #include "ui/views/widget/widget_delegate.h"
 #include "ui/wm/core/shadow_types.h"
 
-#if defined(USE_X11)
-#include "atom/browser/browser.h"
-#include "ui/views/window/native_frame_view.h"
-#endif
-
 #if defined(OS_WIN)
 #include "ui/base/win/message_box_win.h"
 #endif
 
-#define ANSI_FOREGROUND_RED   "\x1b[31m"
-#define ANSI_FOREGROUND_BLACK "\x1b[30m"
-#define ANSI_TEXT_BOLD        "\x1b[1m"
-#define ANSI_BACKGROUND_GRAY  "\x1b[47m"
-#define ANSI_RESET            "\x1b[0m"
-
 namespace atom {
 
 namespace {
@@ -276,13 +261,8 @@ ui::ModalType MessageDialog::GetModalType() const {
 
 views::NonClientFrameView* MessageDialog::CreateNonClientFrameView(
     views::Widget* widget) {
-  if (!parent_) {
-#if defined(USE_X11)
-    return new views::NativeFrameView(widget);
-#else
+  if (!parent_)
     return NULL;
-#endif
-  }
 
   // Create a bubble style frame like Chrome.
   views::BubbleFrameView* frame =  new views::BubbleFrameView(gfx::Insets());
@@ -390,28 +370,7 @@ void ShowMessageBox(NativeWindow* parent_window,
 }
 
 void ShowErrorBox(const base::string16& title, const base::string16& content) {
-#if defined(OS_WIN)
   ui::MessageBox(NULL, content, title, MB_OK | MB_ICONERROR | MB_TASKMODAL);
-#elif defined(USE_X11)
-  if (Browser::Get()->is_ready()) {
-    GtkWidget* dialog = gtk_message_dialog_new(
-        NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
-        "%s", base::UTF16ToUTF8(title).c_str());
-    gtk_message_dialog_format_secondary_text(
-        GTK_MESSAGE_DIALOG(dialog),
-        "%s", base::UTF16ToUTF8(content).c_str());
-    gtk_dialog_run(GTK_DIALOG(dialog));
-    gtk_widget_destroy(dialog);
-  } else {
-    fprintf(stderr,
-            ANSI_TEXT_BOLD ANSI_BACKGROUND_GRAY
-            ANSI_FOREGROUND_RED  "%s\n"
-            ANSI_FOREGROUND_BLACK "%s"
-            ANSI_RESET "\n",
-            base::UTF16ToUTF8(title).c_str(),
-            base::UTF16ToUTF8(content).c_str());
-  }
-#endif
 }
 
 }  // namespace atom
index 3f299c066a65ac1968f9cbc70b00cf39b011e27f..837dd3301cc8c3830229e8256e32f1469aab14a8 100644 (file)
       'atom/browser/ui/file_dialog_mac.mm',
       'atom/browser/ui/file_dialog_win.cc',
       'atom/browser/ui/message_box.h',
+      'atom/browser/ui/message_box_gtk.cc',
       'atom/browser/ui/message_box_mac.mm',
-      'atom/browser/ui/message_box_views.cc',
+      'atom/browser/ui/message_box_win.cc',
       'atom/browser/ui/tray_icon.cc',
       'atom/browser/ui/tray_icon.h',
       'atom/browser/ui/tray_icon_gtk.cc',