Add PanelContainer.getElement, remove PanelContainer view provider

This commit is contained in:
Max Brunsfeld
2017-04-05 15:26:47 -07:00
parent 6f0b1947ee
commit d1e8e359ce
6 changed files with 34 additions and 32 deletions

View File

@@ -34,8 +34,8 @@ describe('PanelContainerElement', () => {
model => new TestPanelContainerItemElement().initialize(model)
)
container = new PanelContainer({location: 'left'})
element = atom.views.getView(container)
container = new PanelContainer({viewRegistry: atom.views, location: 'left'})
element = container.getElement()
jasmineContent.appendChild(element)
})
@@ -94,8 +94,8 @@ describe('PanelContainerElement', () => {
describe('when the container is at the bottom location', () => {
beforeEach(() => {
container = new PanelContainer({location: 'bottom'})
element = atom.views.getView(container)
container = new PanelContainer({viewRegistry: atom.views, location: 'bottom'})
element = container.getElement()
jasmineContent.appendChild(element)
})
@@ -127,8 +127,8 @@ describe('PanelContainerElement', () => {
describe('when the container is modal', () => {
beforeEach(() => {
container = new PanelContainer({location: 'modal'})
element = atom.views.getView(container)
container = new PanelContainer({viewRegistry: atom.views, location: 'modal'})
element = container.getElement()
jasmineContent.appendChild(element)
})

View File

@@ -10,7 +10,7 @@ describe('PanelContainer', () => {
}
beforeEach(() => {
container = new PanelContainer()
container = new PanelContainer({viewRegistry: atom.views})
})
describe('::addPanel(panel)', () => {

View File

@@ -47,8 +47,6 @@ Gutter = require './gutter'
TextEditorRegistry = require './text-editor-registry'
AutoUpdateManager = require './auto-update-manager'
WorkspaceElement = require './workspace-element'
PanelContainerElement = require './panel-container-element'
PanelElement = require './panel-element'
PaneAxisElement = require './pane-axis-element'
{createGutterView} = require './gutter-component-helpers'
@@ -285,8 +283,6 @@ class AtomEnvironment extends Model
registerDefaultCommands({commandRegistry: @commands, @config, @commandInstaller, notificationManager: @notifications, @project, @clipboard})
registerDefaultViewProviders: ->
@views.addViewProvider PanelContainer, (model, env) ->
new PanelContainerElement().initialize(model, env)
@views.addViewProvider Panel, (model, env) ->
new PanelElement().initialize(model, env)
@views.addViewProvider PaneAxis, (model, env) ->

View File

@@ -15,12 +15,9 @@ class PanelContainerElement extends HTMLElement {
}
}
initialize (model, {views}) {
initialize (model, viewRegistry) {
this.model = model
this.views = views
if (this.views == null) {
throw new Error('Must pass a views parameter when initializing PanelContainerElements')
}
this.viewRegistry = viewRegistry
this.subscriptions.add(this.model.onDidAddPanel(this.panelAdded.bind(this)))
this.subscriptions.add(this.model.onDidDestroy(this.destroyed.bind(this)))
@@ -37,7 +34,7 @@ class PanelContainerElement extends HTMLElement {
getModel () { return this.model }
panelAdded ({panel, index}) {
const panelElement = this.views.getView(panel)
const panelElement = this.viewRegistry.getView(panel)
panelElement.classList.add(this.model.getLocation())
if (this.model.isModal()) {
panelElement.classList.add('overlay', 'from-top')

View File

@@ -1,14 +1,16 @@
'use strict'
const {Emitter, CompositeDisposable} = require('event-kit')
const PanelContainerElement = require('./panel-container-element')
module.exports = class PanelContainer {
constructor ({location, dock} = {}) {
constructor ({location, dock, viewRegistry} = {}) {
this.location = location
this.emitter = new Emitter()
this.subscriptions = new CompositeDisposable()
this.panels = []
this.dock = dock
this.viewRegistry = viewRegistry
}
destroy () {
@@ -18,6 +20,13 @@ module.exports = class PanelContainer {
this.emitter.dispose()
}
getElement() {
if (!this.element) {
this.element = new PanelContainerElement().initialize(this, this.viewRegistry)
}
return this.element
}
/*
Section: Event Subscription
*/

View File

@@ -77,13 +77,13 @@ module.exports = class Workspace extends Model {
}
this.panelContainers = {
top: new PanelContainer({location: 'top'}),
left: new PanelContainer({location: 'left', dock: this.docks.left}),
right: new PanelContainer({location: 'right', dock: this.docks.right}),
bottom: new PanelContainer({location: 'bottom', dock: this.docks.bottom}),
header: new PanelContainer({location: 'header'}),
footer: new PanelContainer({location: 'footer'}),
modal: new PanelContainer({location: 'modal'})
top: new PanelContainer({viewRegistry: this.viewRegistry, location: 'top'}),
left: new PanelContainer({viewRegistry: this.viewRegistry, location: 'left', dock: this.docks.left}),
right: new PanelContainer({viewRegistry: this.viewRegistry, location: 'right', dock: this.docks.right}),
bottom: new PanelContainer({viewRegistry: this.viewRegistry, location: 'bottom', dock: this.docks.bottom}),
header: new PanelContainer({viewRegistry: this.viewRegistry, location: 'header'}),
footer: new PanelContainer({viewRegistry: this.viewRegistry, location: 'footer'}),
modal: new PanelContainer({viewRegistry: this.viewRegistry, location: 'modal'})
}
this.subscribeToEvents()
@@ -144,13 +144,13 @@ module.exports = class Workspace extends Model {
}
this.panelContainers = {
top: new PanelContainer({location: 'top'}),
left: new PanelContainer({location: 'left', dock: this.docks.left}),
right: new PanelContainer({location: 'right', dock: this.docks.right}),
bottom: new PanelContainer({location: 'bottom', dock: this.docks.bottom}),
header: new PanelContainer({location: 'header'}),
footer: new PanelContainer({location: 'footer'}),
modal: new PanelContainer({location: 'modal'})
top: new PanelContainer({viewRegistry: this.viewRegistry, location: 'top'}),
left: new PanelContainer({viewRegistry: this.viewRegistry, location: 'left', dock: this.docks.left}),
right: new PanelContainer({viewRegistry: this.viewRegistry, location: 'right', dock: this.docks.right}),
bottom: new PanelContainer({viewRegistry: this.viewRegistry, location: 'bottom', dock: this.docks.bottom}),
header: new PanelContainer({viewRegistry: this.viewRegistry, location: 'header'}),
footer: new PanelContainer({viewRegistry: this.viewRegistry, location: 'footer'}),
modal: new PanelContainer({viewRegistry: this.viewRegistry, location: 'modal'})
}
this.originalFontSize = null