Class: Redcar::Tree

Inherits:
Object show all
Includes:
HasSPI, Model, Observable
Defined in:
plugins/application/lib/application/tree.rb,
plugins/application/lib/application/tree/mirror.rb,
plugins/application/lib/application/tree/controller.rb

Overview

Pass classes implementing Redcar::Tree::Mirror and Redcar::Tree::Controller to Tree#new to create a tree. Pass to window.treebook.add_tree to open the Tree in a Window.

Trees build up their contents by querying the Tree::Mirror. For  instance, a simple tree containing the numbers 1 to 10 could be created like this:

class CountMirror 
  include Redcar::Tree::Mirror

  def top
    (1..10).map {|i| CountNode.new(i)}
  end

  class CountNode

    include Redcar::Tree::NodeMirror

    def initialize(i)
      @i = i
    end

    def text
      @i.to_s
    end
  end
end

tree = Tree.new(CountMirror.new)
Redcar.app.focussed_window.treebook.add_tree(tree)

Defined Under Namespace

Modules: Controller, Mirror

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 HasSPI

#assert_interface

Methods included from Observable

#add_listener, #notify_listeners, #remove_listener

Methods included from ReentryHelpers

#ignore, #ignore_changes

Constructor Details

- (Tree) initialize(tree_mirror, tree_controller = nil)

A new instance of Tree

Parameters:



42
43
44
45
46
47
48
49
# File 'plugins/application/lib/application/tree.rb', line 42

def initialize(tree_mirror, tree_controller=nil)
  assert_interface(tree_mirror,     Redcar::Tree::Mirror)
  if tree_controller
    assert_interface(tree_controller, Redcar::Tree::Controller)
  end
  @tree_mirror     = tree_mirror
  @tree_controller = tree_controller
end

Instance Attribute Details

- (Object) tree_controller (readonly)

Returns the value of attribute tree_controller



38
39
40
# File 'plugins/application/lib/application/tree.rb', line 38

def tree_controller
  @tree_controller
end

- (Object) tree_mirror (readonly)

Returns the value of attribute tree_mirror



38
39
40
# File 'plugins/application/lib/application/tree.rb', line 38

def tree_mirror
  @tree_mirror
end

Instance Method Details

- (Object) close

Close the tree (removes it from the Window's Treebook)



89
90
91
# File 'plugins/application/lib/application/tree.rb', line 89

def close
  Redcar.app.windows.detect {|win| win.treebook.trees.include?(self) }.treebook.remove_tree(self)
end

- (Object) edit(node, select_from = nil, select_to = nil)

Begin an edit operation on the node. This allows the user to edit the text. When the user has finished, TreeController#edited will be called with the new text.



60
61
62
# File 'plugins/application/lib/application/tree.rb', line 60

def edit(node, select_from=nil, select_to=nil)
  notify_listeners(:edit_element, node, select_from, select_to)
end

- (Object) expand(node)

Expand the node.



65
66
67
# File 'plugins/application/lib/application/tree.rb', line 65

def expand(node)
  notify_listeners(:expand_element, node)
end

- (Object) focus



74
75
76
# File 'plugins/application/lib/application/tree.rb', line 74

def focus
  notify_listeners(:focus)
end

- (Object) refresh

Refresh the tree by requerying the mirror from the top and recursing down through open items.



53
54
55
# File 'plugins/application/lib/application/tree.rb', line 53

def refresh
  notify_listeners(:refresh)
end

- (Object) select(node)

Select the node.



70
71
72
# File 'plugins/application/lib/application/tree.rb', line 70

def select(node)
  notify_listeners(:select_element, node)
end

- (Array<NodeMirror>) selection

The selected nodes

Returns:

  • (Array<NodeMirror>)

    the selected nodes



79
80
81
# File 'plugins/application/lib/application/tree.rb', line 79

def selection
  controller.selection
end

- (Array<NodeMirror>) visible_nodes

The visible nodes

Returns:

  • (Array<NodeMirror>)

    the visible nodes



84
85
86
# File 'plugins/application/lib/application/tree.rb', line 84

def visible_nodes
  controller.visible_nodes
end