mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Add PaneContainer.eachPane
It calls the given callback with all current and future panes
This commit is contained in:
committed by
probablycorey
parent
3382a542b3
commit
892ff0c51f
@@ -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())
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user