mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
All of the methods from Native are now implemented in native_handler
This commit is contained in:
@@ -70,10 +70,8 @@
|
||||
CefRefPtr<NativeHandler> nativeHandler = new NativeHandler();
|
||||
global->SetValue("$native", nativeHandler->m_object, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
if (_pathToOpen) {
|
||||
CefRefPtr<CefV8Value> pathToOpen = CefV8Value::CreateString([_pathToOpen UTF8String]);
|
||||
global->SetValue("$pathToOpen", pathToOpen, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
CefRefPtr<CefV8Value> 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);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ NSString *stringFromCefV8Value(const CefRefPtr<CefV8Value>& 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;
|
||||
};
|
||||
};
|
||||
@@ -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) ->
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ windowAdditions =
|
||||
|
||||
setupKeymap: ->
|
||||
@keymap = new GlobalKeymap()
|
||||
|
||||
$(document).on 'keydown', (e) => @keymap.handleKeyEvent(e)
|
||||
|
||||
attachRootView: (url) ->
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user