Class: VR::ListView

Inherits:
Gtk::TreeView
  • Object
show all
Includes:
ViewCommon
Defined in:
lib/treeview/ListView.rb

Instance Attribute Summary

Attributes included from ViewCommon

#column_keys, #vr_cols, #vr_column, #vr_id, #vr_renderer

Instance Method Summary collapse

Methods included from ViewCommon

#add_column, #add_renderer_to_col, #col_attr, #column, #delete_selected, #each_cell_method, #each_renderer, #each_row, #flatten_hash, #get_iter, #id, #initialize, #method_missing, #ren_attr, #renderer, #selected_rows, #turn_on_comboboxes, #vr_row

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class VR::ViewCommon

Instance Method Details

#[](row, col) ⇒ Object

:nodoc:



75
76
77
# File 'lib/treeview/ListView.rb', line 75

def []( row )  # :nodoc:
  model.get_iter(Gtk::TreePath.new("#{row}"))
end

#add_active_record_rows(ar) ⇒ Object

:nodoc:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/treeview/ListView.rb', line 58

def add_active_record_rows(ar) # :nodoc:
  fields = ar.column_names.map { |x| x.to_sym }
  matches = fields & @column_keys #intersection
  ar.each do |obj|
    row = add_row()
    matches.each do |f|
#          begin  
        row[f] = obj[f] unless obj[f].nil?
#          rescue
#            row[f] = obj[f].to_s
#          end
    end          
  end
  self.visible = true
end

#add_row(hash = {}) ⇒ Object

This will add a row to the data model, and fill-in the values from a Hash. This example would add a row to the model and set the name and email fields:

@view.add_row(:name => “Chester”, :email => “chester@chester.com”)

  • hash: A ruby Hash object with pairs of column IDs (symbols) and values.



102
103
104
105
106
# File 'lib/treeview/ListView.rb', line 102

def add_row(hash = {})
  row = vr_row(model.append)
  hash.each_pair { |key, val| row[key] = val }
  return row
end

#select_row(row_number = 0) ⇒ Object

This method will select a given row number. The row will be hilighted, and the GtkSelection object will point to that row. It uses the GtkTreeView#set_cursor method to move the cursor to the specified row.

  • row_number: Integer (FixNum)



90
91
92
# File 'lib/treeview/ListView.rb', line 90

def select_row(row_number = 0)
  set_cursor(Gtk::TreePath.new(row_number), nil, false)
end