Add Workspace.getElement method, remove WorkspaceElement view provider

This commit is contained in:
Max Brunsfeld
2017-04-05 15:09:20 -07:00
parent 88422ee4c9
commit 6d55371930
4 changed files with 34 additions and 22 deletions

View File

@@ -49,6 +49,7 @@ describe('Workspace', () => {
project: atom.project,
packageManager: atom.packages,
grammarRegistry: atom.grammars,
styleManager: atom.styles,
deserializerManager: atom.deserializers,
notificationManager: atom.notifications,
applicationDelegate: atom.applicationDelegate,

View File

@@ -179,7 +179,7 @@ class AtomEnvironment extends Model
@workspace = new Workspace({
@config, @project, packageManager: @packages, grammarRegistry: @grammars, deserializerManager: @deserializers,
notificationManager: @notifications, @applicationDelegate, viewRegistry: @views, assert: @assert.bind(this),
textEditorRegistry: @textEditors,
textEditorRegistry: @textEditors, styleManager: @styles
})
@themes.workspace = @workspace
@@ -285,8 +285,6 @@ class AtomEnvironment extends Model
registerDefaultCommands({commandRegistry: @commands, @config, @commandInstaller, notificationManager: @notifications, @project, @clipboard})
registerDefaultViewProviders: ->
@views.addViewProvider Workspace, (model, env) ->
new WorkspaceElement().initialize(model, env)
@views.addViewProvider PanelContainer, (model, env) ->
new PanelContainerElement().initialize(model, env)
@views.addViewProvider Panel, (model, env) ->

View File

@@ -60,11 +60,11 @@ class WorkspaceElement extends HTMLElement {
font-family: ${this.config.get('editor.fontFamily')};
line-height: ${this.config.get('editor.lineHeight')};
}`
this.styles.addStyleSheet(styleSheetSource, {sourcePath: 'global-text-editor-styles', priority: -1})
this.views.performDocumentPoll()
this.styleManager.addStyleSheet(styleSheetSource, {sourcePath: 'global-text-editor-styles', priority: -1})
this.viewRegistry.performDocumentPoll()
}
initialize (model, {views, workspace, project, config, styles}) {
initialize (model, {config, project, styleManager, viewRegistry}) {
this.handleCenterEnter = this.handleCenterEnter.bind(this)
this.handleCenterLeave = this.handleCenterLeave.bind(this)
this.handleEdgesMouseMove = _.throttle(this.handleEdgesMouseMove.bind(this), 100)
@@ -74,16 +74,14 @@ class WorkspaceElement extends HTMLElement {
this.handleDrop = this.handleDrop.bind(this)
this.model = model
this.views = views
this.workspace = workspace
this.viewRegistry = viewRegistry
this.project = project
this.config = config
this.styles = styles
if (this.views == null) { throw new Error('Must pass a views parameter when initializing WorskpaceElements') }
if (this.workspace == null) { throw new Error('Must pass a workspace parameter when initializing WorskpaceElements') }
this.styleManager = styleManager
if (this.viewRegistry == null) { throw new Error('Must pass a viewRegistry parameter when initializing WorskpaceElements') }
if (this.project == null) { throw new Error('Must pass a project parameter when initializing WorskpaceElements') }
if (this.config == null) { throw new Error('Must pass a config parameter when initializing WorskpaceElements') }
if (this.styles == null) { throw new Error('Must pass a styles parameter when initializing WorskpaceElements') }
if (this.styleManager == null) { throw new Error('Must pass a styleManager parameter when initializing WorskpaceElements') }
this.subscriptions = new CompositeDisposable(
new Disposable(() => {
@@ -100,7 +98,7 @@ class WorkspaceElement extends HTMLElement {
this.observeScrollbarStyle()
this.observeTextEditorFontConfig()
this.paneContainer = this.views.getView(this.model.paneContainer)
this.paneContainer = this.viewRegistry.getView(this.model.paneContainer)
this.verticalAxis.appendChild(this.paneContainer)
this.addEventListener('focus', this.handleFocus.bind(this))
@@ -108,13 +106,13 @@ class WorkspaceElement extends HTMLElement {
window.addEventListener('dragstart', this.handleDragStart)
this.panelContainers = {
top: this.views.getView(this.model.panelContainers.top),
left: this.views.getView(this.model.panelContainers.left),
right: this.views.getView(this.model.panelContainers.right),
bottom: this.views.getView(this.model.panelContainers.bottom),
header: this.views.getView(this.model.panelContainers.header),
footer: this.views.getView(this.model.panelContainers.footer),
modal: this.views.getView(this.model.panelContainers.modal)
top: this.viewRegistry.getView(this.model.panelContainers.top),
left: this.viewRegistry.getView(this.model.panelContainers.left),
right: this.viewRegistry.getView(this.model.panelContainers.right),
bottom: this.viewRegistry.getView(this.model.panelContainers.bottom),
header: this.viewRegistry.getView(this.model.panelContainers.header),
footer: this.viewRegistry.getView(this.model.panelContainers.footer),
modal: this.viewRegistry.getView(this.model.panelContainers.modal)
}
this.horizontalAxis.insertBefore(this.panelContainers.left, this.verticalAxis)
@@ -243,7 +241,7 @@ class WorkspaceElement extends HTMLElement {
moveActiveItemToPaneOnRight (params) { this.paneContainer.moveActiveItemToPaneOnRight(params) }
runPackageSpecs () {
const activePaneItem = this.workspace.getActivePaneItem()
const activePaneItem = this.model.getActivePaneItem()
const activePath = activePaneItem && typeof activePaneItem.getPath === 'function' ? activePaneItem.getPath() : null
let projectPath
if (activePath != null) {
@@ -263,7 +261,7 @@ class WorkspaceElement extends HTMLElement {
}
runBenchmarks () {
const activePaneItem = this.workspace.getActivePaneItem()
const activePaneItem = this.model.getActivePaneItem()
const activePath = activePaneItem && typeof activePaneItem.getPath === 'function' ? activePaneItem.getPath() : null
let projectPath
if (activePath) {

View File

@@ -17,6 +17,7 @@ const Panel = require('./panel')
const PanelContainer = require('./panel-container')
const Task = require('./task')
const WorkspaceCenter = require('./workspace-center')
const WorkspaceElement = require('./workspace-element')
// Essential: Represents the state of the user interface for the entire window.
// An instance of this class is available via the `atom.workspace` global.
@@ -46,6 +47,7 @@ module.exports = class Workspace extends Model {
this.assert = params.assert
this.deserializerManager = params.deserializerManager
this.textEditorRegistry = params.textEditorRegistry
this.styleManager = params.styleManager
this.hoveredDock = null
this.draggingItem = false
this.itemLocationStore = new StateStore('AtomPreviousItemLocations', 1)
@@ -91,6 +93,18 @@ module.exports = class Workspace extends Model {
this.paneContainer.initialize()
}
getElement () {
if (!this.element) {
this.element = new WorkspaceElement().initialize(this, {
config: this.config,
project: this.project,
viewRegistry: this.viewRegistry,
styleManager: this.styleManager
})
}
return this.element
}
createDock (location) {
const dock = new Dock({
location,
@@ -142,6 +156,7 @@ module.exports = class Workspace extends Model {
this.originalFontSize = null
this.openers = []
this.destroyedItemURIs = []
this.element = null
this.consumeServices(this.packageManager)
this.initialize()
}