diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 2003277b7..2482d6334 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -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 diff --git a/src/panel-container.coffee b/src/panel-container.coffee index b22c001a4..322773f69 100644 --- a/src/panel-container.coffee +++ b/src/panel-container.coffee @@ -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 diff --git a/src/workspace.coffee b/src/workspace.coffee index 776b6e1f2..42c07cd72 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -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()