mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Don't use atom globals in WorkspaceElement
This commit is contained in:
committed by
Nathan Sobo
parent
e9cda3ea5c
commit
2479b0cae2
@@ -195,8 +195,8 @@ class Atom extends Model
|
||||
@deserializers.add(TextBuffer)
|
||||
|
||||
registerViewProviders: ->
|
||||
@views.addViewProvider Workspace, (model) ->
|
||||
new WorkspaceElement().initialize(model)
|
||||
@views.addViewProvider Workspace, (model, env) ->
|
||||
new WorkspaceElement().initialize(model, env)
|
||||
@views.addViewProvider PanelContainer, (model) ->
|
||||
new PanelContainerElement().initialize(model)
|
||||
@views.addViewProvider Panel, (model, env) ->
|
||||
|
||||
@@ -8,12 +8,6 @@ module.exports =
|
||||
class WorkspaceElement extends HTMLElement
|
||||
globalTextEditorStyleSheet: null
|
||||
|
||||
createdCallback: ->
|
||||
@subscriptions = new CompositeDisposable
|
||||
@initializeContent()
|
||||
@observeScrollbarStyle()
|
||||
@observeTextEditorFontConfig()
|
||||
|
||||
attachedCallback: ->
|
||||
@focus()
|
||||
|
||||
@@ -46,31 +40,42 @@ class WorkspaceElement extends HTMLElement
|
||||
|
||||
observeTextEditorFontConfig: ->
|
||||
@updateGlobalTextEditorStyleSheet()
|
||||
@subscriptions.add atom.config.onDidChange 'editor.fontSize', @updateGlobalTextEditorStyleSheet.bind(this)
|
||||
@subscriptions.add atom.config.onDidChange 'editor.fontFamily', @updateGlobalTextEditorStyleSheet.bind(this)
|
||||
@subscriptions.add atom.config.onDidChange 'editor.lineHeight', @updateGlobalTextEditorStyleSheet.bind(this)
|
||||
@subscriptions.add @config.onDidChange 'editor.fontSize', @updateGlobalTextEditorStyleSheet.bind(this)
|
||||
@subscriptions.add @config.onDidChange 'editor.fontFamily', @updateGlobalTextEditorStyleSheet.bind(this)
|
||||
@subscriptions.add @config.onDidChange 'editor.lineHeight', @updateGlobalTextEditorStyleSheet.bind(this)
|
||||
|
||||
updateGlobalTextEditorStyleSheet: ->
|
||||
styleSheetSource = """
|
||||
atom-text-editor {
|
||||
font-size: #{atom.config.get('editor.fontSize')}px;
|
||||
font-family: #{atom.config.get('editor.fontFamily')};
|
||||
line-height: #{atom.config.get('editor.lineHeight')};
|
||||
font-size: #{@config.get('editor.fontSize')}px;
|
||||
font-family: #{@config.get('editor.fontFamily')};
|
||||
line-height: #{@config.get('editor.lineHeight')};
|
||||
}
|
||||
"""
|
||||
atom.styles.addStyleSheet(styleSheetSource, sourcePath: 'global-text-editor-styles')
|
||||
|
||||
initialize: (@model) ->
|
||||
@paneContainer = atom.views.getView(@model.paneContainer)
|
||||
initialize: (@model, {@views, @workspace, @project, @config, @styles}) ->
|
||||
throw new Error("Must pass a views parameter when initializing WorskpaceElements") unless @views?
|
||||
throw new Error("Must pass a workspace parameter when initializing WorskpaceElements") unless @workspace?
|
||||
throw new Error("Must pass a project parameter when initializing WorskpaceElements") unless @project?
|
||||
throw new Error("Must pass a config parameter when initializing WorskpaceElements") unless @config?
|
||||
throw new Error("Must pass a styles parameter when initializing WorskpaceElements") unless @styles?
|
||||
|
||||
@subscriptions = new CompositeDisposable
|
||||
@initializeContent()
|
||||
@observeScrollbarStyle()
|
||||
@observeTextEditorFontConfig()
|
||||
|
||||
@paneContainer = @views.getView(@model.paneContainer)
|
||||
@verticalAxis.appendChild(@paneContainer)
|
||||
@addEventListener 'focus', @handleFocus.bind(this)
|
||||
|
||||
@panelContainers =
|
||||
top: atom.views.getView(@model.panelContainers.top)
|
||||
left: atom.views.getView(@model.panelContainers.left)
|
||||
right: atom.views.getView(@model.panelContainers.right)
|
||||
bottom: atom.views.getView(@model.panelContainers.bottom)
|
||||
modal: atom.views.getView(@model.panelContainers.modal)
|
||||
top: @views.getView(@model.panelContainers.top)
|
||||
left: @views.getView(@model.panelContainers.left)
|
||||
right: @views.getView(@model.panelContainers.right)
|
||||
bottom: @views.getView(@model.panelContainers.bottom)
|
||||
modal: @views.getView(@model.panelContainers.modal)
|
||||
|
||||
@horizontalAxis.insertBefore(@panelContainers.left, @verticalAxis)
|
||||
@horizontalAxis.appendChild(@panelContainers.right)
|
||||
@@ -96,10 +101,10 @@ class WorkspaceElement extends HTMLElement
|
||||
focusPaneViewOnRight: -> @paneContainer.focusPaneViewOnRight()
|
||||
|
||||
runPackageSpecs: ->
|
||||
if activePath = atom.workspace.getActivePaneItem()?.getPath?()
|
||||
[projectPath] = atom.project.relativizePath(activePath)
|
||||
if activePath = @workspace.getActivePaneItem()?.getPath?()
|
||||
[projectPath] = @project.relativizePath(activePath)
|
||||
else
|
||||
[projectPath] = atom.project.getPaths()
|
||||
[projectPath] = @project.getPaths()
|
||||
ipc.send('run-package-specs', path.join(projectPath, 'spec')) if projectPath
|
||||
|
||||
module.exports = WorkspaceElement = document.registerElement 'atom-workspace', prototype: WorkspaceElement.prototype
|
||||
|
||||
Reference in New Issue
Block a user