Class: Redcar::Treebook

Inherits:
Object show all
Includes:
Model, Observable
Defined in:
plugins/application/lib/application/treebook.rb

Constant Summary

Constant Summary

Constants included from Observable

Observable::ASPECTS

Instance Attribute Summary (collapse)

Attributes included from Model

#controller

Instance Method Summary (collapse)

Methods included from ReentryHelpers

#ignore, #ignore_changes

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

Parameters:



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

Parameters:



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