mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Never allow PaneContainer::root to be null
This commit is contained in:
@@ -8,6 +8,9 @@ class PaneAxisView extends View
|
||||
@onChildAdded(child) for child in @model.children
|
||||
@subscribe @model.children, 'changed', @onChildrenChanged
|
||||
|
||||
afterAttach: ->
|
||||
@container = @closest('.panes').view()
|
||||
|
||||
viewForModel: (model) ->
|
||||
viewClass = model.getViewClass()
|
||||
model._view ?= new viewClass(model)
|
||||
@@ -26,9 +29,5 @@ class PaneAxisView extends View
|
||||
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()
|
||||
@container?.trigger 'pane:removed', [view]
|
||||
|
||||
@@ -32,9 +32,6 @@ class PaneContainerView extends View
|
||||
getRoot: ->
|
||||
@children().first().view()
|
||||
|
||||
setRoot: (root) ->
|
||||
@model.root = root?.model
|
||||
|
||||
onRootChanged: (root) =>
|
||||
focusedElement = document.activeElement if @hasFocus()
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class PaneContainer extends Model
|
||||
Serializable.includeInto(this)
|
||||
|
||||
@properties
|
||||
root: null
|
||||
root: -> new Pane
|
||||
activePane: null
|
||||
|
||||
previousRoot: null
|
||||
@@ -75,11 +75,8 @@ class PaneContainer extends Model
|
||||
root.parent = this
|
||||
root.container = this
|
||||
|
||||
if root instanceof Pane
|
||||
@activePane ?= root
|
||||
@subscribe root, 'destroyed', =>
|
||||
@activePane = null
|
||||
@root = null
|
||||
|
||||
@activePane ?= root if root instanceof Pane
|
||||
|
||||
destroyEmptyPanes: ->
|
||||
pane.destroy() for pane in @getPanes() when pane.items.length is 0
|
||||
|
||||
@@ -102,6 +102,7 @@ class PaneView extends View
|
||||
@focus() if @model.focused and onDom
|
||||
|
||||
return if @attached
|
||||
@container = @closest('.panes').view()
|
||||
@attached = true
|
||||
@trigger 'pane:attached', [this]
|
||||
|
||||
@@ -118,7 +119,7 @@ class PaneView extends View
|
||||
|
||||
# Public: Returns the next pane, ordered by creation.
|
||||
getNextPane: ->
|
||||
panes = @getContainer()?.getPanes()
|
||||
panes = @container?.getPanes()
|
||||
return unless panes.length > 1
|
||||
nextIndex = (panes.indexOf(this) + 1) % panes.length
|
||||
panes[nextIndex]
|
||||
@@ -194,10 +195,6 @@ class PaneView extends View
|
||||
|
||||
splitDown: (items...) -> @model.splitDown({items})._view
|
||||
|
||||
# Private:
|
||||
getContainer: ->
|
||||
@closest('.panes').view()
|
||||
|
||||
beforeRemove: ->
|
||||
@model.destroy() unless @model.isDestroyed()
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ class Pane extends Model
|
||||
# The item to add. It can be a model with an associated view or a view.
|
||||
# * index:
|
||||
# An optional index at which to add the item. If omitted, the item is
|
||||
# added to the end.
|
||||
# added after the current active item.
|
||||
#
|
||||
# Returns the added item
|
||||
addItem: (item, index=@getActiveItemIndex() + 1) ->
|
||||
@@ -136,6 +136,21 @@ class Pane extends Model
|
||||
@emit 'item-added', item, index
|
||||
item
|
||||
|
||||
# Public: Adds the given items to the pane.
|
||||
#
|
||||
# * items:
|
||||
# An {Array} of items to add. Items can be models with associated views
|
||||
# or views. Any items that are already present in items will not be added.
|
||||
# * index:
|
||||
# An optional index at which to add the item. If omitted, the item is
|
||||
# added after the current active item.
|
||||
#
|
||||
# Returns an {Array} of the added items
|
||||
addItems: (items, index=@getActiveItemIndex() + 1) ->
|
||||
items = items.filter (item) => not (item in @items)
|
||||
@addItem(item, index + i) for item, i in items
|
||||
items
|
||||
|
||||
# Private:
|
||||
removeItem: (item, destroying) ->
|
||||
index = @items.indexOf(item)
|
||||
@@ -187,6 +202,9 @@ class Pane extends Model
|
||||
destroyInactiveItems: ->
|
||||
@destroyItem(item) for item in @getItems() when item isnt @activeItem
|
||||
|
||||
destroy: ->
|
||||
super unless @container?.getPanes().length is 1
|
||||
|
||||
# Private: Called by model superclass.
|
||||
destroyed: ->
|
||||
@container.activateNextPane() if @isActive()
|
||||
|
||||
Reference in New Issue
Block a user