Add RootView.eachPane(callback)

This commit is contained in:
Kevin Sawicki
2013-04-08 13:04:50 -07:00
parent c7175c7e5f
commit e3b381f638
3 changed files with 33 additions and 1 deletions

View File

@@ -354,3 +354,31 @@ describe "RootView", ->
rootView.open(require.resolve('fixtures/sample.txt'))
expect(count).toBe 1
expect(callbackBuffer).toBe rootView.getActiveView().getBuffer()
describe ".eachPane(callback)", ->
beforeEach ->
rootView.attachToDom()
it "invokes the callback for all existing panes", ->
count = 0
callbackPane = null
callback = (pane) ->
callbackPane = pane
count++
rootView.eachPane(callback)
expect(count).toBe 1
expect(callbackPane).toBe rootView.getActivePane()
it "invokes the callback for new panes", ->
count = 0
callbackPane = null
callback = (pane) ->
callbackPane = pane
count++
rootView.eachPane(callback)
count = 0
callbackPane = null
rootView.getActiveView().splitRight()
expect(count).toBe 1
expect(callbackPane).toBe rootView.getActivePane()

View File

@@ -58,7 +58,7 @@ class Pane extends View
return if @attached
@attached = true
@trigger 'pane:attached'
@trigger 'pane:attached', [this]
makeActive: ->
for pane in @getContainer().getPanes() when pane isnt this

View File

@@ -162,6 +162,10 @@ class RootView extends View
indexOfPane: (pane) ->
@panes.indexOfPane(pane)
eachPane: (callback) ->
callback(pane) for pane in @getPanes()
@on 'pane:attached', (e, pane) -> callback(pane)
eachEditor: (callback) ->
callback(editor) for editor in @getEditors()
@on 'editor:attached', (e, editor) -> callback(editor)