mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-08 16:19:17 +03:00
Move the ViewRegistry to atom.views
This commit is contained in:
parent
c217c6544a
commit
ee4116536d
@ -7,7 +7,7 @@ describe "editorView.", ->
|
|||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
atom.workspaceViewParentSelector = '#jasmine-content'
|
atom.workspaceViewParentSelector = '#jasmine-content'
|
||||||
atom.workspaceView = atom.workspace.getView(atom.workspace).__spacePenView
|
atom.workspaceView = atom.views.getView(atom.workspace).__spacePenView
|
||||||
atom.workspaceView.attachToDom()
|
atom.workspaceView.attachToDom()
|
||||||
|
|
||||||
atom.workspaceView.width(1024)
|
atom.workspaceView.width(1024)
|
||||||
|
@ -6,7 +6,7 @@ ThemeManager = require '../src/theme-manager'
|
|||||||
|
|
||||||
describe "the `atom` global", ->
|
describe "the `atom` global", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
atom.workspaceView = atom.workspace.getView(atom.workspace).__spacePenView
|
atom.workspaceView = atom.views.getView(atom.workspace).__spacePenView
|
||||||
|
|
||||||
describe 'window sizing methods', ->
|
describe 'window sizing methods', ->
|
||||||
describe '::getPosition and ::setPosition', ->
|
describe '::getPosition and ::setPosition', ->
|
||||||
|
@ -3,7 +3,7 @@ Package = require '../src/package'
|
|||||||
|
|
||||||
describe "PackageManager", ->
|
describe "PackageManager", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
atom.workspaceView = atom.workspace.getView(atom.workspace).__spacePenView
|
atom.workspaceView = atom.views.getView(atom.workspace).__spacePenView
|
||||||
|
|
||||||
describe "::loadPackage(name)", ->
|
describe "::loadPackage(name)", ->
|
||||||
it "continues if the package has an invalid package.json", ->
|
it "continues if the package has an invalid package.json", ->
|
||||||
|
@ -19,7 +19,7 @@ describe "PaneContainerView", ->
|
|||||||
save: -> @saved = true
|
save: -> @saved = true
|
||||||
isEqual: (other) -> @name is other?.name
|
isEqual: (other) -> @name is other?.name
|
||||||
|
|
||||||
container = atom.workspace.getView(atom.workspace.paneContainer).__spacePenView
|
container = atom.views.getView(atom.workspace.paneContainer).__spacePenView
|
||||||
pane1 = container.getRoot()
|
pane1 = container.getRoot()
|
||||||
pane1.activateItem(new TestView('1'))
|
pane1.activateItem(new TestView('1'))
|
||||||
pane2 = pane1.splitRight(new TestView('2'))
|
pane2 = pane1.splitRight(new TestView('2'))
|
||||||
@ -73,7 +73,7 @@ describe "PaneContainerView", ->
|
|||||||
|
|
||||||
describe "serialization", ->
|
describe "serialization", ->
|
||||||
it "can be serialized and deserialized, and correctly adjusts dimensions of deserialized panes after attach", ->
|
it "can be serialized and deserialized, and correctly adjusts dimensions of deserialized panes after attach", ->
|
||||||
newContainer = atom.workspace.getView(container.model.testSerialization()).__spacePenView
|
newContainer = atom.views.getView(container.model.testSerialization()).__spacePenView
|
||||||
expect(newContainer.find('atom-pane-axis.horizontal > :contains(1)')).toExist()
|
expect(newContainer.find('atom-pane-axis.horizontal > :contains(1)')).toExist()
|
||||||
expect(newContainer.find('atom-pane-axis.horizontal > atom-pane-axis.vertical > :contains(2)')).toExist()
|
expect(newContainer.find('atom-pane-axis.horizontal > atom-pane-axis.vertical > :contains(2)')).toExist()
|
||||||
expect(newContainer.find('atom-pane-axis.horizontal > atom-pane-axis.vertical > :contains(3)')).toExist()
|
expect(newContainer.find('atom-pane-axis.horizontal > atom-pane-axis.vertical > :contains(3)')).toExist()
|
||||||
@ -89,14 +89,14 @@ describe "PaneContainerView", ->
|
|||||||
|
|
||||||
describe "if the 'core.destroyEmptyPanes' config option is false (the default)", ->
|
describe "if the 'core.destroyEmptyPanes' config option is false (the default)", ->
|
||||||
it "leaves the empty panes intact", ->
|
it "leaves the empty panes intact", ->
|
||||||
newContainer = atom.workspace.getView(container.model.testSerialization()).__spacePenView
|
newContainer = atom.views.getView(container.model.testSerialization()).__spacePenView
|
||||||
expect(newContainer.find('atom-pane-axis.horizontal > :contains(1)')).toExist()
|
expect(newContainer.find('atom-pane-axis.horizontal > :contains(1)')).toExist()
|
||||||
expect(newContainer.find('atom-pane-axis.horizontal > atom-pane-axis.vertical > atom-pane').length).toBe 2
|
expect(newContainer.find('atom-pane-axis.horizontal > atom-pane-axis.vertical > atom-pane').length).toBe 2
|
||||||
|
|
||||||
describe "if the 'core.destroyEmptyPanes' config option is true", ->
|
describe "if the 'core.destroyEmptyPanes' config option is true", ->
|
||||||
it "removes empty panes on deserialization", ->
|
it "removes empty panes on deserialization", ->
|
||||||
atom.config.set('core.destroyEmptyPanes', true)
|
atom.config.set('core.destroyEmptyPanes', true)
|
||||||
newContainer = atom.workspace.getView(container.model.testSerialization()).__spacePenView
|
newContainer = atom.views.getView(container.model.testSerialization()).__spacePenView
|
||||||
expect(newContainer.find('atom-pane-axis.horizontal, atom-pane-axis.vertical')).not.toExist()
|
expect(newContainer.find('atom-pane-axis.horizontal, atom-pane-axis.vertical')).not.toExist()
|
||||||
expect(newContainer.find('> :contains(1)')).toExist()
|
expect(newContainer.find('> :contains(1)')).toExist()
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ describe "PaneContainerView", ->
|
|||||||
item2b = new TestView('2b')
|
item2b = new TestView('2b')
|
||||||
item3a = new TestView('3a')
|
item3a = new TestView('3a')
|
||||||
|
|
||||||
container = atom.workspace.getView(new PaneContainer).__spacePenView
|
container = atom.views.getView(new PaneContainer).__spacePenView
|
||||||
pane1 = container.getRoot()
|
pane1 = container.getRoot()
|
||||||
pane1.activateItem(item1a)
|
pane1.activateItem(item1a)
|
||||||
container.attachToDom()
|
container.attachToDom()
|
||||||
@ -259,7 +259,7 @@ describe "PaneContainerView", ->
|
|||||||
# |7|8|9|
|
# |7|8|9|
|
||||||
# -------
|
# -------
|
||||||
|
|
||||||
container = atom.workspace.getView(new PaneContainer).__spacePenView
|
container = atom.views.getView(new PaneContainer).__spacePenView
|
||||||
pane1 = container.getRoot()
|
pane1 = container.getRoot()
|
||||||
pane1.activateItem(new TestView('1'))
|
pane1.activateItem(new TestView('1'))
|
||||||
pane4 = pane1.splitDown(new TestView('4'))
|
pane4 = pane1.splitDown(new TestView('4'))
|
||||||
|
@ -24,7 +24,7 @@ describe "PaneView", ->
|
|||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
deserializerDisposable = atom.deserializers.add(TestView)
|
deserializerDisposable = atom.deserializers.add(TestView)
|
||||||
container = atom.workspace.getView(new PaneContainer).__spacePenView
|
container = atom.views.getView(new PaneContainer).__spacePenView
|
||||||
containerModel = container.model
|
containerModel = container.model
|
||||||
view1 = new TestView(id: 'view-1', text: 'View 1')
|
view1 = new TestView(id: 'view-1', text: 'View 1')
|
||||||
view2 = new TestView(id: 'view-2', text: 'View 2')
|
view2 = new TestView(id: 'view-2', text: 'View 2')
|
||||||
@ -311,13 +311,13 @@ describe "PaneView", ->
|
|||||||
container.attachToDom()
|
container.attachToDom()
|
||||||
pane.focus()
|
pane.focus()
|
||||||
|
|
||||||
container2 = atom.workspace.getView(container.model.testSerialization()).__spacePenView
|
container2 = atom.views.getView(container.model.testSerialization()).__spacePenView
|
||||||
pane2 = container2.getRoot()
|
pane2 = container2.getRoot()
|
||||||
container2.attachToDom()
|
container2.attachToDom()
|
||||||
expect(pane2).toMatchSelector(':has(:focus)')
|
expect(pane2).toMatchSelector(':has(:focus)')
|
||||||
|
|
||||||
$(document.activeElement).blur()
|
$(document.activeElement).blur()
|
||||||
container3 = atom.workspace.getView(container.model.testSerialization()).__spacePenView
|
container3 = atom.views.getView(container.model.testSerialization()).__spacePenView
|
||||||
pane3 = container3.getRoot()
|
pane3 = container3.getRoot()
|
||||||
container3.attachToDom()
|
container3.attachToDom()
|
||||||
expect(pane3).not.toMatchSelector(':has(:focus)')
|
expect(pane3).not.toMatchSelector(':has(:focus)')
|
||||||
|
@ -208,7 +208,7 @@ describe "ThemeManager", ->
|
|||||||
|
|
||||||
describe "base stylesheet loading", ->
|
describe "base stylesheet loading", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
atom.workspaceView = atom.workspace.getView(atom.workspace).__spacePenView
|
atom.workspaceView = atom.views.getView(atom.workspace).__spacePenView
|
||||||
atom.workspaceView.append $('<atom-text-editor>')
|
atom.workspaceView.append $('<atom-text-editor>')
|
||||||
atom.workspaceView.attachToDom()
|
atom.workspaceView.attachToDom()
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ describe "WorkspaceView", ->
|
|||||||
atom.project.setPaths([atom.project.resolve('dir')])
|
atom.project.setPaths([atom.project.resolve('dir')])
|
||||||
pathToOpen = atom.project.resolve('a')
|
pathToOpen = atom.project.resolve('a')
|
||||||
atom.workspace = new Workspace
|
atom.workspace = new Workspace
|
||||||
atom.workspaceView = atom.workspace.getView(atom.workspace).__spacePenView
|
atom.workspaceView = atom.views.getView(atom.workspace).__spacePenView
|
||||||
atom.workspaceView.enableKeymap()
|
atom.workspaceView.enableKeymap()
|
||||||
atom.workspaceView.focus()
|
atom.workspaceView.focus()
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ describe "WorkspaceView", ->
|
|||||||
atom.workspaceView.remove()
|
atom.workspaceView.remove()
|
||||||
atom.project = atom.deserializers.deserialize(projectState)
|
atom.project = atom.deserializers.deserialize(projectState)
|
||||||
atom.workspace = Workspace.deserialize(workspaceState)
|
atom.workspace = Workspace.deserialize(workspaceState)
|
||||||
atom.workspaceView = atom.workspace.getView(atom.workspace).__spacePenView
|
atom.workspaceView = atom.views.getView(atom.workspace).__spacePenView
|
||||||
atom.workspaceView.attachToDom()
|
atom.workspaceView.attachToDom()
|
||||||
|
|
||||||
describe "when the serialized WorkspaceView has an unsaved buffer", ->
|
describe "when the serialized WorkspaceView has an unsaved buffer", ->
|
||||||
@ -274,7 +274,7 @@ describe "WorkspaceView", ->
|
|||||||
describe 'panel containers', ->
|
describe 'panel containers', ->
|
||||||
workspaceElement = null
|
workspaceElement = null
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
workspaceElement = atom.workspace.getView(atom.workspace)
|
workspaceElement = atom.views.getView(atom.workspace)
|
||||||
|
|
||||||
it 'inserts panel container elements in the correct places in the DOM', ->
|
it 'inserts panel container elements in the correct places in the DOM', ->
|
||||||
leftContainer = workspaceElement.querySelector('atom-panel-container[location="left"]')
|
leftContainer = workspaceElement.querySelector('atom-panel-container[location="left"]')
|
||||||
|
@ -140,6 +140,9 @@ class Atom extends Model
|
|||||||
# Public: A {DeserializerManager} instance
|
# Public: A {DeserializerManager} instance
|
||||||
deserializers: null
|
deserializers: null
|
||||||
|
|
||||||
|
# Public: A {ViewRegistry} instance
|
||||||
|
views: null
|
||||||
|
|
||||||
# Public: A {Workspace} instance
|
# Public: A {Workspace} instance
|
||||||
workspace: null
|
workspace: null
|
||||||
|
|
||||||
@ -182,6 +185,7 @@ class Atom extends Model
|
|||||||
|
|
||||||
Config = require './config'
|
Config = require './config'
|
||||||
KeymapManager = require './keymap-extensions'
|
KeymapManager = require './keymap-extensions'
|
||||||
|
ViewRegistry = require './view-registry'
|
||||||
CommandRegistry = require './command-registry'
|
CommandRegistry = require './command-registry'
|
||||||
PackageManager = require './package-manager'
|
PackageManager = require './package-manager'
|
||||||
Clipboard = require './clipboard'
|
Clipboard = require './clipboard'
|
||||||
@ -209,6 +213,7 @@ class Atom extends Model
|
|||||||
@keymaps = new KeymapManager({configDirPath, resourcePath})
|
@keymaps = new KeymapManager({configDirPath, resourcePath})
|
||||||
@keymap = @keymaps # Deprecated
|
@keymap = @keymaps # Deprecated
|
||||||
@commands = new CommandRegistry
|
@commands = new CommandRegistry
|
||||||
|
@views = new ViewRegistry
|
||||||
@packages = new PackageManager({devMode, configDirPath, resourcePath, safeMode})
|
@packages = new PackageManager({devMode, configDirPath, resourcePath, safeMode})
|
||||||
@styles = new StyleManager
|
@styles = new StyleManager
|
||||||
document.head.appendChild(new StylesElement)
|
document.head.appendChild(new StylesElement)
|
||||||
@ -597,7 +602,7 @@ class Atom extends Model
|
|||||||
|
|
||||||
startTime = Date.now()
|
startTime = Date.now()
|
||||||
@workspace = Workspace.deserialize(@state.workspace) ? new Workspace
|
@workspace = Workspace.deserialize(@state.workspace) ? new Workspace
|
||||||
@workspaceView = @workspace.getView(@workspace).__spacePenView
|
@workspaceView = @views.getView(@workspace).__spacePenView
|
||||||
@deserializeTimings.workspace = Date.now() - startTime
|
@deserializeTimings.workspace = Date.now() - startTime
|
||||||
|
|
||||||
@keymaps.defaultTarget = @workspaceView[0]
|
@keymaps.defaultTarget = @workspaceView[0]
|
||||||
|
@ -1,17 +1,90 @@
|
|||||||
{Disposable} = require 'event-kit'
|
{Disposable} = require 'event-kit'
|
||||||
{jQuery} = require './space-pen-extensions'
|
{jQuery} = require './space-pen-extensions'
|
||||||
|
|
||||||
|
# Essential
|
||||||
module.exports =
|
module.exports =
|
||||||
class ViewRegistry
|
class ViewRegistry
|
||||||
constructor: ->
|
constructor: ->
|
||||||
@views = new WeakMap
|
@views = new WeakMap
|
||||||
@providers = []
|
@providers = []
|
||||||
|
|
||||||
|
# Essential: Add a provider that will be used to construct views in the
|
||||||
|
# workspace's view layer based on model objects in its model layer.
|
||||||
|
#
|
||||||
|
# If you're adding your own kind of pane item, a good strategy for all but the
|
||||||
|
# simplest items is to separate the model and the view. The model handles
|
||||||
|
# application logic and is the primary point of API interaction. The view
|
||||||
|
# just handles presentation.
|
||||||
|
#
|
||||||
|
# Use view providers to inform the workspace how your model objects should be
|
||||||
|
# presented in the DOM. A view provider must always return a DOM node, which
|
||||||
|
# makes [HTML 5 custom elements](http://www.html5rocks.com/en/tutorials/webcomponents/customelements/)
|
||||||
|
# an ideal tool for implementing views in Atom.
|
||||||
|
#
|
||||||
|
# ## Examples
|
||||||
|
#
|
||||||
|
# Text editors are divided into a model and a view layer, so when you interact
|
||||||
|
# with methods like `atom.workspace.getActiveTextEditor()` you're only going
|
||||||
|
# to get the model object. We display text editors on screen by teaching the
|
||||||
|
# workspace what view constructor it should use to represent them:
|
||||||
|
#
|
||||||
|
# ```coffee
|
||||||
|
# atom.views.addViewProvider
|
||||||
|
# modelConstructor: TextEditor
|
||||||
|
# viewConstructor: TextEditorElement
|
||||||
|
# ```
|
||||||
|
#
|
||||||
|
# * `providerSpec` {Object} containing the following keys:
|
||||||
|
# * `modelConstructor` Constructor {Function} for your model.
|
||||||
|
# * `viewConstructor` (Optional) Constructor {Function} for your view. It
|
||||||
|
# should be a subclass of `HTMLElement` (that is, your view should be a
|
||||||
|
# DOM node) and have a `::setModel()` method which will be called
|
||||||
|
# immediately after construction. If you don't supply this property, you
|
||||||
|
# must supply the `createView` property with a function that never returns
|
||||||
|
# `undefined`.
|
||||||
|
# * `createView` (Optional) Factory {Function} that must return a subclass
|
||||||
|
# of `HTMLElement` or `undefined`. If this property is not present or the
|
||||||
|
# function returns `undefined`, the view provider will fall back to the
|
||||||
|
# `viewConstructor` property. If you don't provide this property, you must
|
||||||
|
# provider a `viewConstructor` property.
|
||||||
|
#
|
||||||
|
# Returns a {Disposable} on which `.dispose()` can be called to remove the
|
||||||
|
# added provider.
|
||||||
addViewProvider: (providerSpec) ->
|
addViewProvider: (providerSpec) ->
|
||||||
@providers.push(providerSpec)
|
@providers.push(providerSpec)
|
||||||
new Disposable =>
|
new Disposable =>
|
||||||
@providers = @providers.filter (provider) -> provider isnt providerSpec
|
@providers = @providers.filter (provider) -> provider isnt providerSpec
|
||||||
|
|
||||||
|
# Essential: Get the view associated with an object in the workspace.
|
||||||
|
#
|
||||||
|
# If you're just *using* the workspace, you shouldn't need to access the view
|
||||||
|
# layer, but view layer access may be necessary if you want to perform DOM
|
||||||
|
# manipulation that isn't supported via the model API.
|
||||||
|
#
|
||||||
|
# ## Examples
|
||||||
|
#
|
||||||
|
# ### Getting An Editor View
|
||||||
|
# ```coffee
|
||||||
|
# textEditor = atom.workspace.getActiveTextEditor()
|
||||||
|
# textEditorView = atom.views.getView(textEditor)
|
||||||
|
# ```
|
||||||
|
#
|
||||||
|
# ### Getting A Pane View
|
||||||
|
# ```coffee
|
||||||
|
# pane = atom.workspace.getActivePane()
|
||||||
|
# paneView = atom.views.getView(pane)
|
||||||
|
# ```
|
||||||
|
#
|
||||||
|
# ### Getting The Workspace View
|
||||||
|
#
|
||||||
|
# ```coffee
|
||||||
|
# workspaceView = atom.views.getView(atom.workspace)
|
||||||
|
# ```
|
||||||
|
#
|
||||||
|
# * `object` The object for which you want to retrieve a view. This can be a
|
||||||
|
# pane item, a pane, or the workspace itself.
|
||||||
|
#
|
||||||
|
# Returns a DOM element.
|
||||||
getView: (object) ->
|
getView: (object) ->
|
||||||
return unless object?
|
return unless object?
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class WorkspaceElement extends HTMLElement
|
|||||||
getModel: -> @model
|
getModel: -> @model
|
||||||
|
|
||||||
setModel: (@model) ->
|
setModel: (@model) ->
|
||||||
@paneContainer = @model.getView(@model.paneContainer)
|
@paneContainer = atom.views.getView(@model.paneContainer)
|
||||||
@verticalAxis.appendChild(@paneContainer)
|
@verticalAxis.appendChild(@paneContainer)
|
||||||
|
|
||||||
@addEventListener 'focus', @handleFocus.bind(this)
|
@addEventListener 'focus', @handleFocus.bind(this)
|
||||||
|
@ -59,7 +59,7 @@ class WorkspaceView extends View
|
|||||||
|
|
||||||
constructor: (@element) ->
|
constructor: (@element) ->
|
||||||
unless @element?
|
unless @element?
|
||||||
return atom.workspace.getView(atom.workspace).__spacePenView
|
return atom.views.getView(atom.workspace).__spacePenView
|
||||||
super
|
super
|
||||||
@deprecateViewEvents()
|
@deprecateViewEvents()
|
||||||
|
|
||||||
|
@ -45,15 +45,15 @@ class Workspace extends Model
|
|||||||
@emitter = new Emitter
|
@emitter = new Emitter
|
||||||
@openers = []
|
@openers = []
|
||||||
|
|
||||||
@viewRegistry ?= new ViewRegistry
|
viewRegistry = atom.views
|
||||||
@paneContainer ?= new PaneContainer({@viewRegistry})
|
@paneContainer ?= new PaneContainer({viewRegistry})
|
||||||
@paneContainer.onDidDestroyPaneItem(@onPaneItemDestroyed)
|
@paneContainer.onDidDestroyPaneItem(@onPaneItemDestroyed)
|
||||||
|
|
||||||
@panelContainers =
|
@panelContainers =
|
||||||
top: new PanelContainer({@viewRegistry, location: 'top'})
|
top: new PanelContainer({viewRegistry, location: 'top'})
|
||||||
left: new PanelContainer({@viewRegistry, location: 'left'})
|
left: new PanelContainer({viewRegistry, location: 'left'})
|
||||||
right: new PanelContainer({@viewRegistry, location: 'right'})
|
right: new PanelContainer({viewRegistry, location: 'right'})
|
||||||
bottom: new PanelContainer({@viewRegistry, location: 'bottom'})
|
bottom: new PanelContainer({viewRegistry, location: 'bottom'})
|
||||||
|
|
||||||
@subscribeToActiveItem()
|
@subscribeToActiveItem()
|
||||||
|
|
||||||
@ -68,15 +68,15 @@ class Workspace extends Model
|
|||||||
when 'atom://.atom/init-script'
|
when 'atom://.atom/init-script'
|
||||||
@open(atom.getUserInitScriptPath())
|
@open(atom.getUserInitScriptPath())
|
||||||
|
|
||||||
@addViewProvider
|
atom.views.addViewProvider
|
||||||
modelConstructor: Workspace
|
modelConstructor: Workspace
|
||||||
viewConstructor: WorkspaceElement
|
viewConstructor: WorkspaceElement
|
||||||
|
|
||||||
@addViewProvider
|
atom.views.addViewProvider
|
||||||
modelConstructor: PanelContainer
|
modelConstructor: PanelContainer
|
||||||
viewConstructor: PanelContainerElement
|
viewConstructor: PanelContainerElement
|
||||||
|
|
||||||
@addViewProvider
|
atom.views.addViewProvider
|
||||||
modelConstructor: Panel
|
modelConstructor: Panel
|
||||||
viewConstructor: PanelElement
|
viewConstructor: PanelElement
|
||||||
|
|
||||||
@ -85,8 +85,7 @@ class Workspace extends Model
|
|||||||
for packageName in params.packagesWithActiveGrammars ? []
|
for packageName in params.packagesWithActiveGrammars ? []
|
||||||
atom.packages.getLoadedPackage(packageName)?.loadGrammarsSync()
|
atom.packages.getLoadedPackage(packageName)?.loadGrammarsSync()
|
||||||
|
|
||||||
params.viewRegistry = new ViewRegistry
|
params.paneContainer.viewRegistry = atom.views
|
||||||
params.paneContainer.viewRegistry = params.viewRegistry
|
|
||||||
params.paneContainer = PaneContainer.deserialize(params.paneContainer)
|
params.paneContainer = PaneContainer.deserialize(params.paneContainer)
|
||||||
params
|
params
|
||||||
|
|
||||||
@ -605,8 +604,8 @@ class Workspace extends Model
|
|||||||
#
|
#
|
||||||
# * `options` {Object}
|
# * `options` {Object}
|
||||||
# * `item` Your panel content. It can be DOM element, a jQuery element, or
|
# * `item` Your panel content. It can be DOM element, a jQuery element, or
|
||||||
# a model with a view registered via {::addViewProvider}. We recommend the
|
# a model with a view registered via {ViewRegistry::addViewProvider}. We recommend the
|
||||||
# latter. See {::addViewProvider} for more information.
|
# latter. See {ViewRegistry::addViewProvider} for more information.
|
||||||
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
|
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
|
||||||
# (default: true)
|
# (default: true)
|
||||||
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are
|
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are
|
||||||
@ -620,8 +619,8 @@ class Workspace extends Model
|
|||||||
#
|
#
|
||||||
# * `options` {Object}
|
# * `options` {Object}
|
||||||
# * `item` Your panel content. It can be DOM element, a jQuery element, or
|
# * `item` Your panel content. It can be DOM element, a jQuery element, or
|
||||||
# a model with a view registered via {::addViewProvider}. We recommend the
|
# a model with a view registered via {ViewRegistry::addViewProvider}. We recommend the
|
||||||
# latter. See {::addViewProvider} for more information.
|
# latter. See {ViewRegistry::addViewProvider} for more information.
|
||||||
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
|
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
|
||||||
# (default: true)
|
# (default: true)
|
||||||
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are
|
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are
|
||||||
@ -635,8 +634,8 @@ class Workspace extends Model
|
|||||||
#
|
#
|
||||||
# * `options` {Object}
|
# * `options` {Object}
|
||||||
# * `item` Your panel content. It can be DOM element, a jQuery element, or
|
# * `item` Your panel content. It can be DOM element, a jQuery element, or
|
||||||
# a model with a view registered via {::addViewProvider}. We recommend the
|
# a model with a view registered via {ViewRegistry::addViewProvider}. We recommend the
|
||||||
# latter. See {::addViewProvider} for more information.
|
# latter. See {ViewRegistry::addViewProvider} for more information.
|
||||||
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
|
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
|
||||||
# (default: true)
|
# (default: true)
|
||||||
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are
|
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are
|
||||||
@ -650,8 +649,8 @@ class Workspace extends Model
|
|||||||
#
|
#
|
||||||
# * `options` {Object}
|
# * `options` {Object}
|
||||||
# * `item` Your panel content. It can be DOM element, a jQuery element, or
|
# * `item` Your panel content. It can be DOM element, a jQuery element, or
|
||||||
# a model with a view registered via {::addViewProvider}. We recommend the
|
# a model with a view registered via {ViewRegistry::addViewProvider}. We recommend the
|
||||||
# latter. See {::addViewProvider} for more information.
|
# latter. See {ViewRegistry::addViewProvider} for more information.
|
||||||
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
|
# * `visible` (optional) {Boolean} false if you want the panel to initially be hidden
|
||||||
# (default: true)
|
# (default: true)
|
||||||
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are
|
# * `priority` (optional) {Number} Determines stacking order. Lower priority items are
|
||||||
@ -663,87 +662,5 @@ class Workspace extends Model
|
|||||||
|
|
||||||
addPanel: (location, options) ->
|
addPanel: (location, options) ->
|
||||||
options ?= {}
|
options ?= {}
|
||||||
options.viewRegistry = @viewRegistry
|
options.viewRegistry = atom.views
|
||||||
@panelContainers[location].addPanel(new Panel(options))
|
@panelContainers[location].addPanel(new Panel(options))
|
||||||
|
|
||||||
###
|
|
||||||
Section: View Management
|
|
||||||
###
|
|
||||||
|
|
||||||
# Essential: Get the view associated with an object in the workspace.
|
|
||||||
#
|
|
||||||
# If you're just *using* the workspace, you shouldn't need to access the view
|
|
||||||
# layer, but view layer access may be necessary if you want to perform DOM
|
|
||||||
# manipulation that isn't supported via the model API.
|
|
||||||
#
|
|
||||||
# ## Examples
|
|
||||||
#
|
|
||||||
# ### Getting An Editor View
|
|
||||||
# ```coffee
|
|
||||||
# textEditor = atom.workspace.getActiveTextEditor()
|
|
||||||
# textEditorView = atom.workspace.getView(textEditor)
|
|
||||||
# ```
|
|
||||||
#
|
|
||||||
# ### Getting A Pane View
|
|
||||||
# ```coffee
|
|
||||||
# pane = atom.workspace.getActivePane()
|
|
||||||
# paneView = atom.workspace.getView(pane)
|
|
||||||
# ```
|
|
||||||
#
|
|
||||||
# ### Getting The Workspace View
|
|
||||||
#
|
|
||||||
# ```coffee
|
|
||||||
# workspaceView = atom.workspace.getView(atom.workspace)
|
|
||||||
# ```
|
|
||||||
#
|
|
||||||
# * `object` The object for which you want to retrieve a view. This can be a
|
|
||||||
# pane item, a pane, or the workspace itself.
|
|
||||||
#
|
|
||||||
# Returns a DOM element.
|
|
||||||
getView: (object) ->
|
|
||||||
@viewRegistry.getView(object)
|
|
||||||
|
|
||||||
# Essential: Add a provider that will be used to construct views in the
|
|
||||||
# workspace's view layer based on model objects in its model layer.
|
|
||||||
#
|
|
||||||
# If you're adding your own kind of pane item, a good strategy for all but the
|
|
||||||
# simplest items is to separate the model and the view. The model handles
|
|
||||||
# application logic and is the primary point of API interaction. The view
|
|
||||||
# just handles presentation.
|
|
||||||
#
|
|
||||||
# Use view providers to inform the workspace how your model objects should be
|
|
||||||
# presented in the DOM. A view provider must always return a DOM node, which
|
|
||||||
# makes [HTML 5 custom elements](http://www.html5rocks.com/en/tutorials/webcomponents/customelements/)
|
|
||||||
# an ideal tool for implementing views in Atom.
|
|
||||||
#
|
|
||||||
# ## Examples
|
|
||||||
#
|
|
||||||
# Text editors are divided into a model and a view layer, so when you interact
|
|
||||||
# with methods like `atom.workspace.getActiveTextEditor()` you're only going
|
|
||||||
# to get the model object. We display text editors on screen by teaching the
|
|
||||||
# workspace what view constructor it should use to represent them:
|
|
||||||
#
|
|
||||||
# ```coffee
|
|
||||||
# atom.workspace.addViewProvider
|
|
||||||
# modelConstructor: TextEditor
|
|
||||||
# viewConstructor: TextEditorElement
|
|
||||||
# ```
|
|
||||||
#
|
|
||||||
# * `providerSpec` {Object} containing the following keys:
|
|
||||||
# * `modelConstructor` Constructor {Function} for your model.
|
|
||||||
# * `viewConstructor` (Optional) Constructor {Function} for your view. It
|
|
||||||
# should be a subclass of `HTMLElement` (that is, your view should be a
|
|
||||||
# DOM node) and have a `::setModel()` method which will be called
|
|
||||||
# immediately after construction. If you don't supply this property, you
|
|
||||||
# must supply the `createView` property with a function that never returns
|
|
||||||
# `undefined`.
|
|
||||||
# * `createView` (Optional) Factory {Function} that must return a subclass
|
|
||||||
# of `HTMLElement` or `undefined`. If this property is not present or the
|
|
||||||
# function returns `undefined`, the view provider will fall back to the
|
|
||||||
# `viewConstructor` property. If you don't provide this property, you must
|
|
||||||
# provider a `viewConstructor` property.
|
|
||||||
#
|
|
||||||
# Returns a {Disposable} on which `.dispose()` can be called to remove the
|
|
||||||
# added provider.
|
|
||||||
addViewProvider: (providerSpec) ->
|
|
||||||
@viewRegistry.addViewProvider(providerSpec)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user