mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Add PaneContainer::onDidChangeActivePane
This commit is contained in:
@@ -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++
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user