Add subscribeToCommand to track command subscriptions on other views

This commit is contained in:
Nathan Sobo
2013-04-08 17:09:12 -06:00
parent 7c9119c793
commit 2601f266fa
2 changed files with 12 additions and 7 deletions

View File

@@ -39,13 +39,13 @@ class CommandPanelView extends View
@command 'core:move-up', => @navigateBackwardInHistory()
@command 'core:move-down', => @navigateForwardInHistory()
rootView.command 'command-panel:toggle', => @toggle()
rootView.command 'command-panel:toggle-preview', => @togglePreview()
rootView.command 'command-panel:find-in-file', => @attach('/')
rootView.command 'command-panel:find-in-project', => @attach('Xx/')
rootView.command 'command-panel:repeat-relative-address', => @repeatRelativeAddress()
rootView.command 'command-panel:repeat-relative-address-in-reverse', => @repeatRelativeAddress(reverse: true)
rootView.command 'command-panel:set-selection-as-regex-address', => @setSelectionAsLastRelativeAddress()
@subscribeToCommand rootView, 'command-panel:toggle', => @toggle()
@subscribeToCommand rootView, 'command-panel:toggle-preview', => @togglePreview()
@subscribeToCommand rootView, 'command-panel:find-in-file', => @attach('/')
@subscribeToCommand rootView, 'command-panel:find-in-project', => @attach('Xx/')
@subscribeToCommand rootView, 'command-panel:repeat-relative-address', => @repeatRelativeAddress()
@subscribeToCommand rootView, 'command-panel:repeat-relative-address-in-reverse', => @repeatRelativeAddress(reverse: true)
@subscribeToCommand rootView, 'command-panel:set-selection-as-regex-address', => @setSelectionAsLastRelativeAddress()
@on 'click', '.expand', @onExpandAll
@on 'click', '.collapse', @onCollapseAll

View File

@@ -4,5 +4,10 @@ module.exports =
@subscriptions ?= []
@subscriptions.push(cancel: -> eventEmitter.off eventName, callback)
subscribeToCommand: (view, eventName, callback) ->
view.command eventName, callback
@subscriptions ?= []
@subscriptions.push(cancel: -> view.off view, callback)
unsubscribe: ->
subscription.cancel() for subscription in @subscriptions ? []