Merge pull request #4390 from atom/bo-panel-for-item

Add Workspace::panelForItem()
This commit is contained in:
Ben Ogle
2014-12-03 14:15:33 -08:00
3 changed files with 25 additions and 0 deletions

View File

@@ -543,3 +543,13 @@ describe "Workspace", ->
itemView = atom.views.getView(atom.workspace.getModalPanels()[0].getItem())
expect(itemView instanceof TestItemElement).toBe(true)
expect(itemView.getModel()).toBe(model)
describe "::panelForItem(item)", ->
it "returns the panel associated with the item", ->
item = new TestItem
panel = atom.workspace.addLeftPanel(item: item)
itemWithNoPanel = new TestItem
expect(atom.workspace.panelForItem(item)).toBe panel
expect(atom.workspace.panelForItem(itemWithNoPanel)).toBe null

View File

@@ -48,6 +48,11 @@ class PanelContainer
@emitter.emit 'did-add-panel', {panel, index}
panel
panelForItem: (item) ->
for panel in @panels
return panel if panel.getItem() is item
null
panelDestroyed: (panel) ->
index = @panels.indexOf(panel)
if index > -1

View File

@@ -750,6 +750,16 @@ class Workspace extends Model
addModalPanel: (options={}) ->
@addPanel('modal', options)
# Essential: Returns the {Panel} associated with the given item. Returns
# `null` when the item has no panel.
#
# * `item` Item the panel contains
panelForItem: (item) ->
for location, container of @panelContainers
panel = container.panelForItem(item)
return panel if panel?
null
getPanels: (location) ->
@panelContainers[location].getPanels()