From 6d55371930baf60ebf37cf884e341bde3dd346fa Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 5 Apr 2017 15:09:20 -0700 Subject: [PATCH] Add Workspace.getElement method, remove WorkspaceElement view provider --- spec/workspace-spec.js | 1 + src/atom-environment.coffee | 4 +--- src/workspace-element.js | 36 +++++++++++++++++------------------- src/workspace.js | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/spec/workspace-spec.js b/spec/workspace-spec.js index 3d4a7229d..9369f5edb 100644 --- a/spec/workspace-spec.js +++ b/spec/workspace-spec.js @@ -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, diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 458cfff59..36ac5587f 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -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) -> diff --git a/src/workspace-element.js b/src/workspace-element.js index a2fe39d5a..3b65616a8 100644 --- a/src/workspace-element.js +++ b/src/workspace-element.js @@ -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) { diff --git a/src/workspace.js b/src/workspace.js index 6efce9948..00500d9e7 100644 --- a/src/workspace.js +++ b/src/workspace.js @@ -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() }