Remove view registry references from the workspace model layer

Removed various ::getView methods from the model. Using the atom.views
global in the views for now, but going to switch them over to using a
locally assigned view registry instead in a subsequent commit.
Esse commit está contido em:
Nathan Sobo
2014-11-30 14:47:51 -07:00
commit de Max Brunsfeld
commit 4591f00a65
19 arquivos alterados com 98 adições e 127 exclusões
+4 -4
Ver Arquivo
@@ -229,7 +229,7 @@ describe "PaneView", ->
beforeEach -> beforeEach ->
pane2Model = paneModel.splitRight() # Can't destroy the last pane, so we add another pane2Model = paneModel.splitRight() # Can't destroy the last pane, so we add another
pane2 = containerModel.getView(pane2Model).__spacePenView pane2 = atom.views.getView(pane2Model).__spacePenView
it "triggers a 'pane:removed' event with the pane", -> it "triggers a 'pane:removed' event with the pane", ->
removedHandler = jasmine.createSpy("removedHandler") removedHandler = jasmine.createSpy("removedHandler")
@@ -262,7 +262,7 @@ describe "PaneView", ->
beforeEach -> beforeEach ->
pane2Model = paneModel.splitRight(items: [pane.copyActiveItem()]) pane2Model = paneModel.splitRight(items: [pane.copyActiveItem()])
pane2 = containerModel.getView(pane2Model).__spacePenView pane2 = atom.views.getView(pane2Model).__spacePenView
expect(pane2Model.isActive()).toBe true expect(pane2Model.isActive()).toBe true
it "adds or removes the .active class as appropriate", -> it "adds or removes the .active class as appropriate", ->
@@ -309,8 +309,8 @@ describe "PaneView", ->
pane2Model = pane1Model.splitRight(items: [pane1Model.copyActiveItem()]) pane2Model = pane1Model.splitRight(items: [pane1Model.copyActiveItem()])
pane3Model = pane2Model.splitDown(items: [pane2Model.copyActiveItem()]) pane3Model = pane2Model.splitDown(items: [pane2Model.copyActiveItem()])
pane2 = pane2Model._view pane2 = pane2Model._view
pane2 = containerModel.getView(pane2Model).__spacePenView pane2 = atom.views.getView(pane2Model).__spacePenView
pane3 = containerModel.getView(pane3Model).__spacePenView pane3 = atom.views.getView(pane3Model).__spacePenView
expect(container.find('> atom-pane-axis.horizontal > atom-pane').toArray()).toEqual [pane1[0]] expect(container.find('> atom-pane-axis.horizontal > atom-pane').toArray()).toEqual [pane1[0]]
expect(container.find('> atom-pane-axis.horizontal > atom-pane-axis.vertical > atom-pane').toArray()).toEqual [pane2[0], pane3[0]] expect(container.find('> atom-pane-axis.horizontal > atom-pane-axis.vertical > atom-pane').toArray()).toEqual [pane2[0], pane3[0]]
+33 -35
Ver Arquivo
@@ -1,11 +1,10 @@
ViewRegistry = require '../src/view-registry'
Panel = require '../src/panel' Panel = require '../src/panel'
PanelElement = require '../src/panel-element' PanelElement = require '../src/panel-element'
PanelContainer = require '../src/panel-container' PanelContainer = require '../src/panel-container'
PanelContainerElement = require '../src/panel-container-element' PanelContainerElement = require '../src/panel-container-element'
describe "PanelContainerElement", -> describe "PanelContainerElement", ->
[jasmineContent, element, container, viewRegistry] = [] [jasmineContent, element, container] = []
class TestPanelContainerItem class TestPanelContainerItem
constructior: -> constructior: ->
@@ -19,19 +18,18 @@ describe "PanelContainerElement", ->
beforeEach -> beforeEach ->
jasmineContent = document.body.querySelector('#jasmine-content') jasmineContent = document.body.querySelector('#jasmine-content')
viewRegistry = new ViewRegistry atom.views.addViewProvider
viewRegistry.addViewProvider
modelConstructor: Panel modelConstructor: Panel
viewConstructor: PanelElement viewConstructor: PanelElement
viewRegistry.addViewProvider atom.views.addViewProvider
modelConstructor: PanelContainer modelConstructor: PanelContainer
viewConstructor: PanelContainerElement viewConstructor: PanelContainerElement
viewRegistry.addViewProvider atom.views.addViewProvider
modelConstructor: TestPanelContainerItem modelConstructor: TestPanelContainerItem
viewConstructor: TestPanelContainerItemElement viewConstructor: TestPanelContainerItemElement
container = new PanelContainer({viewRegistry, location: 'left'}) container = new PanelContainer({location: 'left'})
element = container.getView() element = atom.views.getView(container)
jasmineContent.appendChild(element) jasmineContent.appendChild(element)
it 'has a location class with value from the model', -> it 'has a location class with value from the model', ->
@@ -44,9 +42,9 @@ describe "PanelContainerElement", ->
describe "adding and removing panels", -> describe "adding and removing panels", ->
it "allows panels to be inserted at any position", -> it "allows panels to be inserted at any position", ->
panel1 = new Panel({viewRegistry, item: new TestPanelContainerItem(), priority: 10}) panel1 = new Panel({item: new TestPanelContainerItem(), priority: 10})
panel2 = new Panel({viewRegistry, item: new TestPanelContainerItem(), priority: 5}) panel2 = new Panel({item: new TestPanelContainerItem(), priority: 5})
panel3 = new Panel({viewRegistry, item: new TestPanelContainerItem(), priority: 8}) panel3 = new Panel({item: new TestPanelContainerItem(), priority: 8})
container.addPanel(panel1) container.addPanel(panel1)
container.addPanel(panel2) container.addPanel(panel2)
@@ -60,7 +58,7 @@ describe "PanelContainerElement", ->
it "adds atom-panel elements when a new panel is added to the container; removes them when the panels are destroyed", -> it "adds atom-panel elements when a new panel is added to the container; removes them when the panels are destroyed", ->
expect(element.childNodes.length).toBe 0 expect(element.childNodes.length).toBe 0
panel1 = new Panel({viewRegistry, item: new TestPanelContainerItem()}) panel1 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel1) container.addPanel(panel1)
expect(element.childNodes.length).toBe 1 expect(element.childNodes.length).toBe 1
expect(element.childNodes[0]).toHaveClass 'left' expect(element.childNodes[0]).toHaveClass 'left'
@@ -69,12 +67,12 @@ describe "PanelContainerElement", ->
expect(element.childNodes[0].tagName).toBe 'ATOM-PANEL' expect(element.childNodes[0].tagName).toBe 'ATOM-PANEL'
panel2 = new Panel({viewRegistry, item: new TestPanelContainerItem()}) panel2 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel2) container.addPanel(panel2)
expect(element.childNodes.length).toBe 2 expect(element.childNodes.length).toBe 2
expect(panel1.getView().style.display).not.toBe 'none' expect(atom.views.getView(panel1).style.display).not.toBe 'none'
expect(panel2.getView().style.display).not.toBe 'none' expect(atom.views.getView(panel2).style.display).not.toBe 'none'
panel1.destroy() panel1.destroy()
expect(element.childNodes.length).toBe 1 expect(element.childNodes.length).toBe 1
@@ -84,26 +82,26 @@ describe "PanelContainerElement", ->
describe "when the container is at the bottom location", -> describe "when the container is at the bottom location", ->
beforeEach -> beforeEach ->
container = new PanelContainer({viewRegistry, location: 'bottom'}) container = new PanelContainer({location: 'bottom'})
element = container.getView() element = atom.views.getView(container)
jasmineContent.appendChild(element) jasmineContent.appendChild(element)
it "adds atom-panel elements when a new panel is added to the container; removes them when the panels are destroyed", -> it "adds atom-panel elements when a new panel is added to the container; removes them when the panels are destroyed", ->
expect(element.childNodes.length).toBe 0 expect(element.childNodes.length).toBe 0
panel1 = new Panel({viewRegistry, item: new TestPanelContainerItem(), className: 'one'}) panel1 = new Panel({item: new TestPanelContainerItem(), className: 'one'})
container.addPanel(panel1) container.addPanel(panel1)
expect(element.childNodes.length).toBe 1 expect(element.childNodes.length).toBe 1
expect(element.childNodes[0]).toHaveClass 'bottom' expect(element.childNodes[0]).toHaveClass 'bottom'
expect(element.childNodes[0]).toHaveClass 'tool-panel' # legacy selector support expect(element.childNodes[0]).toHaveClass 'tool-panel' # legacy selector support
expect(element.childNodes[0]).toHaveClass 'panel-bottom' # legacy selector support expect(element.childNodes[0]).toHaveClass 'panel-bottom' # legacy selector support
expect(element.childNodes[0].tagName).toBe 'ATOM-PANEL' expect(element.childNodes[0].tagName).toBe 'ATOM-PANEL'
expect(panel1.getView()).toHaveClass 'one' expect(atom.views.getView(panel1)).toHaveClass 'one'
panel2 = new Panel({viewRegistry, item: new TestPanelContainerItem(), className: 'two'}) panel2 = new Panel({item: new TestPanelContainerItem(), className: 'two'})
container.addPanel(panel2) container.addPanel(panel2)
expect(element.childNodes.length).toBe 2 expect(element.childNodes.length).toBe 2
expect(panel2.getView()).toHaveClass 'two' expect(atom.views.getView(panel2)).toHaveClass 'two'
panel1.destroy() panel1.destroy()
expect(element.childNodes.length).toBe 1 expect(element.childNodes.length).toBe 1
@@ -113,34 +111,34 @@ describe "PanelContainerElement", ->
describe "when the container is modal", -> describe "when the container is modal", ->
beforeEach -> beforeEach ->
container = new PanelContainer({viewRegistry, location: 'modal'}) container = new PanelContainer({location: 'modal'})
element = container.getView() element = atom.views.getView(container)
jasmineContent.appendChild(element) jasmineContent.appendChild(element)
it "allows only one panel to be visible at a time", -> it "allows only one panel to be visible at a time", ->
panel1 = new Panel({viewRegistry, item: new TestPanelContainerItem()}) panel1 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel1) container.addPanel(panel1)
expect(panel1.getView().style.display).not.toBe 'none' expect(atom.views.getView(panel1).style.display).not.toBe 'none'
panel2 = new Panel({viewRegistry, item: new TestPanelContainerItem()}) panel2 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel2) container.addPanel(panel2)
expect(panel1.getView().style.display).toBe 'none' expect(atom.views.getView(panel1).style.display).toBe 'none'
expect(panel2.getView().style.display).not.toBe 'none' expect(atom.views.getView(panel2).style.display).not.toBe 'none'
panel1.show() panel1.show()
expect(panel1.getView().style.display).not.toBe 'none' expect(atom.views.getView(panel1).style.display).not.toBe 'none'
expect(panel2.getView().style.display).toBe 'none' expect(atom.views.getView(panel2).style.display).toBe 'none'
it "adds the 'modal' class to panels", -> it "adds the 'modal' class to panels", ->
panel1 = new Panel({viewRegistry, item: new TestPanelContainerItem()}) panel1 = new Panel({item: new TestPanelContainerItem()})
container.addPanel(panel1) container.addPanel(panel1)
expect(panel1.getView()).toHaveClass 'modal' expect(atom.views.getView(panel1)).toHaveClass 'modal'
# legacy selector support # legacy selector support
expect(panel1.getView()).not.toHaveClass 'tool-panel' expect(atom.views.getView(panel1)).not.toHaveClass 'tool-panel'
expect(panel1.getView()).toHaveClass 'overlay' expect(atom.views.getView(panel1)).toHaveClass 'overlay'
expect(panel1.getView()).toHaveClass 'from-top' expect(atom.views.getView(panel1)).toHaveClass 'from-top'
+4 -6
Ver Arquivo
@@ -1,16 +1,14 @@
ViewRegistry = require '../src/view-registry'
Panel = require '../src/panel' Panel = require '../src/panel'
PanelContainer = require '../src/panel-container' PanelContainer = require '../src/panel-container'
describe "PanelContainer", -> describe "PanelContainer", ->
[container, viewRegistry] = [] [container] = []
class TestPanelItem class TestPanelItem
constructior: -> constructior: ->
beforeEach -> beforeEach ->
viewRegistry = new ViewRegistry container = new PanelContainer
container = new PanelContainer({viewRegistry})
describe "::addPanel(panel)", -> describe "::addPanel(panel)", ->
it 'emits an onDidAddPanel event with the index the panel was inserted at', -> it 'emits an onDidAddPanel event with the index the panel was inserted at', ->
@@ -46,7 +44,7 @@ describe "PanelContainer", ->
[initialPanel] = [] [initialPanel] = []
beforeEach -> beforeEach ->
# 'left' logic is the same as 'top' # 'left' logic is the same as 'top'
container = new PanelContainer({viewRegistry, location: 'left'}) container = new PanelContainer({location: 'left'})
initialPanel = new Panel(item: new TestPanelItem()) initialPanel = new Panel(item: new TestPanelItem())
container.addPanel(initialPanel) container.addPanel(initialPanel)
@@ -75,7 +73,7 @@ describe "PanelContainer", ->
[initialPanel] = [] [initialPanel] = []
beforeEach -> beforeEach ->
# 'bottom' logic is the same as 'right' # 'bottom' logic is the same as 'right'
container = new PanelContainer({viewRegistry, location: 'right'}) container = new PanelContainer({location: 'right'})
initialPanel = new Panel(item: new TestPanelItem()) initialPanel = new Panel(item: new TestPanelItem())
container.addPanel(initialPanel) container.addPanel(initialPanel)
+11 -13
Ver Arquivo
@@ -1,9 +1,8 @@
ViewRegistry = require '../src/view-registry'
Panel = require '../src/panel' Panel = require '../src/panel'
PanelElement = require '../src/panel-element' PanelElement = require '../src/panel-element'
describe "PanelElement", -> describe "PanelElement", ->
[jasmineContent, element, panel, viewRegistry] = [] [jasmineContent, element, panel] = []
class TestPanelItem class TestPanelItem
constructior: -> constructior: ->
@@ -17,17 +16,16 @@ describe "PanelElement", ->
beforeEach -> beforeEach ->
jasmineContent = document.body.querySelector('#jasmine-content') jasmineContent = document.body.querySelector('#jasmine-content')
viewRegistry = new ViewRegistry atom.views.addViewProvider
viewRegistry.addViewProvider
modelConstructor: Panel modelConstructor: Panel
viewConstructor: PanelElement viewConstructor: PanelElement
viewRegistry.addViewProvider atom.views.addViewProvider
modelConstructor: TestPanelItem modelConstructor: TestPanelItem
viewConstructor: TestPanelItemElement viewConstructor: TestPanelItemElement
it 'removes the element when the panel is destroyed', -> it 'removes the element when the panel is destroyed', ->
panel = new Panel({viewRegistry, item: new TestPanelItem}) panel = new Panel({item: new TestPanelItem})
element = panel.getView() element = atom.views.getView(panel)
jasmineContent.appendChild(element) jasmineContent.appendChild(element)
expect(element.parentNode).toBe jasmineContent expect(element.parentNode).toBe jasmineContent
@@ -36,15 +34,15 @@ describe "PanelElement", ->
describe "changing panel visibility", -> describe "changing panel visibility", ->
it 'initially renders panel created with visibile: false', -> it 'initially renders panel created with visibile: false', ->
panel = new Panel({viewRegistry, visible: false, item: new TestPanelItem}) panel = new Panel({visible: false, item: new TestPanelItem})
element = panel.getView() element = atom.views.getView(panel)
jasmineContent.appendChild(element) jasmineContent.appendChild(element)
expect(element.style.display).toBe 'none' expect(element.style.display).toBe 'none'
it 'hides and shows the panel element when Panel::hide() and Panel::show() are called', -> it 'hides and shows the panel element when Panel::hide() and Panel::show() are called', ->
panel = new Panel({viewRegistry, item: new TestPanelItem}) panel = new Panel({item: new TestPanelItem})
element = panel.getView() element = atom.views.getView(panel)
jasmineContent.appendChild(element) jasmineContent.appendChild(element)
expect(element.style.display).not.toBe 'none' expect(element.style.display).not.toBe 'none'
@@ -57,8 +55,8 @@ describe "PanelElement", ->
describe "when a class name is specified", -> describe "when a class name is specified", ->
it 'initially renders panel created with visibile: false', -> it 'initially renders panel created with visibile: false', ->
panel = new Panel({viewRegistry, className: 'some classes', item: new TestPanelItem}) panel = new Panel({className: 'some classes', item: new TestPanelItem})
element = panel.getView() element = atom.views.getView(panel)
jasmineContent.appendChild(element) jasmineContent.appendChild(element)
expect(element).toHaveClass 'some' expect(element).toHaveClass 'some'
+5 -5
Ver Arquivo
@@ -482,7 +482,7 @@ describe "Workspace", ->
expect(panel).toBeDefined() expect(panel).toBeDefined()
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0}) expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
itemView = atom.workspace.getLeftPanels()[0].getItemView() itemView = atom.views.getView(atom.workspace.getLeftPanels()[0].getItem())
expect(itemView instanceof TestItemElement).toBe(true) expect(itemView instanceof TestItemElement).toBe(true)
expect(itemView.getModel()).toBe(model) expect(itemView.getModel()).toBe(model)
@@ -497,7 +497,7 @@ describe "Workspace", ->
expect(panel).toBeDefined() expect(panel).toBeDefined()
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0}) expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
itemView = atom.workspace.getRightPanels()[0].getItemView() itemView = atom.views.getView(atom.workspace.getRightPanels()[0].getItem())
expect(itemView instanceof TestItemElement).toBe(true) expect(itemView instanceof TestItemElement).toBe(true)
expect(itemView.getModel()).toBe(model) expect(itemView.getModel()).toBe(model)
@@ -512,7 +512,7 @@ describe "Workspace", ->
expect(panel).toBeDefined() expect(panel).toBeDefined()
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0}) expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
itemView = atom.workspace.getTopPanels()[0].getItemView() itemView = atom.views.getView(atom.workspace.getTopPanels()[0].getItem())
expect(itemView instanceof TestItemElement).toBe(true) expect(itemView instanceof TestItemElement).toBe(true)
expect(itemView.getModel()).toBe(model) expect(itemView.getModel()).toBe(model)
@@ -527,7 +527,7 @@ describe "Workspace", ->
expect(panel).toBeDefined() expect(panel).toBeDefined()
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0}) expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
itemView = atom.workspace.getBottomPanels()[0].getItemView() itemView = atom.views.getView(atom.workspace.getBottomPanels()[0].getItem())
expect(itemView instanceof TestItemElement).toBe(true) expect(itemView instanceof TestItemElement).toBe(true)
expect(itemView.getModel()).toBe(model) expect(itemView.getModel()).toBe(model)
@@ -542,6 +542,6 @@ describe "Workspace", ->
expect(panel).toBeDefined() expect(panel).toBeDefined()
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0}) expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
itemView = atom.workspace.getModalPanels()[0].getItemView() itemView = atom.views.getView(atom.workspace.getModalPanels()[0].getItem())
expect(itemView instanceof TestItemElement).toBe(true) expect(itemView instanceof TestItemElement).toBe(true)
expect(itemView.getModel()).toBe(model) expect(itemView.getModel()).toBe(model)
+2 -2
Ver Arquivo
@@ -22,12 +22,12 @@ class PaneAxisElement extends HTMLElement
@classList.add('vertical', 'pane-column') @classList.add('vertical', 'pane-column')
childAdded: ({child, index}) -> childAdded: ({child, index}) ->
view = @model.getView(child) view = atom.views.getView(child)
@insertBefore(view, @children[index]) @insertBefore(view, @children[index])
callAttachHooks(view) # for backward compatibility with SpacePen views callAttachHooks(view) # for backward compatibility with SpacePen views
childRemoved: ({child}) -> childRemoved: ({child}) ->
view = @model.getView(child) view = atom.views.getView(child)
view.remove() view.remove()
childReplaced: ({index, oldChild, newChild}) -> childReplaced: ({index, oldChild, newChild}) ->
-3
Ver Arquivo
@@ -39,9 +39,6 @@ class PaneAxis extends Model
getOrientation: -> @orientation getOrientation: -> @orientation
getView: (object) ->
@container.getView(object)
getChildren: -> @children.slice() getChildren: -> @children.slice()
getPanes: -> getPanes: ->
+2 -2
Ver Arquivo
@@ -19,7 +19,7 @@ class PaneContainerElement extends HTMLElement
focusedElement = document.activeElement if @hasFocus() focusedElement = document.activeElement if @hasFocus()
@firstChild?.remove() @firstChild?.remove()
if root? if root?
view = @model.getView(root) view = atom.views.getView(root)
@appendChild(view) @appendChild(view)
callAttachHooks(view) callAttachHooks(view)
focusedElement?.focus() focusedElement?.focus()
@@ -45,7 +45,7 @@ class PaneContainerElement extends HTMLElement
y = pointB.y - pointA.y y = pointB.y - pointA.y
Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))
paneView = @model.getView(@model.getActivePane()) paneView = atom.views.getView(@model.getActivePane())
box = @boundingBoxForPaneView(paneView) box = @boundingBoxForPaneView(paneView)
paneViews = _.toArray(@querySelectorAll('atom-pane')) paneViews = _.toArray(@querySelectorAll('atom-pane'))
+3 -3
Ver Arquivo
@@ -23,7 +23,7 @@ class PaneContainerView extends View
@subscriptions.add @model.onDidChangeActivePaneItem(@onActivePaneItemChanged) @subscriptions.add @model.onDidChangeActivePaneItem(@onActivePaneItemChanged)
getRoot: -> getRoot: ->
view = @model.getView(@model.getRoot()) view = atom.views.getView(@model.getRoot())
view.__spacePenView ? view view.__spacePenView ? view
onActivePaneItemChanged: (activeItem) => onActivePaneItemChanged: (activeItem) =>
@@ -55,7 +55,7 @@ class PaneContainerView extends View
@getActivePaneView() @getActivePaneView()
getActivePaneView: -> getActivePaneView: ->
@model.getView(@model.getActivePane()).__spacePenView atom.views.getView(@model.getActivePane()).__spacePenView
getActivePaneItem: -> getActivePaneItem: ->
@model.getActivePaneItem() @model.getActivePaneItem()
@@ -64,7 +64,7 @@ class PaneContainerView extends View
@getActivePaneView()?.activeView @getActivePaneView()?.activeView
paneForUri: (uri) -> paneForUri: (uri) ->
@model.getView(@model.paneForUri(uri)).__spacePenView atom.views.getView(@model.paneForUri(uri)).__spacePenView
focusNextPaneView: -> focusNextPaneView: ->
@model.activateNextPane() @model.activateNextPane()
+4 -9
Ver Arquivo
@@ -9,7 +9,6 @@ PaneAxisElement = require './pane-axis-element'
PaneAxis = require './pane-axis' PaneAxis = require './pane-axis'
TextEditor = require './text-editor' TextEditor = require './text-editor'
TextEditorElement = require './text-editor-element' TextEditorElement = require './text-editor-element'
ViewRegistry = require './view-registry'
ItemRegistry = require './item-registry' ItemRegistry = require './item-registry'
module.exports = module.exports =
@@ -36,7 +35,6 @@ class PaneContainer extends Model
@subscriptions = new CompositeDisposable @subscriptions = new CompositeDisposable
@itemRegistry = new ItemRegistry @itemRegistry = new ItemRegistry
@viewRegistry = params?.viewRegistry ? new ViewRegistry
@registerViewProviders() @registerViewProviders()
@setRoot(params?.root ? new Pane) @setRoot(params?.root ? new Pane)
@@ -58,25 +56,22 @@ class PaneContainer extends Model
activePaneId: @activePane.id activePaneId: @activePane.id
registerViewProviders: -> registerViewProviders: ->
@viewRegistry.addViewProvider atom.views.addViewProvider
modelConstructor: PaneContainer modelConstructor: PaneContainer
viewConstructor: PaneContainerElement viewConstructor: PaneContainerElement
@viewRegistry.addViewProvider atom.views.addViewProvider
modelConstructor: PaneAxis modelConstructor: PaneAxis
viewConstructor: PaneAxisElement viewConstructor: PaneAxisElement
@viewRegistry.addViewProvider atom.views.addViewProvider
modelConstructor: Pane modelConstructor: Pane
viewConstructor: PaneElement viewConstructor: PaneElement
@viewRegistry.addViewProvider atom.views.addViewProvider
modelConstructor: TextEditor modelConstructor: TextEditor
viewConstructor: TextEditorElement viewConstructor: TextEditorElement
getView: (object) ->
@viewRegistry.getView(object)
onDidChangeRoot: (fn) -> onDidChangeRoot: (fn) ->
@emitter.on 'did-change-root', fn @emitter.on 'did-change-root', fn
+3 -3
Ver Arquivo
@@ -66,7 +66,7 @@ class PaneElement extends HTMLElement
return unless item? return unless item?
hasFocus = @hasFocus() hasFocus = @hasFocus()
itemView = @model.getView(item) itemView = atom.views.getView(item)
unless @itemViews.contains(itemView) unless @itemViews.contains(itemView)
@itemViews.appendChild(itemView) @itemViews.appendChild(itemView)
@@ -94,14 +94,14 @@ class PaneElement extends HTMLElement
itemView.style.display = 'none' itemView.style.display = 'none'
itemRemoved: ({item, index, destroyed}) -> itemRemoved: ({item, index, destroyed}) ->
if viewToRemove = @model.getView(item) if viewToRemove = atom.views.getView(item)
callRemoveHooks(viewToRemove) if destroyed callRemoveHooks(viewToRemove) if destroyed
viewToRemove.remove() viewToRemove.remove()
paneDestroyed: -> paneDestroyed: ->
@subscriptions.dispose() @subscriptions.dispose()
getActiveView: -> @model.getView(@model.getActiveItem()) getActiveView: -> atom.views.getView(@model.getActiveItem())
hasFocus: -> hasFocus: ->
this is document.activeElement or @contains(document.activeElement) this is document.activeElement or @contains(document.activeElement)
+5 -5
Ver Arquivo
@@ -153,15 +153,15 @@ class PaneView extends View
activeItemModifiedChanged: => activeItemModifiedChanged: =>
@trigger 'pane:active-item-modified-status-changed' @trigger 'pane:active-item-modified-status-changed'
@::accessor 'activeView', -> @model.getView(@activeItem)?.__spacePenView @::accessor 'activeView', -> atom.views.getView(@activeItem)?.__spacePenView
splitLeft: (items...) -> @model.getView(@model.splitLeft({items})).__spacePenView splitLeft: (items...) -> atom.views.getView(@model.splitLeft({items})).__spacePenView
splitRight: (items...) -> @model.getView(@model.splitRight({items})).__spacePenView splitRight: (items...) -> atom.views.getView(@model.splitRight({items})).__spacePenView
splitUp: (items...) -> @model.getView(@model.splitUp({items})).__spacePenView splitUp: (items...) -> atom.views.getView(@model.splitUp({items})).__spacePenView
splitDown: (items...) -> @model.getView(@model.splitDown({items})).__spacePenView splitDown: (items...) -> atom.views.getView(@model.splitDown({items})).__spacePenView
getContainer: -> @closest('atom-pane-container').view() getContainer: -> @closest('atom-pane-container').view()
-3
Ver Arquivo
@@ -53,9 +53,6 @@ class Pane extends Model
params.activeItem = find params.items, (item) -> item.getUri?() is activeItemUri params.activeItem = find params.items, (item) -> item.getUri?() is activeItemUri
params params
getView: (object) ->
@container.getView(object)
getParent: -> @parent getParent: -> @parent
setParent: (@parent) -> @parent setParent: (@parent) -> @parent
+2 -2
Ver Arquivo
@@ -13,7 +13,7 @@ class PanelContainerElement extends HTMLElement
@classList.add(@model.getLocation()) @classList.add(@model.getLocation())
panelAdded: ({panel, index}) -> panelAdded: ({panel, index}) ->
panelElement = panel.getView() panelElement = atom.views.getView(panel)
panelElement.classList.add(@model.getLocation()) panelElement.classList.add(@model.getLocation())
if @model.isModal() if @model.isModal()
panelElement.classList.add("overlay", "from-top") panelElement.classList.add("overlay", "from-top")
@@ -32,7 +32,7 @@ class PanelContainerElement extends HTMLElement
@hideAllPanelsExcept(panel) if visible @hideAllPanelsExcept(panel) if visible
panelRemoved: ({panel, index}) -> panelRemoved: ({panel, index}) ->
@removeChild(panel.getView()) @removeChild(atom.views.getView(panel))
destroyed: -> destroyed: ->
@subscriptions.dispose() @subscriptions.dispose()
+1 -3
Ver Arquivo
@@ -2,7 +2,7 @@
module.exports = module.exports =
class PanelContainer class PanelContainer
constructor: ({@viewRegistry, @location}) -> constructor: ({@location}={}) ->
@emitter = new Emitter @emitter = new Emitter
@subscriptions = new CompositeDisposable @subscriptions = new CompositeDisposable
@panels = [] @panels = []
@@ -30,8 +30,6 @@ class PanelContainer
Section: Panels Section: Panels
### ###
getView: -> @viewRegistry.getView(this)
getLocation: -> @location getLocation: -> @location
isModal: -> @location is 'modal' isModal: -> @location is 'modal'
+5 -3
Ver Arquivo
@@ -8,15 +8,17 @@ class PanelElement extends HTMLElement
getModel: -> @model getModel: -> @model
setModel: (@model) -> setModel: (@model) ->
view = @model.getItemView() @appendChild(@getItemView())
@appendChild(view)
@classList.add(@model.getClassName().split(' ')...) if @model.getClassName()? @classList.add(@model.getClassName().split(' ')...) if @model.getClassName()?
@subscriptions.add @model.onDidChangeVisible(@visibleChanged.bind(this)) @subscriptions.add @model.onDidChangeVisible(@visibleChanged.bind(this))
@subscriptions.add @model.onDidDestroy(@destroyed.bind(this)) @subscriptions.add @model.onDidDestroy(@destroyed.bind(this))
getItemView: ->
atom.views.getView(@model.getItem())
attachedCallback: -> attachedCallback: ->
callAttachHooks(@model.getItemView()) # for backward compatibility with SpacePen views callAttachHooks(@getItemView()) # for backward compatibility with SpacePen views
@visibleChanged(@model.isVisible()) @visibleChanged(@model.isVisible())
visibleChanged: (visible) -> visibleChanged: (visible) ->
+3 -10
Ver Arquivo
@@ -14,7 +14,7 @@ class Panel
Section: Construction and Destruction Section: Construction and Destruction
### ###
constructor: ({@viewRegistry, @item, @visible, @priority, @className}) -> constructor: ({@item, @visible, @priority, @className}) ->
@emitter = new Emitter @emitter = new Emitter
@visible ?= true @visible ?= true
@priority ?= 100 @priority ?= 100
@@ -50,15 +50,8 @@ class Panel
Section: Panel Details Section: Panel Details
### ###
# Public: Gets this panel model's view DOM node. # Public: Returns the panel's item.
# getItem: -> @item
# Returns an `<atom-panel>` {Element}
getView: -> @viewRegistry.getView(this)
# Public: Gets your panel contents view.
#
# Returns an {Element} or jQuery element, depeneding on how you created the panel.
getItemView: -> @viewRegistry.getView(@item)
# Public: Returns a {Number} indicating this panel's priority. # Public: Returns a {Number} indicating this panel's priority.
getPriority: -> @priority getPriority: -> @priority
+5 -5
Ver Arquivo
@@ -70,11 +70,11 @@ class WorkspaceElement extends HTMLElement
@addEventListener 'focus', @handleFocus.bind(this) @addEventListener 'focus', @handleFocus.bind(this)
@panelContainers = @panelContainers =
top: @model.panelContainers.top.getView() top: atom.views.getView(@model.panelContainers.top)
left: @model.panelContainers.left.getView() left: atom.views.getView(@model.panelContainers.left)
right: @model.panelContainers.right.getView() right: atom.views.getView(@model.panelContainers.right)
bottom: @model.panelContainers.bottom.getView() bottom: atom.views.getView(@model.panelContainers.bottom)
modal: @model.panelContainers.modal.getView() modal: atom.views.getView(@model.panelContainers.modal)
@horizontalAxis.insertBefore(@panelContainers.left, @verticalAxis) @horizontalAxis.insertBefore(@panelContainers.left, @verticalAxis)
@horizontalAxis.appendChild(@panelContainers.right) @horizontalAxis.appendChild(@panelContainers.right)
+6 -11
Ver Arquivo
@@ -14,7 +14,6 @@ Panel = require './panel'
PanelElement = require './panel-element' PanelElement = require './panel-element'
PanelContainer = require './panel-container' PanelContainer = require './panel-container'
PanelContainerElement = require './panel-container-element' PanelContainerElement = require './panel-container-element'
ViewRegistry = require './view-registry'
WorkspaceElement = require './workspace-element' WorkspaceElement = require './workspace-element'
# Essential: Represents the state of the user interface for the entire window. # Essential: Represents the state of the user interface for the entire window.
@@ -34,7 +33,6 @@ class Workspace extends Model
@delegatesProperty 'activePane', 'activePaneItem', toProperty: 'paneContainer' @delegatesProperty 'activePane', 'activePaneItem', toProperty: 'paneContainer'
@properties @properties
viewRegistry: null
paneContainer: null paneContainer: null
fullScreen: false fullScreen: false
destroyedItemUris: -> [] destroyedItemUris: -> []
@@ -45,16 +43,15 @@ class Workspace extends Model
@emitter = new Emitter @emitter = new Emitter
@openers = [] @openers = []
viewRegistry = atom.views @paneContainer ?= new PaneContainer()
@paneContainer ?= new PaneContainer({viewRegistry})
@paneContainer.onDidDestroyPaneItem(@didDestroyPaneItem) @paneContainer.onDidDestroyPaneItem(@didDestroyPaneItem)
@panelContainers = @panelContainers =
top: new PanelContainer({viewRegistry, location: 'top'}) top: new PanelContainer({location: 'top'})
left: new PanelContainer({viewRegistry, location: 'left'}) left: new PanelContainer({location: 'left'})
right: new PanelContainer({viewRegistry, location: 'right'}) right: new PanelContainer({location: 'right'})
bottom: new PanelContainer({viewRegistry, location: 'bottom'}) bottom: new PanelContainer({location: 'bottom'})
modal: new PanelContainer({viewRegistry, location: 'modal'}) modal: new PanelContainer({location: 'modal'})
@subscribeToActiveItem() @subscribeToActiveItem()
@@ -86,7 +83,6 @@ 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.paneContainer.viewRegistry = atom.views
params.paneContainer = PaneContainer.deserialize(params.paneContainer) params.paneContainer = PaneContainer.deserialize(params.paneContainer)
params params
@@ -732,5 +728,4 @@ class Workspace extends Model
addPanel: (location, options) -> addPanel: (location, options) ->
options ?= {} options ?= {}
options.viewRegistry = atom.views
@panelContainers[location].addPanel(new Panel(options)) @panelContainers[location].addPanel(new Panel(options))