From 2601f266fa3fe01f9792fbeede4437e28661f936 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 8 Apr 2013 17:09:12 -0600 Subject: [PATCH] Add subscribeToCommand to track command subscriptions on other views --- .../command-panel/lib/command-panel-view.coffee | 14 +++++++------- src/stdlib/subscriber.coffee | 5 +++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/packages/command-panel/lib/command-panel-view.coffee b/src/packages/command-panel/lib/command-panel-view.coffee index 13d773e41..bafdb62c2 100644 --- a/src/packages/command-panel/lib/command-panel-view.coffee +++ b/src/packages/command-panel/lib/command-panel-view.coffee @@ -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 diff --git a/src/stdlib/subscriber.coffee b/src/stdlib/subscriber.coffee index b843b2c49..ede4f8f67 100644 --- a/src/stdlib/subscriber.coffee +++ b/src/stdlib/subscriber.coffee @@ -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 ? []