Class: VR::TextCol

Inherits:
Object
  • Object
show all
Includes:
GladeGUI
Defined in:
lib/treeview/columns/TextCol.rb

Overview

The TextCol class is a simple text editor for editing strings of data:

http://visualruby.net/img/textcol.jpg

It is a very useful class when you want to display and edit long strings
of data in a VR::ListView.  To create a coulmn of long strings in a VR::ListView,
simply define the column type as VR::TextCol:

 @view = VR::ListView.new(:name => String, :quote => VR::TextCol)
 row = @view.add_row
 row[:name] = "Eric"
 row[:quote] = VR::TextCol.new("I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth.  - Umberto Eco) ")

The above listview will only display the first 20 characters of the quote, so
it won't destroy the appearance of the listview.  When a user clicks on the
quote column, a window like the one above will appear.

See the example project, "listview_objects" for more.

Instance Attribute Summary collapse

Attributes included from GladeGUI

#builder

Instance Method Summary collapse

Methods included from GladeGUI

#active_record_valid?, #class_name, #destroy_window, #fill_control, #get_glade_active_record, #get_glade_all, #get_glade_variables, #load_glade, #parse_signals, #set_glade_active_record, #set_glade_all, #set_glade_variables, #set_parent, #show_window

Constructor Details

#initialize(text, length_to_display = 20) ⇒ TextCol

Returns a new instance of TextCol.



32
33
34
35
# File 'lib/treeview/columns/TextCol.rb', line 32

def initialize(text, length_to_display = 20)
  @length_to_display = length_to_display
  @text = text
end

Instance Attribute Details

#length_to_displayObject

Returns the value of attribute length_to_display.



27
28
29
# File 'lib/treeview/columns/TextCol.rb', line 27

def length_to_display
  @length_to_display
end

#textObject

Returns the value of attribute text.



27
28
29
# File 'lib/treeview/columns/TextCol.rb', line 27

def text
  @text
end

Instance Method Details

#<=>(text_col) ⇒ Object



58
59
60
# File 'lib/treeview/columns/TextCol.rb', line 58

def <=>(text_col)
  self.text <=> text_col.text
end

#buttonSave__clicked(*args) ⇒ Object

:nodoc:



53
54
55
56
# File 'lib/treeview/columns/TextCol.rb', line 53

def buttonSave__clicked(*args) # :nodoc:

  get_glade_variables()
  destroy_window()
end

#showObject



37
38
39
40
41
42
# File 'lib/treeview/columns/TextCol.rb', line 37

def show()
  load_glade(__FILE__)     
  set_glade_variables()
  @builder["window1"].resize 650, 360
  show_window()
end

#to_sObject

The to_s method outputs the string that is shown in the VR::ListView. By default

it will display the first 20 characters of the string.  If you
want to change the number of characters it displays, change the
value of the length_to_display variable.


49
50
51
# File 'lib/treeview/columns/TextCol.rb', line 49

def to_s
  (@text.size > @length_to_display ? @text[0, @length_to_display - 4] + "..." :  @text).gsub("\n"," ")
end