Add Workspace::onDidDestroyPane

This helps with the background-tips conversion
This commit is contained in:
Nathan Sobo 2014-12-02 11:53:41 -07:00
parent 1eab423a1c
commit fbc9c05096
4 changed files with 32 additions and 0 deletions

View File

@ -161,6 +161,21 @@ describe "PaneContainer", ->
expect(events).toEqual [{pane: pane2}, {pane: pane3}]
describe "::onDidDestroyPane(callback)", ->
it "invokes the given callback when panes are destroyed", ->
container = new PaneContainer
events = []
container.onDidDestroyPane (event) -> events.push(event)
pane1 = container.getActivePane()
pane2 = pane1.splitRight()
pane3 = pane2.splitDown()
pane2.destroy()
pane3.destroy()
expect(events).toEqual [{pane: pane2}, {pane: pane3}]
describe "::onWillDestroyPaneItem() and ::onDidDestroyPaneItem", ->
it "invokes the given callbacks when an item will be destroyed on any pane", ->
container = new PaneContainer

View File

@ -79,6 +79,9 @@ class PaneContainer extends Model
fn(pane) for pane in @getPanes()
@onDidAddPane ({pane}) -> fn(pane)
onDidDestroyPane: (fn) ->
@emitter.on 'did-destroy-pane', fn
onDidChangeActivePane: (fn) ->
@emitter.on 'did-change-active-pane', fn
@ -193,6 +196,9 @@ class PaneContainer extends Model
didAddPane: (event) ->
@emitter.emit 'did-add-pane', event
didDestroyPane: (event) ->
@emitter.emit 'did-destroy-pane', event
# Called by Model superclass when destroyed
destroyed: ->
pane.destroy() for pane in @getPanes()

View File

@ -534,6 +534,7 @@ class Pane extends Model
@emitter.emit 'did-destroy'
@emitter.dispose()
item.destroy?() for item in @items.slice()
@container.didDestroyPane(pane: this)
###
Section: Splitting

View File

@ -233,6 +233,16 @@ class Workspace extends Model
# Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
onDidAddPane: (callback) -> @paneContainer.onDidAddPane(callback)
# Extended: Invoke the given callback when a pane is destroyed in the
# workspace.
#
# * `callback` {Function} to be called panes are destroyed.
# * `event` {Object} with the following keys:
# * `pane` The destroyed pane.
#
# Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
onDidDestroyPane: (callback) -> @paneContainer.onDidDestroyPane(callback)
# Extended: Invoke the given callback with all current and future panes in the
# workspace.
#