From d334a26ddc6e5b34a663ed853f433df7ccbaf54b Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Thu, 1 Mar 2012 16:10:47 -0800 Subject: [PATCH] All of the methods from Native are now implemented in native_handler --- Atom/src/AtomController.mm | 6 ++---- Atom/src/native_handler.mm | 22 +++++++++++++++++++--- src/atom/app.coffee | 7 +------ src/atom/global-keymap.coffee | 10 ++++++++++ src/atom/window.coffee | 1 + src/stdlib/native.coffee | 32 -------------------------------- 6 files changed, 33 insertions(+), 45 deletions(-) delete mode 100644 src/stdlib/native.coffee diff --git a/Atom/src/AtomController.mm b/Atom/src/AtomController.mm index e013f308e..f07edbd2a 100644 --- a/Atom/src/AtomController.mm +++ b/Atom/src/AtomController.mm @@ -70,10 +70,8 @@ CefRefPtr nativeHandler = new NativeHandler(); global->SetValue("$native", nativeHandler->m_object, V8_PROPERTY_ATTRIBUTE_NONE); - if (_pathToOpen) { - CefRefPtr pathToOpen = CefV8Value::CreateString([_pathToOpen UTF8String]); - global->SetValue("$pathToOpen", pathToOpen, V8_PROPERTY_ATTRIBUTE_NONE); - } + CefRefPtr pathToOpen = _pathToOpen ? CefV8Value::CreateString([_pathToOpen UTF8String]) : CefV8Value::CreateNull(); + global->SetValue("$pathToOpen", pathToOpen, V8_PROPERTY_ATTRIBUTE_NONE); global->SetValue("atom", _atomContext->GetGlobal()->GetValue("atom"), V8_PROPERTY_ATTRIBUTE_NONE); diff --git a/Atom/src/native_handler.mm b/Atom/src/native_handler.mm index 13244a284..8bc51d0f5 100644 --- a/Atom/src/native_handler.mm +++ b/Atom/src/native_handler.mm @@ -10,7 +10,7 @@ NSString *stringFromCefV8Value(const CefRefPtr& value) { NativeHandler::NativeHandler() : CefV8Handler() { m_object = CefV8Value::CreateObject(NULL); - const char *functionNames[] = {"exists", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools"}; + const char *functionNames[] = {"exists", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools", "newWindow", "saveDialog"}; NSUInteger arrayLength = sizeof(functionNames) / sizeof(const char *); for (NSUInteger i = 0; i < arrayLength; i++) { const char *functionName = functionNames[i]; @@ -214,7 +214,6 @@ bool NativeHandler::Execute(const CefString& name, [panel setCanChooseDirectories:YES]; if ([panel runModal] == NSFileHandlingPanelOKButton) { NSURL *url = [[panel URLs] lastObject]; - NSLog(@"An URL %@", [url path]); retval = CefV8Value::CreateString([[url path] UTF8String]); } else { @@ -229,6 +228,23 @@ bool NativeHandler::Execute(const CefString& name, return true; } + else if (name == "newWindow") { + [NSApp open:nil]; + + return true; + } + else if (name == "saveDialog") { + NSSavePanel *panel = [NSSavePanel savePanel]; + if ([panel runModal] == NSFileHandlingPanelOKButton) { + NSURL *url = [panel URL]; + retval = CefV8Value::CreateString([[url path] UTF8String]); + } + else { + return CefV8Value::CreateNull(); + } + + return true; + } else if (name == "quit") { [NSApp terminate:nil]; return true; @@ -239,4 +255,4 @@ bool NativeHandler::Execute(const CefString& name, } return false; -}; +}; \ No newline at end of file diff --git a/src/atom/app.coffee b/src/atom/app.coffee index cab01e383..ce79e4a83 100644 --- a/src/atom/app.coffee +++ b/src/atom/app.coffee @@ -13,12 +13,7 @@ class App setupKeymap: -> @keymap = new GlobalKeymap() - @keymap.bindKeys "*", - 'meta-o': 'open' - - $(document).on 'open', => - url = $native.openDialog() - @open(url) if url + $(document).on 'keydown', (e) => @keymap.handleKeyEvent(e) open: (url) -> diff --git a/src/atom/global-keymap.coffee b/src/atom/global-keymap.coffee index 22fbf853c..1fe11643c 100644 --- a/src/atom/global-keymap.coffee +++ b/src/atom/global-keymap.coffee @@ -9,6 +9,16 @@ class GlobalKeymap constructor: -> @bindingSets = [] + @bindKeys "*", + 'meta-n': 'newWindow' + 'meta-o': 'open' + + $(document).on 'newWindow', => $native.newWindow() + $(document).on 'open', => + url = $native.openDialog() + atom.open(url) if url + + bindKeys: (selector, bindings) -> @bindingSets.unshift(new BindingSet(selector, bindings)) diff --git a/src/atom/window.coffee b/src/atom/window.coffee index c3bc6a688..d9d1c95cb 100644 --- a/src/atom/window.coffee +++ b/src/atom/window.coffee @@ -31,6 +31,7 @@ windowAdditions = setupKeymap: -> @keymap = new GlobalKeymap() + $(document).on 'keydown', (e) => @keymap.handleKeyEvent(e) attachRootView: (url) -> diff --git a/src/stdlib/native.coffee b/src/stdlib/native.coffee deleted file mode 100644 index 332b5909a..000000000 --- a/src/stdlib/native.coffee +++ /dev/null @@ -1,32 +0,0 @@ -_ = require 'underscore' - -module.exports = -class Native - constructor: (nativeMethods)-> - _.extend(this, nativeMethods) - - alert: (message, detailedMessage, buttons) -> - $native.alert(message, detailedMessage, buttons) - - # path - Optional. The String path to the file to base it on. - newWindow: (path) -> - controller = OSX.NSApp.createController path - controller.window - controller.window.makeKeyAndOrderFront null - - # Returns null or a file path. - openPanel: -> - $native.openPanel() - - # Returns null or a file path. - savePanel: -> - panel = OSX.NSSavePanel.savePanel - if panel.runModal isnt OSX.NSFileHandlingPanelOKButton - return null - panel.filenames.lastObject.valueOf() - - writeToPasteboard: (text) -> - $native.writeToPasteboard text - - readFromPasteboard: -> - $native.readFromPasteboard() \ No newline at end of file