atom.on, atom.off, atom.trigger

This commit is contained in:
Chris Wanstrath
2011-11-09 12:32:54 -08:00
parent 51f8497229
commit 9db7eb1c0d
7 changed files with 24 additions and 20 deletions

View File

@@ -14,7 +14,7 @@ class Browser extends Pane
/^https?:\/\//.test path
constructor: ->
atom.event.on "window:open", (e) =>
atom.on "window:open", (e) =>
path = e.details
return unless @constructor.isPathUrl path
@@ -24,4 +24,4 @@ class Browser extends Pane
@show()
atom.event.trigger "browser:focus", path
atom.trigger "browser:focus", path

View File

@@ -36,12 +36,12 @@ class Editor extends Pane
@ace.setShowInvisibles(true)
@ace.setPrintMarginColumn 78
atom.event.on 'window:open', (e) =>
atom.on 'window:open', (e) =>
path = e.details
@addBuffer e.details if fs.isFile path
atom.event.on 'window:close', (e) => @removeBuffer e.details
atom.event.on 'editor:bufferFocus', (e) => @resize()
atom.on 'window:close', (e) => @removeBuffer e.details
atom.on 'editor:bufferFocus', (e) => @resize()
# Resize editor when panes are added/removed
el = document.body
@@ -109,7 +109,7 @@ class Editor extends Pane
atom.storage.set @openPathsKey, openPaths
buffer.on 'change', -> buffer.$atom_dirty = true
atom.event.trigger "editor:bufferAdd", path
atom.trigger "editor:bufferAdd", path
@focusBuffer path
@@ -142,7 +142,7 @@ class Editor extends Pane
openPaths = atom.storage.get @openPathsKey, []
atom.storage.set @openPathsKey, _.without openPaths, path
atom.event.trigger "editor:bufferRemove", path
atom.trigger "editor:bufferRemove", path
if path is @activePath
newActivePath = Object.keys(@buffers)[0]
@@ -161,7 +161,7 @@ class Editor extends Pane
@ace.setSession buffer
atom.storage.set @focusedPathKey, path
atom.event.trigger "editor:bufferFocus", path
atom.trigger "editor:bufferFocus", path
save: (path) ->
path ?= @activePath

View File

@@ -35,7 +35,7 @@ class Modal
$('#modal input').focus()
@resize()
atom.event.trigger 'modal:show', @
atom.trigger 'modal:show', @
resize: ->
$('#modal').css
@@ -48,7 +48,7 @@ class Modal
$('#modal-overlay').fadeOut 200, -> $(this).remove()
$(document).unbind '.modal'
$(window).unbind '.modal'
atom.event.trigger 'modal:hide', @
atom.trigger 'modal:hide', @
toggle: ->
if @showing then @hide() else @show()

View File

@@ -8,8 +8,12 @@ Storage = require 'storage'
window.atom = {}
window.atom.native = new Native
window.atom.event = new Event
window.atom.keybinder = new KeyBinder
window.atom.storage = new Storage
window.atom.event = new Event
# atom.on, atom.off, etc.
for name, method of window.atom.event
window.atom[name] = window.atom.event[name]
window.atom.app = new App

View File

@@ -72,7 +72,7 @@ windowAdditions =
console.warn "window: Extension #{extension.constructor.name} failed to startup."
console.warn error
atom.event.trigger 'extensions:loaded'
atom.trigger 'extensions:loaded'
loadKeyBindings: ->
atom.keybinder.load "#{@appRoot}/static/key-bindings.coffee"
@@ -96,18 +96,18 @@ windowAdditions =
open: (path) ->
$atomController.window.makeKeyAndOrderFront $atomController
atom.event.trigger 'window:open', path
atom.trigger 'window:open', path
close: (path) ->
@shutdown()
$atomController.close
atom.event.trigger 'window:close', path
atom.trigger 'window:close', path
handleKeyEvent: ->
atom.keybinder.handleEvent.apply atom.keybinder, arguments
triggerEvent: ->
atom.event.trigger arguments...
atom.trigger arguments...
canOpen: (path) ->
parent = @path.replace(/([^\/])$/, "$1/")