Add PaneContainer::onDidChangeActivePane

This commit is contained in:
Nathan Sobo
2014-08-27 10:56:56 -06:00
parent 8225f759bf
commit 2b63f8a4ee
3 changed files with 25 additions and 2 deletions

View File

@@ -43,6 +43,16 @@ describe "Pane", ->
pane2.activate()
expect(container.getActivePane()).toBe pane2
it "invokes ::onDidChangeActivePane observers on the container", ->
observed = []
container.onDidChangeActivePane (activePane) -> observed.push(activePane)
pane1.activate()
pane1.activate()
pane2.activate()
pane1.activate()
expect(observed).toEqual [pane1, pane2, pane1]
it "invokes ::onDidActivate() observers", ->
eventCount = 0
pane1.onDidActivate -> eventCount++

View File

@@ -1,5 +1,6 @@
{find} = require 'underscore-plus'
{Model} = require 'theorist'
{Emitter} = require 'event-kit'
Serializable = require 'serializable'
Pane = require './pane'
@@ -23,6 +24,9 @@ class PaneContainer extends Model
constructor: (params) ->
super
@emitter = new Emitter
@subscribe @$root, @onRootChanged
@destroyEmptyPanes() if params?.destroyEmptyPanes
@@ -36,6 +40,9 @@ class PaneContainer extends Model
root: @root?.serialize()
activePaneId: @activePane.id
onDidChangeActivePane: (fn) ->
@emitter.on 'did-change-active-pane', fn
getRoot: -> @root
replaceChild: (oldChild, newChild) ->
@@ -48,6 +55,12 @@ class PaneContainer extends Model
getActivePane: ->
@activePane
setActivePane: (pane) ->
if pane isnt @activePane
@activePane = pane
@emitter.emit 'did-change-active-pane', @activePane
@activePane
paneForUri: (uri) ->
find @getPanes(), (pane) -> pane.itemForUri(uri)?
@@ -80,7 +93,7 @@ class PaneContainer extends Model
@previousRoot = root
unless root?
@activePane = null
@setActivePane(null)
return
root.parent = this

View File

@@ -127,7 +127,7 @@ class Pane extends Model
# Public: Makes this pane the *active* pane, causing it to gain focus
# immediately.
activate: ->
@container?.activePane = this
@container?.setActivePane(this)
@emit 'activated'
@emitter.emit 'did-activate'