atom variable holds all global state and is shared across contexts.

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-02-28 13:14:35 -08:00
parent 5ac7088423
commit b37b45b4b1
13 changed files with 69 additions and 54 deletions

View File

@@ -0,0 +1,2 @@
App = require 'app'
window.atom = new App(atom.loadPath, atom.native)

View File

@@ -1,14 +1,15 @@
Native = require 'native'
GlobalKeymap = require 'global-keymap'
$ = require 'jquery'
_ = require 'underscore'
module.exports =
class App
globalKeymap: null
native: null
constructor: ->
@native = new Native
constructor: (@loadPath, nativeMethods)->
@native = new Native(nativeMethods)
@globalKeymap = new GlobalKeymap
$(document).on 'keydown', (e) => @globalKeymap.handleKeyEvent(e)
@@ -19,11 +20,11 @@ class App
@globalKeymap.bindKey(selector, pattern, eventName)
open: (url) ->
$native.open url
@native.open url
quit: ->
$native.terminate null
@native.terminate null
windows: ->
# controller.jsWindow for controller in OSX.NSApp.controllers
[]
# controller.jsWindow for controller in OSX.NSApp.controllers
[]

View File

@@ -1,7 +1,4 @@
# Like sands through the hourglass, so are the days of our lives.
App = require 'app'
window.atom = new App
require 'window'
window.startup $pathToOpen

View File

@@ -9,7 +9,7 @@ module.exports =
# Make the given path absolute by resolving it against the
# current working directory.
absolute: (path) ->
$native.absolute(path)
atom.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) ->
$native.exists path
atom.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) ->
$native.isDirectory path
atom.native.isDirectory path
# Returns true if the file specified by path exists and is a
# regular file.
isFile: (path) ->
not $native.isDirectory path
not atom.native.isDirectory path
# Returns an array with all the names of files contained
# in the directory path.
list: (path) ->
$native.list(path, false)
atom.native.list(path, false)
listTree: (path) ->
$native.list(path, true)
atom.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) ->
$native.remove path
atom.native.remove path
# Open, read, and close a file, returning the file's contents.
read: (path) ->
$native.read(path)
atom.native.read(path)
# Open, write, flush, and close a file, writing the given content.
write: (path, content) ->
$native.write(path, content)
atom.native.write(path, content)
async:
list: (path) ->
deferred = $.Deferred()
$native.asyncList path, false, (subpaths) ->
atom.native.asyncList path, false, (subpaths) ->
deferred.resolve subpaths
deferred
listTree: (path) ->
deferred = $.Deferred()
$native.asyncList path, true, (subpaths) ->
atom.native.asyncList path, true, (subpaths) ->
deferred.resolve subpaths
deferred

View File

@@ -2,8 +2,11 @@ _ = require 'underscore'
module.exports =
class Native
constructor: (nativeMethods)->
_.extend(this, nativeMethods)
alert: (message, detailedMessage, buttons) ->
$native.alert(message, detailedMessage, buttons)
atom.native.alert(message, detailedMessage, buttons)
# path - Optional. The String path to the file to base it on.
newWindow: (path) ->
@@ -29,10 +32,10 @@ class Native
panel.filenames.lastObject.valueOf()
writeToPasteboard: (text) ->
$native.writeToPasteboard text
atom.native.writeToPasteboard text
readFromPasteboard: ->
$native.readFromPasteboard()
atom.native.readFromPasteboard()
resetMainMenu: (menu) ->
# OSX.NSApp.resetMainMenu

View File

@@ -1,11 +1,11 @@
paths = [
"#{$atom.loadPath}/spec"
"#{$atom.loadPath}/src/stdlib"
"#{$atom.loadPath}/src/atom"
"#{$atom.loadPath}/src"
"#{$atom.loadPath}/extensions"
"#{$atom.loadPath}/vendor"
"#{$atom.loadPath}/static"
"#{atom.loadPath}/spec"
"#{atom.loadPath}/src/stdlib"
"#{atom.loadPath}/src/atom"
"#{atom.loadPath}/src"
"#{atom.loadPath}/extensions"
"#{atom.loadPath}/vendor"
"#{atom.loadPath}/static"
]
window.__filename = null
@@ -100,7 +100,7 @@ __expand = (path) ->
return null
__exists = (path) ->
$native.exists path
atom.native.exists path
__coffeeCache = (filePath) ->
{CoffeeScript} = require 'coffee-script'
@@ -108,7 +108,7 @@ __coffeeCache = (filePath) ->
__read = (path) ->
try
$native.read(path)
atom.native.read(path)
catch e
throw "require: can't read #{path}"