Module: ActiveWindow::TreeStoreExtentions
- Included in:
- ActiveTreeStore, FilteredActiveTreeStore
- Defined in:
- lib/active_window/active_tree_store/extentions.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#add(object, parent = nil) ⇒ Object
Add
object
to tree, give optionalparent
. -
#apply_to_tree(treeview, opts = {}) ⇒ Object
associates a Gtk::TreeView widget with self (a tree model).
-
#get_object(iter) ⇒ Object
The original object for
iter
. -
#populate(array) ⇒ Object
Populare the Tree with an array of objects.
-
#refresh(object) ⇒ Object
Updates the display in the tree/list of the given object.
Class Method Details
permalink .included(base) ⇒ Object
[View source]
4 5 6 7 8 9 10 |
# File 'lib/active_window/active_tree_store/extentions.rb', line 4 def self.included(base) base.class_eval do include ActiveSupport::Callbacks include ActiveTreeStoreColumns include ActiveTreeStoreIndex end end |
Instance Method Details
permalink #add(object, parent = nil) ⇒ Object
Add object
to tree, give optional parent
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_window/active_tree_store/extentions.rb', line 39 def add(object, parent=nil) iter = self.append parent case object when Hash update_iter_from_hash iter, object else update_iter_from_object iter, object end iter[ self.class.column_id[:object] ] = object iter end |
permalink #apply_to_tree(treeview, opts = {}) ⇒ Object
associates a Gtk::TreeView widget with self (a tree model).
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/active_window/active_tree_store/extentions.rb', line 12 def apply_to_tree(treeview, opts={}) raise ArgumentError, "please provide a Gtk::TreeView" unless treeview.is_a?(Gtk::TreeView) treeview.model = self cols = self.class.visible_columns cols = cols.except(opts[:except]) if opts.has_key?(:except) cols = cols.slice(opts[:only]) if opts.has_key?(:only) cols.map(&:view).each do |column| treeview.append_column(column) end end |
permalink #get_object(iter) ⇒ Object
The original object for iter
. FIXME remove
33 34 35 36 |
# File 'lib/active_window/active_tree_store/extentions.rb', line 33 def get_object(iter) raise "depricated - please use iter[OBJECT]" iter[ self.class.column_id[:object] ] end |
permalink #populate(array) ⇒ Object
Populare the Tree with an array of objects. The Tree gets cleared first.
24 25 26 27 28 29 |
# File 'lib/active_window/active_tree_store/extentions.rb', line 24 def populate(array) clear array.each do |element| self.add element end end |
permalink #refresh(object) ⇒ Object
Updates the display in the tree/list of the given object
52 53 54 55 56 57 58 59 |
# File 'lib/active_window/active_tree_store/extentions.rb', line 52 def refresh(object) each do |model,path,iter| if iter[OBJECT] == object update_iter_from_object(iter, object) break end end end |