From 16c7c523cf1497880fab6721087345802857fa27 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 28 Aug 2012 13:54:44 -0500 Subject: [PATCH] Native open code now presents the open panel from the browser process This avoids retina resolution issues and ink framework errors that occur when opening dialogs from the chromium renderer process. --- native/atom_cef_client.cpp | 8 +++++++- native/atom_cef_client.h | 1 + native/atom_cef_client_mac.mm | 9 +++++++++ native/v8_extensions/atom.mm | 6 ++++-- native/v8_extensions/native.js | 3 --- native/v8_extensions/native.mm | 21 +-------------------- src/app/keymap.coffee | 4 +--- 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/native/atom_cef_client.cpp b/native/atom_cef_client.cpp index ac6f8351f..9dc342bcf 100644 --- a/native/atom_cef_client.cpp +++ b/native/atom_cef_client.cpp @@ -24,9 +24,15 @@ bool AtomCefClient::OnProcessMessageReceived(CefRefPtr browser, std::string name = message->GetName().ToString(); if (name == "open") { - Open(message->GetArgumentList()->GetString(0)); + if (message->GetArgumentList()->GetSize() == 1) { + Open(message->GetArgumentList()->GetString(0)); + } + else { + Open(); + } return true; } + return false; } diff --git a/native/atom_cef_client.h b/native/atom_cef_client.h index 736abd22b..d8efb338a 100644 --- a/native/atom_cef_client.h +++ b/native/atom_cef_client.h @@ -106,6 +106,7 @@ class AtomCefClient : public CefClient, void ShowDevTools(CefRefPtr browser); void Open(std::string path); + void Open(); IMPLEMENT_REFCOUNTING(AtomCefClient); IMPLEMENT_LOCKING(AtomCefClient); diff --git a/native/atom_cef_client_mac.mm b/native/atom_cef_client_mac.mm index 6f1fd3170..b8a9283e8 100644 --- a/native/atom_cef_client_mac.mm +++ b/native/atom_cef_client_mac.mm @@ -7,4 +7,13 @@ void AtomCefClient::Open(std::string path) { NSString *pathString = [NSString stringWithCString:path.c_str() encoding:NSUTF8StringEncoding]; [(AtomApplication *)[AtomApplication sharedApplication] open:pathString]; +} + +void AtomCefClient::Open() { + NSOpenPanel *panel = [NSOpenPanel openPanel]; + [panel setCanChooseDirectories:YES]; + if ([panel runModal] == NSFileHandlingPanelOKButton) { + NSURL *url = [[panel URLs] lastObject]; + Open([[url path] UTF8String]); + } } \ No newline at end of file diff --git a/native/v8_extensions/atom.mm b/native/v8_extensions/atom.mm index 4042653d7..b4de5eaea 100644 --- a/native/v8_extensions/atom.mm +++ b/native/v8_extensions/atom.mm @@ -24,8 +24,10 @@ namespace v8_extensions { if (name == "open") { CefRefPtr message = CefProcessMessage::Create("open"); CefRefPtr messageArgs = message->GetArgumentList(); - messageArgs->SetSize(1); - messageArgs->SetString(0, arguments[0]->GetStringValue()); + if (arguments.size() >= 1) { + messageArgs->SetSize(1); + messageArgs->SetString(0, arguments[0]->GetStringValue()); + } browser->SendProcessMessage(PID_BROWSER, message); } }; diff --git a/native/v8_extensions/native.js b/native/v8_extensions/native.js index a9a76c7fb..105861a1a 100644 --- a/native/v8_extensions/native.js +++ b/native/v8_extensions/native.js @@ -34,9 +34,6 @@ var $native = {}; native function open(path); $native.open = open; - native function openDialog(); - $native.openDialog = openDialog; - native function quit(); $native.quit = quit; diff --git a/native/v8_extensions/native.mm b/native/v8_extensions/native.mm index d8f1b8094..0be82b38e 100644 --- a/native/v8_extensions/native.mm +++ b/native/v8_extensions/native.mm @@ -211,25 +211,6 @@ bool Native::Execute(const CefString& name, return true; } - else if (name == "openDialog") { - NSOpenPanel *panel = [NSOpenPanel openPanel]; - [panel setCanChooseDirectories:YES]; - if ([panel runModal] == NSFileHandlingPanelOKButton) { - NSURL *url = [[panel URLs] lastObject]; - retval = CefV8Value::CreateString([[url path] UTF8String]); - } - else { - retval = CefV8Value::CreateNull(); - } - - return true; - } - else if (name == "open") { - NSString *path = stringFromCefV8Value(arguments[0]); - [NSApp open:path]; - - return true; - } else if (name == "newWindow") { [(AtomApplication *)NSApp open:nil]; @@ -478,4 +459,4 @@ bool Native::Execute(const CefString& name, return false; }; -} // namespace v8_extensions \ No newline at end of file +} // namespace v8_extensions diff --git a/src/app/keymap.coffee b/src/app/keymap.coffee index 1faa80063..7c75682e2 100644 --- a/src/app/keymap.coffee +++ b/src/app/keymap.coffee @@ -21,9 +21,7 @@ class Keymap $(document).on 'new-window', => $native.newWindow() $(document).on 'open-user-configuration', => atom.open(atom.configFilePath) - $(document).on 'open', => - path = $native.openDialog() - atom.open(path) if path + $(document).on 'open', => atom.open() bindKeys: (selector, bindings) -> index = @bindingSets.length