From 62729c42eeb81e021a4b3145754d75366477d2cc Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 18 Feb 2013 16:22:09 -0700 Subject: [PATCH] Panes destroy their items when they are removed As a consequence of these changes, editors will no longer need to listen for destruction of their edit sessions. An editor will eventually only ever be displaying a single edit session, and the editor will destroy that edit session when it is removed. Panes will be responsible for supporting multiple edit sessions, and they will automatically remove the editor when they have no more edit session items. --- spec/app/pane-spec.coffee | 10 ++++++++++ src/app/editor.coffee | 2 +- src/app/pane.coffee | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/app/pane-spec.coffee b/spec/app/pane-spec.coffee index 3921542ef..e4a551906 100644 --- a/spec/app/pane-spec.coffee +++ b/spec/app/pane-spec.coffee @@ -80,6 +80,10 @@ 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 "pane:show-next-item and pane:show-preview-item", -> it "advances forward/backward through the pane's items, looping around at either end", -> expect(pane.currentItem).toBe view1 @@ -91,3 +95,9 @@ describe "Pane", -> expect(pane.currentItem).toBe editSession2 pane.trigger 'pane:show-next-item' expect(pane.currentItem).toBe view1 + + describe ".remove()", -> + it "destroys all the pane's items", -> + pane.remove() + expect(editSession1.destroyed).toBeTruthy() + expect(editSession2.destroyed).toBeTruthy() diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 03f7766ed..dc4bddd85 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -498,7 +498,7 @@ class Editor extends View @editSessions.push(editSession) @closedEditSessions = @closedEditSessions.filter ({path})-> path isnt editSession.getPath() - editSession.on 'destroyed', => @editSessionDestroyed(editSession) +# editSession.on 'destroyed', => @editSessionDestroyed(editSession) @trigger 'editor:edit-session-added', [editSession, index] index diff --git a/src/app/pane.coffee b/src/app/pane.coffee index dd9a4ac10..774654b76 100644 --- a/src/app/pane.coffee +++ b/src/app/pane.coffee @@ -64,6 +64,7 @@ class Pane extends View removeItem: (item) -> @showNextItem() if item is @currentItem and @items.length > 1 _.remove(@items, item) + item.destroy?() @cleanupItemView(item) cleanupItemView: (item) -> @@ -135,6 +136,9 @@ class Pane extends View parentAxis.replaceWith(sibling) rootView?.adjustPaneDimensions() + afterRemove: -> + item.destroy?() for item in @getItems() + buildPaneAxis: (axis) -> switch axis when 'row' then new PaneRow