From 2e2ff3a1d094f96a2f243e37ac7f396cecbd157b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 26 Feb 2013 14:19:33 -0700 Subject: [PATCH] Add Pane.destroyItem and rename removeActiveItem -> destroyActiveItem Pane.removeItem removes an item, but no longer tries to call destroy on it. This will facilitate moving items between panes. --- spec/app/pane-spec.coffee | 14 +++++++++----- src/app/pane.coffee | 12 ++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/spec/app/pane-spec.coffee b/spec/app/pane-spec.coffee index 884399bf8..bf2420eaa 100644 --- a/spec/app/pane-spec.coffee +++ b/spec/app/pane-spec.coffee @@ -88,6 +88,12 @@ describe "Pane", -> expect(pane.itemViews.find('#view-2')).toExist() expect(pane.activeView).toBe view2 + describe ".destroyItem(item)", -> + it "removes the item and destroys it if it's a model", -> + pane.destroyItem(editSession2) + expect(pane.getItems().indexOf(editSession2)).toBe -1 + expect(editSession2.destroyed).toBeTruthy() + describe ".removeItem(item)", -> it "removes the item from the items list and shows the next item if it was showing", -> pane.removeItem(view1) @@ -124,10 +130,6 @@ describe "Pane", -> pane.removeItem(editSession1) expect(pane.itemViews.find('.editor')).not.toExist() - it "calls destroy on the model", -> - pane.removeItem(editSession2) - expect(editSession2.destroyed).toBeTruthy() - describe ".moveItem(item, index)", -> it "moves the item to the given index and emits a 'pane:item-moved' event with the item and the new index", -> itemMovedHandler = jasmine.createSpy("itemMovedHandler") @@ -152,13 +154,15 @@ describe "Pane", -> itemMovedHandler.reset() describe "core:close", -> - it "removes the active item and does not bubble the event", -> + it "destroys the active item and does not bubble the event", -> containerCloseHandler = jasmine.createSpy("containerCloseHandler") container.on 'core:close', containerCloseHandler + pane.showItem(editSession1) initialItemCount = pane.getItems().length pane.trigger 'core:close' expect(pane.getItems().length).toBe initialItemCount - 1 + expect(editSession1.destroyed).toBeTruthy() expect(containerCloseHandler).not.toHaveBeenCalled() diff --git a/src/app/pane.coffee b/src/app/pane.coffee index fecf57fc5..83a970949 100644 --- a/src/app/pane.coffee +++ b/src/app/pane.coffee @@ -20,7 +20,7 @@ class Pane extends View @viewsByClassName = {} @showItem(@items[0]) - @command 'core:close', @removeActiveItem + @command 'core:close', @destroyActiveItem @command 'pane:show-next-item', @showNextItem @command 'pane:show-previous-item', @showPreviousItem @command 'pane:split-left', => @splitLeft() @@ -89,17 +89,21 @@ class Pane extends View @trigger 'pane:item-added', [item, index] item - removeActiveItem: => - @removeItem(@activeItem) + destroyActiveItem: => + @destroyItem(@activeItem) false + destroyItem: (item) -> + @removeItem(item) + item.destroy?() + removeItem: (item) -> index = @items.indexOf(item) return if index == -1 @showNextItem() if item is @activeItem and @items.length > 1 _.remove(@items, item) - item.destroy?() + @cleanupItemView(item) @trigger 'pane:item-removed', [item, index] @remove() unless @items.length