mirror of
https://github.com/atom/atom.git
synced 2026-01-15 01:48:15 -05:00
Add PaneContainer::onDidAddPaneItem and ::observePaneItems
This commit is contained in:
@@ -102,3 +102,16 @@ describe "PaneContainer", ->
|
||||
pane4 = pane2.splitRight()
|
||||
|
||||
expect(observed).toEqual [pane1, pane2, pane3, pane4]
|
||||
|
||||
describe "::observePaneItems()", ->
|
||||
it "invokes observers with all current and future pane items", ->
|
||||
container = new PaneContainer(root: new Pane(items: [new Object, new Object]))
|
||||
container.getRoot().splitRight(items: [new Object])
|
||||
[pane1, pane2] = container.getPanes()
|
||||
observed = []
|
||||
container.observePaneItems (pane) -> observed.push(pane)
|
||||
|
||||
pane3 = pane2.splitDown(items: [new Object])
|
||||
pane3.addItems([new Object, new Object])
|
||||
|
||||
expect(observed).toEqual container.getPaneItems()
|
||||
|
||||
@@ -51,6 +51,9 @@ class PaneAxis extends Model
|
||||
getPanes: ->
|
||||
flatten(@children.map (child) -> child.getPanes())
|
||||
|
||||
getItems: ->
|
||||
flatten(@children.map (child) -> child.getItems())
|
||||
|
||||
onDidAddChild: (fn) ->
|
||||
@emitter.on 'did-add-child', fn
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{find} = require 'underscore-plus'
|
||||
{find, flatten} = require 'underscore-plus'
|
||||
{Model} = require 'theorist'
|
||||
{Emitter, CompositeDisposable} = require 'event-kit'
|
||||
Serializable = require 'serializable'
|
||||
@@ -31,6 +31,7 @@ class PaneContainer extends Model
|
||||
@destroyEmptyPanes() if params?.destroyEmptyPanes
|
||||
|
||||
@monitorActivePaneItem()
|
||||
@monitorPaneItems()
|
||||
|
||||
deserializeParams: (params) ->
|
||||
params.root = atom.deserializers.deserialize(params.root, container: this)
|
||||
@@ -63,6 +64,13 @@ class PaneContainer extends Model
|
||||
fn(@getActivePane())
|
||||
@onDidChangeActivePane(fn)
|
||||
|
||||
onDidAddPaneItem: (fn) ->
|
||||
@emitter.on 'did-add-pane-item', fn
|
||||
|
||||
observePaneItems: (fn) ->
|
||||
fn(item) for item in @getPaneItems()
|
||||
@onDidAddPaneItem ({item}) -> fn(item)
|
||||
|
||||
onDidChangeActivePaneItem: (fn) ->
|
||||
@emitter.on 'did-change-active-pane-item', fn
|
||||
|
||||
@@ -89,6 +97,9 @@ class PaneContainer extends Model
|
||||
getPanes: ->
|
||||
@getRoot().getPanes()
|
||||
|
||||
getPaneItems: ->
|
||||
@getRoot().getItems()
|
||||
|
||||
getActivePane: ->
|
||||
@activePane
|
||||
|
||||
@@ -154,3 +165,11 @@ class PaneContainer extends Model
|
||||
@emitter.emit 'did-change-active-pane-item', activeItem
|
||||
|
||||
@subscriptions.add(childSubscription)
|
||||
|
||||
monitorPaneItems: ->
|
||||
@subscriptions.add @observePanes (pane) =>
|
||||
for item, index in pane.getItems()
|
||||
@emitter.emit 'did-add-pane-item', {item, pane, index}
|
||||
|
||||
pane.onDidAddItem ({item, index}) =>
|
||||
@emitter.emit 'did-add-pane-item', {item, pane, index}
|
||||
|
||||
Reference in New Issue
Block a user