diff --git a/Atom/src/Atom.mm b/Atom/src/Atom.mm index 7afe49948..955d0c5a5 100755 --- a/Atom/src/Atom.mm +++ b/Atom/src/Atom.mm @@ -91,12 +91,12 @@ CefRefPtr bootstrapScript = CefV8Value::CreateString("atom-bootstrap"); global->SetValue("$bootstrapScript", bootstrapScript, V8_PROPERTY_ATTRIBUTE_NONE); + CefRefPtr nativeHandler = new NativeHandler(); + global->SetValue("$native", nativeHandler->m_object, V8_PROPERTY_ATTRIBUTE_NONE); + CefRefPtr atom = CefV8Value::CreateObject(NULL); global->SetValue("atom", atom, V8_PROPERTY_ATTRIBUTE_NONE); - - CefRefPtr nativeHandler = new NativeHandler(); - atom->SetValue("native", nativeHandler->m_object, V8_PROPERTY_ATTRIBUTE_NONE); - + CefRefPtr loadPath = CefV8Value::CreateString(PROJECT_DIR); atom->SetValue("loadPath", loadPath, V8_PROPERTY_ATTRIBUTE_NONE); diff --git a/Atom/src/AtomController.mm b/Atom/src/AtomController.mm index 511cd6242..e013f308e 100644 --- a/Atom/src/AtomController.mm +++ b/Atom/src/AtomController.mm @@ -2,6 +2,7 @@ #import "include/cef.h" #import "client_handler.h" +#import "native_handler.h" @implementation AtomController @@ -66,6 +67,9 @@ CefRefPtr bootstrapScript = CefV8Value::CreateString([_bootstrapScript UTF8String]); global->SetValue("$bootstrapScript", bootstrapScript, V8_PROPERTY_ATTRIBUTE_NONE); + 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); diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index a573f7ecb..b06e0e974 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -731,21 +731,21 @@ describe "Editor", -> describe "cut, copy & paste", -> beforeEach -> - atom.native.writeToPasteboard('first') - expect(atom.native.readFromPasteboard()).toBe 'first' + $native.writeToPasteboard('first') + expect($native.readFromPasteboard()).toBe 'first' describe "when a cut event is triggered", -> it "removes the selected text from the buffer and places it on the pasteboard", -> editor.getSelection().setBufferRange new Range([0,4], [0,9]) editor.trigger "cut" expect(editor.buffer.getLine(0)).toBe "var sort = function () {" - expect(atom.native.readFromPasteboard()).toBe 'quick' + expect($native.readFromPasteboard()).toBe 'quick' describe "when a copy event is triggered", -> it "copies selected text onto the clipboard", -> editor.getSelection().setBufferRange new Range([0,4], [0, 13]) editor.trigger "copy" - expect(atom.native.readFromPasteboard()).toBe 'quicksort' + expect($native.readFromPasteboard()).toBe 'quicksort' describe "when a paste event is triggered", -> it "pastes text into the buffer", -> diff --git a/spec/atom/selection-spec.coffee b/spec/atom/selection-spec.coffee index 886c97d6f..fc696c3f2 100644 --- a/spec/atom/selection-spec.coffee +++ b/spec/atom/selection-spec.coffee @@ -120,44 +120,44 @@ describe "Selection", -> describe ".cut()", -> beforeEach -> - atom.native.writeToPasteboard('first') - expect(atom.native.readFromPasteboard()).toBe 'first' + $native.writeToPasteboard('first') + expect($native.readFromPasteboard()).toBe 'first' it "removes selected text from the buffer and places it on the clipboard", -> selection.setBufferRange new Range([0,4], [0,13]) selection.cut() - expect(atom.native.readFromPasteboard()).toBe 'quicksort' + expect($native.readFromPasteboard()).toBe 'quicksort' expect(editor.buffer.getLine(0)).toBe "var = function () {" expect(selection.isEmpty()).toBeTruthy() selection.setBufferRange new Range([1,6], [3,8]) selection.cut() - expect(atom.native.readFromPasteboard()).toBe "sort = function(items) {\n if (items.length <= 1) return items;\n var " + expect($native.readFromPasteboard()).toBe "sort = function(items) {\n if (items.length <= 1) return items;\n var " expect(editor.buffer.getLine(1)).toBe " var pivot = items.shift(), current, left = [], right = [];" it "places nothing on the clipboard when there is no selection", -> selection.setBufferRange new Range([0,4], [0,4]) selection.copy() - expect(atom.native.readFromPasteboard()).toBe 'first' + expect($native.readFromPasteboard()).toBe 'first' describe ".copy()", -> beforeEach -> - atom.native.writeToPasteboard('first') - expect(atom.native.readFromPasteboard()).toBe 'first' + $native.writeToPasteboard('first') + expect($native.readFromPasteboard()).toBe 'first' it "places selected text on the clipboard", -> selection.setBufferRange new Range([0,4], [0,13]) selection.copy() - expect(atom.native.readFromPasteboard()).toBe 'quicksort' + expect($native.readFromPasteboard()).toBe 'quicksort' selection.setBufferRange new Range([0,4], [3,13]) selection.copy() - expect(atom.native.readFromPasteboard()).toBe "quicksort = function () {\n var sort = function(items) {\n if (items.length <= 1) return items;\n var pivot" + expect($native.readFromPasteboard()).toBe "quicksort = function () {\n var sort = function(items) {\n if (items.length <= 1) return items;\n var pivot" it "places nothing on the clipboard when there is no selection", -> selection.setBufferRange new Range([0,4], [0,4]) selection.copy() - expect(atom.native.readFromPasteboard()).toBe 'first' + expect($native.readFromPasteboard()).toBe 'first' describe ".selectWord()", -> describe "when the cursor is inside a word", -> diff --git a/src/atom-bootstrap.coffee b/src/atom-bootstrap.coffee index 70cb10d85..1f7905381 100644 --- a/src/atom-bootstrap.coffee +++ b/src/atom-bootstrap.coffee @@ -1,2 +1,2 @@ App = require 'app' -window.atom = new App(atom.loadPath, atom.native) +window.atom = new App(atom.loadPath, $native) diff --git a/src/atom/app.coffee b/src/atom/app.coffee index 6fad8fbfd..cab01e383 100644 --- a/src/atom/app.coffee +++ b/src/atom/app.coffee @@ -1,4 +1,3 @@ -Native = require 'native' GlobalKeymap = require 'global-keymap' $ = require 'jquery' _ = require 'underscore' @@ -6,13 +5,10 @@ _ = require 'underscore' module.exports = class App keymap: null - native: null windows: null constructor: (@loadPath, nativeMethods)-> - @native = new Native(nativeMethods) @windows = [] - @setupKeymap() setupKeymap: -> @@ -21,15 +17,15 @@ class App 'meta-o': 'open' $(document).on 'open', => - url = @native.openDialog() + url = $native.openDialog() @open(url) if url $(document).on 'keydown', (e) => @keymap.handleKeyEvent(e) open: (url) -> - @native.open url + $native.open url quit: -> - @native.terminate null + $native.terminate null windowOpened: (window) -> @windows.push window diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 0687f091b..4cb52f302 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -295,7 +295,7 @@ class Editor extends View cutSelection: -> @selection.cut() copySelection: -> @selection.copy() - paste: -> @selection.insertText(atom.native.readFromPasteboard()) + paste: -> @selection.insertText($native.readFromPasteboard()) foldSelection: -> @selection.fold() diff --git a/src/atom/selection.coffee b/src/atom/selection.coffee index 5db89b167..19ff0c5e4 100644 --- a/src/atom/selection.coffee +++ b/src/atom/selection.coffee @@ -164,7 +164,7 @@ class Selection extends View copy: -> return if @isEmpty() text = @editor.buffer.getTextInRange(@getBufferRange()) - atom.native.writeToPasteboard text + $native.writeToPasteboard text fold: -> @editor.lineFolder.createFold(@getBufferRange()) diff --git a/src/atom/window.coffee b/src/atom/window.coffee index 714999453..c3bc6a688 100644 --- a/src/atom/window.coffee +++ b/src/atom/window.coffee @@ -44,7 +44,7 @@ windowAdditions = $('head').append "" showConsole: -> - atom.native.showDevTools() + $native.showDevTools() onerror: -> @showConsole() diff --git a/src/stdlib/fs.coffee b/src/stdlib/fs.coffee index 97ece8dcd..f888b0c91 100644 --- a/src/stdlib/fs.coffee +++ b/src/stdlib/fs.coffee @@ -9,7 +9,7 @@ module.exports = # Make the given path absolute by resolving it against the # current working directory. absolute: (path) -> - atom.native.absolute(path) + $native.absolute(path) # Return the basename of the given path. That is the path with # any leading directory components removed. If specified, also @@ -28,7 +28,7 @@ module.exports = # Returns true if the file specified by path exists exists: (path) -> - atom.native.exists path + $native.exists path join: (paths...) -> return paths[0] if paths.length == 1 @@ -38,44 +38,44 @@ module.exports = # Returns true if the file specified by path exists and is a # directory. isDirectory: (path) -> - atom.native.isDirectory path + $native.isDirectory path # Returns true if the file specified by path exists and is a # regular file. isFile: (path) -> - not atom.native.isDirectory path + not $native.isDirectory path # Returns an array with all the names of files contained # in the directory path. list: (path) -> - atom.native.list(path, false) + $native.list(path, false) listTree: (path) -> - atom.native.list(path, true) + $native.list(path, true) # Remove a file at the given path. Throws an error if path is not a # file or a symbolic link to a file. remove: (path) -> - atom.native.remove path + $native.remove path # Open, read, and close a file, returning the file's contents. read: (path) -> - atom.native.read(path) + $native.read(path) # Open, write, flush, and close a file, writing the given content. write: (path, content) -> - atom.native.write(path, content) + $native.write(path, content) async: list: (path) -> deferred = $.Deferred() - atom.native.asyncList path, false, (subpaths) -> + $native.asyncList path, false, (subpaths) -> deferred.resolve subpaths deferred listTree: (path) -> deferred = $.Deferred() - atom.native.asyncList path, true, (subpaths) -> + $native.asyncList path, true, (subpaths) -> deferred.resolve subpaths deferred diff --git a/src/stdlib/native.coffee b/src/stdlib/native.coffee index 0b2a031c1..332b5909a 100644 --- a/src/stdlib/native.coffee +++ b/src/stdlib/native.coffee @@ -6,7 +6,7 @@ class Native _.extend(this, nativeMethods) alert: (message, detailedMessage, buttons) -> - atom.native.alert(message, detailedMessage, buttons) + $native.alert(message, detailedMessage, buttons) # path - Optional. The String path to the file to base it on. newWindow: (path) -> @@ -16,7 +16,7 @@ class Native # Returns null or a file path. openPanel: -> - atom.native.openPanel() + $native.openPanel() # Returns null or a file path. savePanel: -> @@ -26,7 +26,7 @@ class Native panel.filenames.lastObject.valueOf() writeToPasteboard: (text) -> - atom.native.writeToPasteboard text + $native.writeToPasteboard text readFromPasteboard: -> - atom.native.readFromPasteboard() \ No newline at end of file + $native.readFromPasteboard() \ No newline at end of file diff --git a/src/stdlib/require.coffee b/src/stdlib/require.coffee index 5bb71f2c9..887f5327c 100644 --- a/src/stdlib/require.coffee +++ b/src/stdlib/require.coffee @@ -99,7 +99,7 @@ __expand = (path) -> return null __exists = (path) -> - atom.native.exists path + $native.exists path __coffeeCache = (filePath) -> {CoffeeScript} = require 'coffee-script' @@ -107,7 +107,7 @@ __coffeeCache = (filePath) -> __read = (path) -> try - atom.native.read(path) + $native.read(path) catch e throw "require: can't read #{path}"