Class: VR::Col::Ren::CellRendererObject

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

Overview

This class is a helper to VR::ListView and VR::TreeView. When

colums are created, this class is used as the renderer because
it adds functionality to the Gtk Renderer.

When you call ListView#render(model_col) an instance of this class
will be returned.  It is a subclass of

{Gtk::CellRendererText}[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ACellRendererText]

So it has all the functionality of its parent, plus the methods listed here.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

:nodoc:



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

def initialize(model_col, column, view, model_sym) # :nodoc:
  super()
  @model_col = model_col
  @model_sym = model_sym
  @view = view
  @column = column
  @edit = true
  @edited_callback = nil
  @visual_attributes_method = "visual_attributes"
  @view.model.set_sort_func(@model_col) { |m,x,y| x[@model_col] <=> y[@model_col] } 
  @show_block = Proc.new { |obj| obj.show_glade() if obj.respond_to? "show_glade" }
  @view.signal_connect("row_activated") do | view, path, col |
    next if !@edit or !col.eql? @column
    iter = @view.model.get_iter(path)
    obj = iter[@model_col]
    @show_block.call(obj)
    block = @edited_callback ? @edited_callback.call(@model_sym, @view.vr_row(iter)) : true 
    @view.signal_emit_stop("row_activated") if block  
  end
end

Instance Attribute Details

#columnObject

Returns the value of attribute column



16
17
18
# File 'lib/treeview/columns/CellRendererObject.rb', line 16

def column
  @column
end

#edited_callbackObject

Returns the value of attribute edited_callback



16
17
18
# File 'lib/treeview/columns/CellRendererObject.rb', line 16

def edited_callback
  @edited_callback
end

#model_colObject

Returns the value of attribute model_col



16
17
18
# File 'lib/treeview/columns/CellRendererObject.rb', line 16

def model_col
  @model_col
end

#model_symObject

Returns the value of attribute model_sym



16
17
18
# File 'lib/treeview/columns/CellRendererObject.rb', line 16

def model_sym
  @model_sym
end

#visual_attributes_methodObject

Returns the value of attribute visual_attributes_method



16
17
18
# File 'lib/treeview/columns/CellRendererObject.rb', line 16

def visual_attributes_method
  @visual_attributes_method
end

Instance Method Details

#editable=(e) ⇒ Object



40
41
42
# File 'lib/treeview/columns/CellRendererObject.rb', line 40

def editable=(e)
  @edit = e
end

#render_object(iter) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/treeview/columns/CellRendererObject.rb', line 44

def render_object(iter)
  obj = iter[@view.id(@model_col)]
  self.text = obj.respond_to?(:to_s) ?  obj.to_s : "Define to_s!"
  if obj.respond_to? @visual_attributes_method
    return unless attrib = obj.send(@visual_attributes_method)
    attrib.each_pair do | key, val |
      self.send( key.to_s + "=", val)
    end
  end
end

#set_editableObject



39
# File 'lib/treeview/columns/CellRendererObject.rb', line 39

alias :set_editable :editable=