]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Run async open dialog in new thread
authorCheng Zhao <zcbenz@gmail.com>
Tue, 16 Dec 2014 19:27:38 +0000 (11:27 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 16 Dec 2014 19:27:38 +0000 (11:27 -0800)
atom/browser/ui/file_dialog_win.cc
common.gypi

index 0bd0c521af8731dfee11c44d3473f96e0cf9ed43..804c0b2791399197afe58133cf749424005acda1 100644 (file)
@@ -15,6 +15,7 @@
 #include "base/strings/string_util.h"
 #include "base/strings/string_split.h"
 #include "base/strings/utf_string_conversions.h"
+#include "base/threading/thread.h"
 #include "base/win/registry.h"
 #include "third_party/wtl/include/atlapp.h"
 #include "third_party/wtl/include/atldlgs.h"
@@ -113,6 +114,26 @@ class FileDialog {
   DISALLOW_COPY_AND_ASSIGN(FileDialog);
 };
 
+struct RunState {
+  base::Thread* dialog_thread;
+  base::MessageLoop* ui_message_loop;
+};
+
+void RunOpenDialogInNewThread(const RunState& run_state,
+                              atom::NativeWindow* parent,
+                              const std::string& title,
+                              const base::FilePath& default_path,
+                              const Filters& filters,
+                              int properties,
+                              const OpenDialogCallback& callback) {
+  std::vector<base::FilePath> paths;
+  bool result = ShowOpenDialog(parent, title, default_path, filters, properties,
+                               &paths);
+  run_state.ui_message_loop->PostTask(FROM_HERE,
+                                      base::Bind(callback, result, paths));
+  run_state.ui_message_loop->DeleteSoon(FROM_HERE, run_state.dialog_thread);
+}
+
 }  // namespace
 
 bool ShowOpenDialog(atom::NativeWindow* parent_window,
@@ -162,20 +183,27 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
   return true;
 }
 
-void ShowOpenDialog(atom::NativeWindow* parent_window,
+void ShowOpenDialog(atom::NativeWindow* parent,
                     const std::string& title,
                     const base::FilePath& default_path,
                     const Filters& filters,
                     int properties,
                     const OpenDialogCallback& callback) {
-  std::vector<base::FilePath> paths;
-  bool result = ShowOpenDialog(parent_window,
-                               title,
-                               default_path,
-                               filters,
-                               properties,
-                               &paths);
-  callback.Run(result, paths);
+  base::Thread* thread = new base::Thread("AtomShell_FileDialogThread");
+  thread->init_com_with_mta(false);
+  if (!thread->Start())
+    return;
+
+  if (parent)
+    EnableWindow(
+        static_cast<atom::NativeWindowViews*>(parent)->GetAcceleratedWidget(),
+        FALSE);
+
+  RunState state = { thread, base::MessageLoop::current() };
+  thread->message_loop()->PostTask(
+      FROM_HERE,
+      base::Bind(&RunOpenDialogInNewThread, state, parent, title, default_path,
+                 filters, properties, callback));
 }
 
 bool ShowSaveDialog(atom::NativeWindow* parent_window,
index 7ee6d494a4dcbe981ab64d04f82b742180236dea..68d9418f23ed466340e50e0c67d33732684380df 100644 (file)
       4005,  # (node.h) macro redefinition
       4189,  # local variable is initialized but not referenced
       4201,  # (uv.h) nameless struct/union
+      4503,  # decorated name length exceeded, name was truncated
       4800,  # (v8.h) forcing value to bool 'true' or 'false'
       4819,  # The file contains a character that cannot be represented in the current code page
       4996,  # (atlapp.h) 'GetVersionExW': was declared deprecated