-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpane-container.coffee
94 lines (72 loc) · 2.2 KB
/
pane-container.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{find} = require 'underscore-plus'
{Model} = require 'theorist'
Serializable = require 'serializable'
Pane = require './pane'
module.exports =
class PaneContainer extends Model
atom.deserializers.add(this)
Serializable.includeInto(this)
@properties
root: -> new Pane
activePane: null
previousRoot: null
@behavior 'activePaneItem', ->
@$activePane
.switch((activePane) -> activePane?.$activeItem)
.distinctUntilChanged()
constructor: (params) ->
super
@subscribe @$root, @onRootChanged
@destroyEmptyPanes() if params?.destroyEmptyPanes
deserializeParams: (params) ->
params.root = atom.deserializers.deserialize(params.root, container: this)
params.destroyEmptyPanes = atom.config.get('core.destroyEmptyPanes')
params
serializeParams: (params) ->
root: @root?.serialize()
replaceChild: (oldChild, newChild) ->
throw new Error("Replacing non-existent child") if oldChild isnt @root
@root = newChild
getPanes: ->
@root?.getPanes() ? []
getActivePane: ->
@activePane
paneForUri: (uri) ->
find @getPanes(), (pane) -> pane.itemForUri(uri)?
saveAll: ->
pane.saveItems() for pane in @getPanes()
activateNextPane: ->
panes = @getPanes()
if panes.length > 1
currentIndex = panes.indexOf(@activePane)
nextIndex = (currentIndex + 1) % panes.length
panes[nextIndex].activate()
true
else
false
activatePreviousPane: ->
panes = @getPanes()
if panes.length > 1
currentIndex = panes.indexOf(@activePane)
previousIndex = currentIndex - 1
previousIndex = panes.length - 1 if previousIndex < 0
panes[previousIndex].activate()
true
else
false
onRootChanged: (root) =>
@unsubscribe(@previousRoot) if @previousRoot?
@previousRoot = root
unless root?
@activePane = null
return
root.parent = this
root.container = this
@activePane ?= root if root instanceof Pane
destroyEmptyPanes: ->
pane.destroy() for pane in @getPanes() when pane.items.length is 0
itemDestroyed: (item) ->
@emit 'item-destroyed', item
# Called by Model superclass when destroyed
destroyed: ->
pane.destroy() for pane in @getPanes()