Sha256: b52e4da624acecb0f80e0277c11168eecab30a64dc07c2c4a795184ec33a77af

Contents?: true

Size: 1.05 KB

Versions: 25

Compression:

Stored size: 1.05 KB

Contents

module Redcar
  class Treebook
    include Redcar::Observable
    include Redcar::Model
    
    attr_reader :trees, :focussed_tree
    
    def initialize
      @trees = []
      @focussed_tree = nil
    end
    
    # Add a tree to this treebook
    #
    # @param [Redcar::Tree]
    def add_tree(tree)
      @trees << tree
      @focussed_tree = tree
      notify_listeners(:tree_added, tree)
    end
    
    # Bring the tree to the front
    #
    # @param [Redcar::Tree]
    def focus_tree(tree)
      @focussed_tree = tree
      notify_listeners(:tree_focussed, tree)
    end
    
    # Remove a tree from this treebook
    #
    # @param [Redcar::Tree]
    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
      end
    end
    
    private
    
    # Tell the Treebook that this tree has been focussed in the GUI.
    def set_focussed_tree(tree)
      @focussed_tree = tree
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
redcar-0.8.1 plugins/application/lib/application/treebook.rb
redcar-0.8 plugins/application/lib/application/treebook.rb
redcar-0.7 plugins/application/lib/application/treebook.rb
redcar-0.6.1 plugins/application/lib/application/treebook.rb
redcar-0.6 plugins/application/lib/application/treebook.rb
redcar-0.6.1dev plugins/application/lib/application/treebook.rb
redcar-0.5.1 plugins/application/lib/application/treebook.rb
redcar-0.5 plugins/application/lib/application/treebook.rb
redcar-0.5.6dev plugins/application/lib/application/treebook.rb
redcar-0.5.5dev plugins/application/lib/application/treebook.rb
redcar-0.5.4dev plugins/application/lib/application/treebook.rb
redcar-0.5.3dev plugins/application/lib/application/treebook.rb
redcar-0.5.2dev plugins/application/lib/application/treebook.rb
redcar-0.5.1dev plugins/application/lib/application/treebook.rb
redcar-0.4.1 plugins/application/lib/application/treebook.rb
redcar-0.4 plugins/application/lib/application/treebook.rb
redcar-0.3.10.1dev plugins/application/lib/application/treebook.rb
redcar-0.3.10.0dev plugins/application/lib/application/treebook.rb
redcar-0.3.9 plugins/application/lib/application/treebook.rb
redcar-0.3.9.0dev plugins/application/lib/application/treebook.rb