mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Merge pull request #4390 from atom/bo-panel-for-item
Add Workspace::panelForItem()
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user