Add PaneContainer.eachPane

It calls the given callback with all current and future panes
This commit is contained in:
Nathan Sobo
2013-02-25 15:27:09 -07:00
committed by probablycorey
parent 3382a542b3
commit 892ff0c51f
4 changed files with 29 additions and 0 deletions

View File

@@ -57,6 +57,21 @@ describe "PaneContainer", ->
container.find('.pane.active').removeClass('active')
expect(container.getActivePane()).toBe pane1
describe ".eachPane(callback)", ->
it "runs the callback with all current and future panes until the subscription is cancelled", ->
panes = []
subscription = container.eachPane (pane) -> panes.push(pane)
expect(panes).toEqual [pane1, pane2, pane3]
panes = []
pane4 = pane3.splitRight()
expect(panes).toEqual [pane4]
panes = []
subscription.cancel()
pane4.splitDown()
expect(panes).toEqual []
describe "serialization", ->
it "can be serialized and deserialized, and correctly adjusts dimensions of deserialized panes after attach", ->
newContainer = deserialize(container.serialize())

View File

@@ -39,6 +39,12 @@ class PaneContainer extends View
getPanes: ->
@find('.pane').toArray().map (node)-> $(node).view()
eachPane: (callback) ->
callback(pane) for pane in @getPanes()
paneAttached = (e) -> callback($(e.target).view())
@on 'pane:attached', paneAttached
cancel: => @off 'pane:attached', paneAttached
getFocusedPane: ->
@find('.pane:has(:focus)').view()

View File

@@ -30,6 +30,11 @@ class Pane extends View
@on 'focus', => @currentView.focus(); false
@on 'focusin', => @makeActive()
afterAttach: ->
return if @attached
@attached = true
@trigger 'pane:attached'
makeActive: ->
for pane in @getContainer().getPanes() when pane isnt this
pane.makeInactive()

View File

@@ -166,6 +166,9 @@ class RootView extends View
saveAll: ->
editor.save() for editor in @getEditors()
eachPane: (callback) ->
@panes.eachPane(callback)
eachEditor: (callback) ->
callback(editor) for editor in @getEditors()
@on 'editor:attached', (e, editor) -> callback(editor)