diff --git a/spec/pane-view-spec.coffee b/spec/pane-view-spec.coffee index 63c812621..8fd9838cc 100644 --- a/spec/pane-view-spec.coffee +++ b/spec/pane-view-spec.coffee @@ -1,6 +1,7 @@ PaneContainerView = require '../src/pane-container-view' PaneView = require '../src/pane-view' fs = require 'fs-plus' +{Emitter} = require 'event-kit' {$, View} = require 'atom' path = require 'path' temp = require 'temp' @@ -162,6 +163,38 @@ describe "PaneView", -> view2.trigger 'title-changed' expect(activeItemTitleChangedHandler).toHaveBeenCalled() + describe 'when there is a onDidChangeTitle method', -> + beforeEach -> + TestView::changeTitle = -> + @emitter.emit 'did-change-title', 'title' + TestView::onDidChangeTitle = (callback) -> + @emitter.on 'did-change-title', callback + + view1.emitter = new Emitter + view2.emitter = new Emitter + + view1.id = 1 + view2.id = 2 + + pane.activateItem(view2) + pane.activateItem(view1) + + fffit "emits pane:active-item-title-changed", -> + activeItemTitleChangedHandler = jasmine.createSpy("activeItemTitleChangedHandler") + pane.on 'pane:active-item-title-changed', activeItemTitleChangedHandler + + expect(pane.getActiveItem()).toBe view1 + view2.changeTitle() + expect(activeItemTitleChangedHandler).not.toHaveBeenCalled() + + view1.changeTitle() + expect(activeItemTitleChangedHandler).toHaveBeenCalled() + activeItemTitleChangedHandler.reset() + + pane.activateItem(view2) + view2.changeTitle() + expect(activeItemTitleChangedHandler).toHaveBeenCalled() + describe "when an unmodifed buffer's path is deleted", -> it "removes the pane item", -> editor = null diff --git a/src/pane-view.coffee b/src/pane-view.coffee index 0de2ca7f1..41224e2d3 100644 --- a/src/pane-view.coffee +++ b/src/pane-view.coffee @@ -147,6 +147,9 @@ class PaneView extends View @activeItem onActiveItemChanged: (item) => + @activeItemDisposables.dispose() if @activeItemDisposables? + @activeItemDisposables = new CompositeDisposable() + if @previousActiveItem?.off? @previousActiveItem.off 'title-changed', @activeItemTitleChanged @previousActiveItem.off 'modified-status-changed', @activeItemModifiedChanged @@ -154,15 +157,29 @@ class PaneView extends View return unless item? - hasFocus = @hasFocus() - if item.on? - item.on 'title-changed', @activeItemTitleChanged - item.on 'modified-status-changed', @activeItemModifiedChanged + if item.onDidChangeTitle? + disposable = item.onDidChangeTitle(@activeItemTitleChanged) + deprecate 'Please return a Disposable object from your ::onDidChangeTitle method!' unless disposable?.dispose? + @activeItemDisposables.add(disposable) if disposable?.dispose? + else if item.on? + disposable = item.on('title-changed', @activeItemTitleChanged) + deprecate 'Please return a Disposable object from your ::on method. Your ::off method will not be called soon!' unless disposable?.dispose? + @activeItemDisposables.add(disposable) if disposable?.dispose? + + if item.onDidChangeModified? + disposable = item.onDidChangeModified(@activeItemModifiedChanged) + deprecate 'Please return a Disposable object from your ::onDidChangeModified method!' unless disposable?.dispose? + @activeItemDisposables.add(disposable) if disposable?.dispose? + else if item.on? + item.on('modified-status-changed', @activeItemModifiedChanged) + deprecate 'Please return a Disposable object from your ::on method. Your ::off method will not be called soon!' unless disposable?.dispose? + @activeItemDisposables.add(disposable) if disposable?.dispose? + view = @viewForItem(item) otherView.hide() for otherView in @itemViews.children().not(view).views() @itemViews.append(view) unless view.parent().is(@itemViews) view.show() if @attached - view.focus() if hasFocus + view.focus() if @hasFocus() @trigger 'pane:active-item-changed', [item]