Move PaneContainer.deserialize to an instance method

Signed-off-by: Max Brunsfeld <maxbrunsfeld@github.com>
This commit is contained in:
Nathan Sobo
2015-10-02 13:42:36 -06:00
parent 4a00d6ba35
commit fd7fbbfea5
6 changed files with 63 additions and 57 deletions

View File

@@ -7,42 +7,35 @@ ItemRegistry = require './item-registry'
module.exports =
class PaneContainer extends Model
@version: 1
serializationVersion: 1
root: null
@deserialize: (state) ->
container = Object.create(@prototype) # allows us to pass a self reference to our child before invoking constructor
state.root = atom.deserializers.deserialize(state.root, {container})
state.destroyEmptyPanes = atom.config.get('core.destroyEmptyPanes')
state.activePane = find state.root.getPanes(), (pane) -> pane.id is state.activePaneId
@call(container, state) # run constructor
container
constructor: (params) ->
super
@activePane = params?.activePane
@config = params.config
@emitter = new Emitter
@subscriptions = new CompositeDisposable
@itemRegistry = new ItemRegistry
@setRoot(params?.root ? new Pane)
@setActivePane(@getPanes()[0]) unless @getActivePane()
@destroyEmptyPanes() if params?.destroyEmptyPanes
@setRoot(new Pane(container: this))
@setActivePane(@getRoot())
@monitorActivePaneItem()
@monitorPaneItems()
serialize: (params) ->
deserializer: 'PaneContainer'
version: @constructor.version
version: @serializationVersion
root: @root?.serialize()
activePaneId: @activePane.id
deserialize: (state, deserializerManager) ->
return unless state.version is @serializationVersion
@setRoot(deserializerManager.deserialize(state.root, {container: this}))
activePane = find @getRoot().getPanes(), (pane) -> pane.id is state.activePaneId
@setActivePane(activePane ? @getPanes()[0])
@destroyEmptyPanes() if @config.get('core.destroyEmptyPanes')
onDidChangeRoot: (fn) ->
@emitter.on 'did-change-root', fn