Merge pull request #4340 from atom/mb-add-panel-getters

Add panel getter methods to workspace
This commit is contained in:
Max Brunsfeld
2014-11-28 10:05:35 -08:00
2 changed files with 75 additions and 7 deletions

View File

@@ -458,45 +458,90 @@ describe "Workspace", ->
expect(atom.setDocumentEdited).toHaveBeenCalledWith(false)
describe "adding panels", ->
class TestPanel
constructior: ->
class TestItem
class TestItemElement extends HTMLElement
constructor: ->
setModel: (@model) ->
getModel: -> @model
beforeEach ->
atom.views.addViewProvider(
modelConstructor: TestItem
viewConstructor: TestItemElement
)
describe '::addLeftPanel(model)', ->
it 'adds a panel to the correct panel container', ->
expect(atom.workspace.getLeftPanels().length).toBe(0)
atom.workspace.panelContainers.left.onDidAddPanel addPanelSpy = jasmine.createSpy()
panel = atom.workspace.addLeftPanel(item: new TestPanel())
model = new TestItem
panel = atom.workspace.addLeftPanel(item: model)
expect(panel).toBeDefined()
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
itemView = atom.workspace.getLeftPanels()[0].getItemView()
expect(itemView instanceof TestItemElement).toBe(true)
expect(itemView.getModel()).toBe(model)
describe '::addRightPanel(model)', ->
it 'adds a panel to the correct panel container', ->
expect(atom.workspace.getRightPanels().length).toBe(0)
atom.workspace.panelContainers.right.onDidAddPanel addPanelSpy = jasmine.createSpy()
panel = atom.workspace.addRightPanel(item: new TestPanel())
model = new TestItem
panel = atom.workspace.addRightPanel(item: model)
expect(panel).toBeDefined()
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
itemView = atom.workspace.getRightPanels()[0].getItemView()
expect(itemView instanceof TestItemElement).toBe(true)
expect(itemView.getModel()).toBe(model)
describe '::addTopPanel(model)', ->
it 'adds a panel to the correct panel container', ->
expect(atom.workspace.getTopPanels().length).toBe(0)
atom.workspace.panelContainers.top.onDidAddPanel addPanelSpy = jasmine.createSpy()
panel = atom.workspace.addTopPanel(item: new TestPanel())
model = new TestItem
panel = atom.workspace.addTopPanel(item: model)
expect(panel).toBeDefined()
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
itemView = atom.workspace.getTopPanels()[0].getItemView()
expect(itemView instanceof TestItemElement).toBe(true)
expect(itemView.getModel()).toBe(model)
describe '::addBottomPanel(model)', ->
it 'adds a panel to the correct panel container', ->
expect(atom.workspace.getBottomPanels().length).toBe(0)
atom.workspace.panelContainers.bottom.onDidAddPanel addPanelSpy = jasmine.createSpy()
panel = atom.workspace.addBottomPanel(item: new TestPanel())
model = new TestItem
panel = atom.workspace.addBottomPanel(item: model)
expect(panel).toBeDefined()
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
itemView = atom.workspace.getBottomPanels()[0].getItemView()
expect(itemView instanceof TestItemElement).toBe(true)
expect(itemView.getModel()).toBe(model)
describe '::addModalPanel(model)', ->
it 'adds a panel to the correct panel container', ->
expect(atom.workspace.getModalPanels().length).toBe(0)
atom.workspace.panelContainers.modal.onDidAddPanel addPanelSpy = jasmine.createSpy()
panel = atom.workspace.addModalPanel(item: new TestPanel())
model = new TestItem
panel = atom.workspace.addModalPanel(item: model)
expect(panel).toBeDefined()
expect(addPanelSpy).toHaveBeenCalledWith({panel, index: 0})
itemView = atom.workspace.getModalPanels()[0].getItemView()
expect(itemView instanceof TestItemElement).toBe(true)
expect(itemView.getModel()).toBe(model)

View File

@@ -609,6 +609,10 @@ class Workspace extends Model
Section: Panels
###
# Essential: Get an {Array} of all the panel items at the bottom of the editor window.
getBottomPanels: ->
@getPanels('bottom')
# Essential: Adds a panel item to the bottom of the editor window.
#
# * `options` {Object}
@@ -624,6 +628,10 @@ class Workspace extends Model
addBottomPanel: (options) ->
@addPanel('bottom', options)
# Essential: Get an {Array} of all the panel items to the left of the editor window.
getLeftPanels: ->
@getPanels('left')
# Essential: Adds a panel item to the left of the editor window.
#
# * `options` {Object}
@@ -639,6 +647,10 @@ class Workspace extends Model
addLeftPanel: (options) ->
@addPanel('left', options)
# Essential: Get an {Array} of all the panel items to the right of the editor window.
getRightPanels: ->
@getPanels('right')
# Essential: Adds a panel item to the right of the editor window.
#
# * `options` {Object}
@@ -654,6 +666,10 @@ class Workspace extends Model
addRightPanel: (options) ->
@addPanel('right', options)
# Essential: Get an {Array} of all the panel items at the top of the editor window.
getTopPanels: ->
@getPanels('top')
# Essential: Adds a panel item to the top of the editor window above the tabs.
#
# * `options` {Object}
@@ -669,6 +685,10 @@ class Workspace extends Model
addTopPanel: (options) ->
@addPanel('top', options)
# Essential: Get an {Array} of all the modal panel items
getModalPanels: ->
@getPanels('modal')
# Essential: Adds a panel item as a modal dialog.
#
# * `options` {Object}
@@ -684,6 +704,9 @@ class Workspace extends Model
addModalPanel: (options={}) ->
@addPanel('modal', options)
getPanels: (location) ->
@panelContainers[location].getPanels()
addPanel: (location, options) ->
options ?= {}
options.viewRegistry = atom.views