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
.included(base) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/active_window/active_tree_store/extentions.rb', line 5 def self.included(base) base.class_eval do include ActiveSupport::Callbacks include ActiveTreeStoreColumns include ActiveTreeStoreIndex end end |
Instance Method Details
#add(object, parent = nil) ⇒ Object
Add object
to tree, give optional parent
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/active_window/active_tree_store/extentions.rb', line 40 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 |
#apply_to_tree(treeview, opts = {}) ⇒ Object
associates a Gtk::TreeView widget with self (a tree model).
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/active_window/active_tree_store/extentions.rb', line 13 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 |
#get_object(iter) ⇒ Object
The original object for iter
. FIXME remove
34 35 36 37 |
# File 'lib/active_window/active_tree_store/extentions.rb', line 34 def get_object(iter) raise "depricated - please use iter[OBJECT]" iter[ self.class.column_id[:object] ] end |
#populate(array) ⇒ Object
Populare the Tree with an array of objects. The Tree gets cleared first.
25 26 27 28 29 30 |
# File 'lib/active_window/active_tree_store/extentions.rb', line 25 def populate(array) clear array.each do |element| self.add element end end |
#refresh(object) ⇒ Object
Updates the display in the tree/list of the given object
53 54 55 56 57 58 59 60 |
# File 'lib/active_window/active_tree_store/extentions.rb', line 53 def refresh(object) each do |model,path,iter| if iter[OBJECT] == object update_iter_from_object(iter, object) break end end end |