Files
atom/src/pane-axis-view.coffee
2014-01-13 13:46:27 -07:00

35 lines
1.0 KiB
CoffeeScript

{View} = require './space-pen-extensions'
PaneView = null
### Internal ###
module.exports =
class PaneAxisView extends View
initialize: (@model) ->
@onChildAdded(child) for child in @model.children
@subscribe @model.children, 'changed', @onChildrenChanged
viewForModel: (model) ->
viewClass = model.getViewClass()
model._view ?= new viewClass(model)
onChildrenChanged: ({index, removedValues, insertedValues}) =>
focusedElement = document.activeElement if @hasFocus()
@onChildRemoved(child, index) for child in removedValues
@onChildAdded(child, index + i) for child, i in insertedValues
focusedElement?.focus() if document.activeElement is document.body
onChildAdded: (child, index) =>
view = @viewForModel(child)
@insertAt(index, view)
onChildRemoved: (child) =>
view = @viewForModel(child)
view.detach()
PaneView ?= require './pane-view'
if view instanceof PaneView and view.model.isDestroyed()
@getContainer()?.trigger 'pane:removed', [view]
getContainer: ->
@closest('.panes').view()