Add Pane::onDidActivate

This commit is contained in:
Nathan Sobo
2014-08-27 10:22:14 -06:00
parent 548018e9b2
commit 2d58d9c8b5
3 changed files with 29 additions and 0 deletions

View File

@@ -28,6 +28,29 @@ describe "Pane", ->
expect(pane.getItems().length).toBe 2
expect(pane.getActiveItem()).toBe pane.itemAtIndex(0)
describe "::activate()", ->
[container, pane1, pane2] = []
beforeEach ->
container = new PaneContainer(root: new Pane)
container.getRoot().splitRight()
[pane1, pane2] = container.getPanes()
it "changes the active pane on the container", ->
expect(container.getActivePane()).toBe pane2
pane1.activate()
expect(container.getActivePane()).toBe pane1
pane2.activate()
expect(container.getActivePane()).toBe pane2
it "invokes ::onDidActivate() observers", ->
eventCount = 0
pane1.onDidActivate -> eventCount++
pane1.activate()
pane1.activate()
pane2.activate()
expect(eventCount).toBe 2
describe "::addItem(item, index)", ->
it "adds the item at the given index", ->
pane = new Pane(items: [new Item("A"), new Item("B")])

View File

@@ -36,6 +36,8 @@ class PaneContainer extends Model
root: @root?.serialize()
activePaneId: @activePane.id
getRoot: -> @root
replaceChild: (oldChild, newChild) ->
throw new Error("Replacing non-existent child") if oldChild isnt @root
@root = newChild

View File

@@ -94,6 +94,9 @@ class Pane extends Model
# Called by the view layer to construct a view for this model.
getViewClass: -> PaneView ?= require './pane-view'
onDidActivate: (fn) ->
@emitter.on 'did-activate', fn
onDidAddItem: (fn) ->
@emitter.on 'did-add-item', fn
@@ -123,6 +126,7 @@ class Pane extends Model
activate: ->
@container?.activePane = this
@emit 'activated'
@emitter.emit 'did-activate'
getPanes: -> [this]