atom.event

This commit is contained in:
Chris Wanstrath
2011-11-09 12:19:33 -08:00
parent 7425aec186
commit 73fd8562ab
8 changed files with 26 additions and 31 deletions

View File

@@ -1,6 +1,5 @@
$ = require 'jquery'
Event = require 'event'
Pane = require 'pane'
module.exports =
@@ -15,7 +14,7 @@ class Browser extends Pane
/^https?:\/\//.test path
constructor: ->
Event.on "window:open", (e) =>
atom.event.on "window:open", (e) =>
path = e.details
return unless @constructor.isPathUrl path
@@ -25,4 +24,4 @@ class Browser extends Pane
@show()
Event.trigger "browser:focus", path
atom.event.trigger "browser:focus", path

View File

@@ -3,7 +3,6 @@ _ = require 'underscore'
fs = require 'fs'
ace = require 'ace/ace'
Event = require 'event'
KeyBinder = require 'key-binder'
Storage = require 'storage'
Pane = require 'pane'
@@ -39,12 +38,12 @@ class Editor extends Pane
@ace.setShowInvisibles(true)
@ace.setPrintMarginColumn 78
Event.on 'window:open', (e) =>
atom.event.on 'window:open', (e) =>
path = e.details
@addBuffer e.details if fs.isFile path
Event.on 'window:close', (e) => @removeBuffer e.details
Event.on 'editor:bufferFocus', (e) => @resize()
atom.event.on 'window:close', (e) => @removeBuffer e.details
atom.event.on 'editor:bufferFocus', (e) => @resize()
# Resize editor when panes are added/removed
el = document.body
@@ -112,7 +111,7 @@ class Editor extends Pane
Storage.set @openPathsKey, openPaths
buffer.on 'change', -> buffer.$atom_dirty = true
Event.trigger "editor:bufferAdd", path
atom.event.trigger "editor:bufferAdd", path
@focusBuffer path
@@ -145,7 +144,7 @@ class Editor extends Pane
openPaths = Storage.get @openPathsKey, []
Storage.set @openPathsKey, _.without openPaths, path
Event.trigger "editor:bufferRemove", path
atom.event.trigger "editor:bufferRemove", path
if path is @activePath
newActivePath = Object.keys(@buffers)[0]
@@ -164,7 +163,7 @@ class Editor extends Pane
@ace.setSession buffer
Storage.set @focusedPathKey, path
Event.trigger "editor:bufferFocus", path
atom.event.trigger "editor:bufferFocus", path
save: (path) ->
path ?= @activePath

View File

@@ -3,16 +3,16 @@
module.exports =
class Event
@events: {}
events: {}
@on: (name, callback) ->
on: (name, callback) ->
window.document.addEventListener name, callback
callback
@off: (name, callback) ->
off: (name, callback) ->
window.document.removeEventListener name, callback
@trigger: (name, data, bubbleToApp=true) ->
trigger: (name, data, bubbleToApp=true) ->
if bubbleToApp and name.match /^app:/
OSX.NSApp.triggerGlobalEvent_data name, data
return

View File

@@ -1,7 +1,5 @@
$ = require 'jquery'
Event = require 'event'
module.exports =
class Modal
template: '<div id="modal"><div class="popup"><div class="content"></div><a href="#" class="close inline">&nbsp;</a></div></div>'
@@ -37,7 +35,7 @@ class Modal
$('#modal input').focus()
@resize()
Event.trigger 'modal:show', @
atom.event.trigger 'modal:show', @
resize: ->
$('#modal').css
@@ -50,7 +48,7 @@ class Modal
$('#modal-overlay').fadeOut 200, -> $(this).remove()
$(document).unbind '.modal'
$(window).unbind '.modal'
Event.trigger 'modal:hide', @
atom.event.trigger 'modal:hide', @
toggle: ->
if @showing then @hide() else @show()

View File

@@ -1,8 +1,10 @@
# Like sands through the hourglass, so are the days of our lives.
App = require 'app'
Event = require 'event'
Native = require 'native'
window.atom = {}
window.atom.app = new App
window.atom.native = new Native
window.atom.native = new Native
window.atom.event = new Event

View File

@@ -1,7 +1,6 @@
Browser = require 'browser'
Editor = require 'editor'
Extension = require 'extension'
Event = require 'event'
KeyBinder = require 'key-binder'
Native = require 'native'
Storage = require 'storage'
@@ -77,7 +76,7 @@ windowAdditions =
console.warn "window: Extension #{extension.constructor.name} failed to startup."
console.warn error
Event.trigger 'extensions:loaded'
atom.event.trigger 'extensions:loaded'
loadKeyBindings: ->
KeyBinder.load "#{@appRoot}/static/key-bindings.coffee"
@@ -101,18 +100,18 @@ windowAdditions =
open: (path) ->
$atomController.window.makeKeyAndOrderFront $atomController
Event.trigger 'window:open', path
atom.event.trigger 'window:open', path
close: (path) ->
@shutdown()
$atomController.close
Event.trigger 'window:close', path
atom.event.trigger 'window:close', path
handleKeyEvent: ->
KeyBinder.handleEvent.apply KeyBinder, arguments
triggerEvent: ->
Event.trigger arguments...
atom.event.trigger arguments...
canOpen: (path) ->
parent = @path.replace(/([^\/])$/, "$1/")