Add priority system to the panels

This commit is contained in:
Ben Ogle
2014-10-17 13:44:40 -07:00
parent b94485eafd
commit de78e53b35
3 changed files with 76 additions and 3 deletions

View File

@@ -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

View File

@@ -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: ->