From 5240d9989fd0b87e0eb73833e9d4805c10e2e350 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 25 Feb 2013 17:15:00 -0700 Subject: [PATCH] Pane emits 'pane:item-removed' events --- spec/app/pane-spec.coffee | 7 +++++++ src/app/pane.coffee | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/spec/app/pane-spec.coffee b/spec/app/pane-spec.coffee index 963ce359f..d263cff4b 100644 --- a/spec/app/pane-spec.coffee +++ b/spec/app/pane-spec.coffee @@ -99,6 +99,13 @@ describe "Pane", -> expect(pane.getItems()).toEqual [editSession1, view2] expect(pane.activeItem).toBe editSession1 + it "triggers 'pane:item-removed' with the item and its former index", -> + itemRemovedHandler = jasmine.createSpy("itemRemovedHandler") + pane.on 'pane:item-removed', itemRemovedHandler + pane.removeItem(editSession1) + expect(itemRemovedHandler).toHaveBeenCalled() + expect(itemRemovedHandler.argsForCall[0][1..2]).toEqual [editSession1, 1] + it "removes the pane when its last item is removed", -> pane.removeItem(item) for item in pane.getItems() expect(pane.hasParent()).toBeFalsy() diff --git a/src/app/pane.coffee b/src/app/pane.coffee index 547160157..eadccaa50 100644 --- a/src/app/pane.coffee +++ b/src/app/pane.coffee @@ -94,10 +94,14 @@ class Pane extends View false 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 itemForPath: (path) ->