Class: Redcar::Treebook
- Inherits:
-
Object
- Object
- Redcar::Treebook
- Includes:
- Model, Observable
- Defined in:
- plugins/application/lib/application/treebook.rb
Constant Summary
Constant Summary
Constants included from Observable
Instance Attribute Summary (collapse)
-
- (Object) focussed_tree
readonly
Returns the value of attribute focussed_tree.
-
- (Object) trees
readonly
Returns the value of attribute trees.
Attributes included from Model
Instance Method Summary (collapse)
-
- (Object) add_tree(tree)
Add a tree to this treebook.
-
- (Object) focus_tree(tree)
Bring the tree to the front.
-
- (Treebook) initialize
constructor
A new instance of Treebook.
-
- (Object) remove_tree(tree)
Remove a tree from this treebook.
- - (Object) switch_down
- - (Object) switch_up
Methods included from ReentryHelpers
Methods included from Observable
#add_listener, #notify_listeners, #remove_listener
Constructor Details
- (Treebook) initialize
A new instance of Treebook
8 9 10 11 |
# File 'plugins/application/lib/application/treebook.rb', line 8 def initialize @trees = [] @focussed_tree = nil end |
Instance Attribute Details
- (Object) focussed_tree (readonly)
Returns the value of attribute focussed_tree
6 7 8 |
# File 'plugins/application/lib/application/treebook.rb', line 6 def focussed_tree @focussed_tree end |
- (Object) trees (readonly)
Returns the value of attribute trees
6 7 8 |
# File 'plugins/application/lib/application/treebook.rb', line 6 def trees @trees end |
Instance Method Details
- (Object) add_tree(tree)
Add a tree to this treebook
@param [Redcar::Tree]
16 17 18 19 20 21 22 |
# File 'plugins/application/lib/application/treebook.rb', line 16 def add_tree(tree) @trees << tree @focussed_tree = tree notify_listeners(:tree_added, tree) tree.focus Redcar.app.repeat_event(:tree_added) if Redcar.app end |
- (Object) focus_tree(tree)
Bring the tree to the front
27 28 29 30 31 32 |
# File 'plugins/application/lib/application/treebook.rb', line 27 def focus_tree(tree) return if @focussed_tree == tree @focussed_tree = tree notify_listeners(:tree_focussed, tree) tree.focus end |
- (Object) remove_tree(tree)
Remove a tree from this treebook
37 38 39 40 41 42 43 44 45 46 |
# File 'plugins/application/lib/application/treebook.rb', line 37 def remove_tree(tree) if @trees.include?(tree) @trees.delete(tree) notify_listeners(:tree_removed, tree) if tree == focussed_tree focus_tree(trees.first) if trees.any? end Redcar.app.repeat_event(:tree_removed) if Redcar.app end end |
- (Object) switch_down
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'plugins/application/lib/application/treebook.rb', line 48 def switch_down if @trees.any? if @focussed_tree index = @trees.index @focussed_tree else index = -1 end new_tree_index = index + 1 new_tree_index = 0 if new_tree_index < 0 or new_tree_index >= @trees.size tree = @trees[new_tree_index] focus_tree(tree) if tree end end |
- (Object) switch_up
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'plugins/application/lib/application/treebook.rb', line 62 def switch_up if @trees.any? if @focussed_tree index = @trees.index @focussed_tree else index = 1 end new_tree_index = index - 1 new_tree_index = @trees.size - 1 if new_tree_index < 0 or new_tree_index >= @trees.size tree = @trees[new_tree_index] focus_tree(tree) if tree end end |