mirror of
https://github.com/atom/atom.git
synced 2026-02-19 02:44:29 -05:00
Add priority system to the panels
This commit is contained in:
@@ -38,8 +38,13 @@ class PanelContainer
|
||||
|
||||
addPanel: (panel) ->
|
||||
@subscriptions.add panel.onDidDestroy(@panelDestoryed.bind(this))
|
||||
index = @panels.length
|
||||
@panels.push(panel)
|
||||
|
||||
index = @getPanelIndex(panel)
|
||||
if index is @panels.length
|
||||
@panels.push(panel)
|
||||
else
|
||||
@panels.splice(index, 0, panel)
|
||||
|
||||
@emitter.emit 'did-add-panel', {panel, index}
|
||||
panel
|
||||
|
||||
@@ -48,3 +53,14 @@ class PanelContainer
|
||||
if index > -1
|
||||
@panels.splice(index, 1)
|
||||
@emitter.emit 'did-remove-panel', {panel, index}
|
||||
|
||||
getPanelIndex: (panel) ->
|
||||
priority = panel.getPriority()
|
||||
if @location in ['bottom', 'right']
|
||||
for p, i in @panels by -1
|
||||
return i + 1 if priority < p.getPriority()
|
||||
0
|
||||
else
|
||||
for p, i in @panels
|
||||
return i if priority < p.getPriority()
|
||||
@panels.length
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
# Public:
|
||||
module.exports =
|
||||
class Panel
|
||||
constructor: ({@viewRegistry, @item, @visible}) ->
|
||||
constructor: ({@viewRegistry, @item, @visible, @priority}) ->
|
||||
@emitter = new Emitter
|
||||
@visible ?= true
|
||||
@priority ?= 100
|
||||
|
||||
destroy: ->
|
||||
@emitter.emit 'did-destroy', this
|
||||
@@ -33,6 +34,8 @@ class Panel
|
||||
|
||||
getItemView: -> @viewRegistry.getView(@item)
|
||||
|
||||
getPriority: -> @priority
|
||||
|
||||
isVisible: -> @visible
|
||||
|
||||
hide: ->
|
||||
|
||||
Reference in New Issue
Block a user