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.
This commit is contained in:
Nathan Sobo
2013-02-18 16:22:09 -07:00
committed by probablycorey
parent 77bf3e4d74
commit 62729c42ee
3 changed files with 15 additions and 1 deletions

View File

@@ -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()

View File

@@ -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

View File

@@ -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