Class: VR::Col::Ren::CellRendererCombo

Inherits:
Gtk::CellRendererCombo
  • Object
show all
Defined in:
lib/treeview/columns/CellRendererCombo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_col, column, view, model_sym) ⇒ CellRendererCombo

:nodoc:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/treeview/columns/CellRendererCombo.rb', line 21

def initialize(model_col, column, view, model_sym) # :nodoc:
  super()
  @model_col = model_col
  @column = column
  @view = view
  @model_sym = model_sym
  @view.model.set_sort_func(@model_col) { |m,x,y| x[@model_col].selected <=> y[@model_col].selected }
  @validate_block = Proc.new { |text, model_sym, row, view | true } 
  self.editable = true
  self.has_entry = false
  @edited_callback = nil
  self.signal_connect('edited') do |ren, path, text| # iter for
    iter = @view.model.get_iter(path)
    if @validate_block.call(text, @model_sym, @view.vr_row(iter), @view)
      iter[@model_col].selected = text 
      @edited_callback.call(@model_sym, @view.vr_row(iter)) if @edited_callback
    end  
  end
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column



19
20
21
# File 'lib/treeview/columns/CellRendererCombo.rb', line 19

def column
  @column
end

#edited_callbackObject

Returns the value of attribute edited_callback



18
19
20
# File 'lib/treeview/columns/CellRendererCombo.rb', line 18

def edited_callback
  @edited_callback
end

#model_colObject (readonly)

Returns the value of attribute model_col



19
20
21
# File 'lib/treeview/columns/CellRendererCombo.rb', line 19

def model_col
  @model_col
end

#model_symObject (readonly)

Returns the value of attribute model_sym



19
20
21
# File 'lib/treeview/columns/CellRendererCombo.rb', line 19

def model_sym
  @model_sym
end

#validate_blockObject

Returns the value of attribute validate_block



18
19
20
# File 'lib/treeview/columns/CellRendererCombo.rb', line 18

def validate_block
  @validate_block
end

Instance Method Details

#set_model(vr_combo) ⇒ Object

This sets the renderer's “editable” property to true, and makes it save

the edited value to the model.  When a user edits a row in the ListView
the value isn't automatically saved by Gtk.  This method groups both actions
together, so setting edit_save=true, allows both editing and saving of
the field.  

Also, you can use VR::ListView and VR::TreeView's convenience methods to
envoke call this method:

 NAME = 0
 ADDR = 1
 @view.set_attr([NAME, ADDR], :edit_save => true)  #sets model_col = 0, 1 
 @view.set_edit_save( 0 => true, 1 => false)

is_editable = boolean


58
59
60
61
62
# File 'lib/treeview/columns/CellRendererCombo.rb', line 58

def set_model(vr_combo) # :nodoc:
  self.model = Gtk::ListStore.new(String)
  vr_combo.selections.each { |s| r = self.model.append ; r[0] = s }
  self.text_column = 0
end