Add PaneAxis.getElement, remove PaneAxis view provider

This commit is contained in:
Max Brunsfeld
2017-04-05 16:25:53 -07:00
parent d0421a75c8
commit 6344f9884d
6 changed files with 19 additions and 18 deletions

View File

@@ -47,7 +47,6 @@ Gutter = require './gutter'
TextEditorRegistry = require './text-editor-registry'
AutoUpdateManager = require './auto-update-manager'
PaneAxisElement = require './pane-axis-element'
{createGutterView} = require './gutter-component-helpers'
# Essential: Atom global for dealing with packages, themes, menus, and the window.
@@ -282,8 +281,6 @@ class AtomEnvironment extends Model
registerDefaultCommands({commandRegistry: @commands, @config, @commandInstaller, notificationManager: @notifications, @project, @clipboard})
registerDefaultViewProviders: ->
@views.addViewProvider PaneAxis, (model, env) ->
new PaneAxisElement().initialize(model, env)
@views.addViewProvider(Gutter, createGutterView)
registerDefaultOpeners: ->

View File

@@ -11,8 +11,8 @@ class PaneAxisElement extends HTMLElement
@subscriptions = null
@childRemoved({child}) for child in @model.getChildren()
initialize: (@model, {@views}) ->
throw new Error("Must pass a views parameter when initializing TextEditorElements") unless @views?
initialize: (@model, @viewRegistry) ->
debugger unless @viewRegistry?
@subscriptions ?= @subscribeToModel()
@childAdded({child, index}) for child, index in @model.getChildren()
@@ -35,7 +35,7 @@ class PaneAxisElement extends HTMLElement
element?.nodeName.toLowerCase() is 'atom-pane-resize-handle'
childAdded: ({child, index}) ->
view = @views.getView(child)
view = @viewRegistry.getView(child)
@insertBefore(view, @children[index * 2])
prevElement = view.previousSibling
@@ -51,7 +51,7 @@ class PaneAxisElement extends HTMLElement
@insertBefore(resizeHandle, nextElement)
childRemoved: ({child}) ->
view = @views.getView(child)
view = @viewRegistry.getView(child)
siblingView = view.previousSibling
# make sure next sibling view is pane resize view
if siblingView? and @isPaneResizeHandleElement(siblingView)

View File

@@ -1,6 +1,7 @@
{Emitter, CompositeDisposable} = require 'event-kit'
{flatten} = require 'underscore-plus'
Model = require './model'
PaneAxisElement = require './pane-axis-element'
module.exports =
class PaneAxis extends Model
@@ -8,12 +9,12 @@ class PaneAxis extends Model
container: null
orientation: null
@deserialize: (state, {deserializers}) ->
@deserialize: (state, {deserializers, views}) ->
state.children = state.children.map (childState) ->
deserializers.deserialize(childState)
new this(state)
new this(state, views)
constructor: ({@orientation, children, flexScale}={}) ->
constructor: ({@orientation, children, flexScale}, @viewRegistry) ->
@emitter = new Emitter
@subscriptionsByChild = new WeakMap
@subscriptions = new CompositeDisposable
@@ -28,6 +29,9 @@ class PaneAxis extends Model
orientation: @orientation
flexScale: @flexScale
getElement: ->
@element ?= new PaneAxisElement().initialize(this, @viewRegistry)
getFlexScale: -> @flexScale
setFlexScale: (@flexScale) ->

View File

@@ -820,7 +820,7 @@ class Pane extends Model
params.items.push(@copyActiveItem())
if @parent.orientation isnt orientation
@parent.replaceChild(this, new PaneAxis({@container, orientation, children: [this], @flexScale}))
@parent.replaceChild(this, new PaneAxis({@container, orientation, children: [this], @flexScale}, @viewRegistry))
@setFlexScale(1)
newPane = new Pane(extend({@applicationDelegate, @notificationManager, @deserializerManager, @config, @viewRegistry}, params))