Class: VR::Col::BlobCol

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

Overview

The BlobCol 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::Col::BlobCol:

 @view = VR::ListView.new(:name => String, :quote => VR::Col::BlobCol)
 row = @view.add_row
 row[:name] = "Eric"
 row[:quote] = VR::Col::BlobCol.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

#extract_key, #get_glade_active_record, #get_glade_all, #get_glade_variables, #load_glade, #parse_signals, #set_drag_drop, #set_glade_active_record, #set_glade_all, #set_glade_hash, #set_glade_variables, #show_glade, #try_to_select_text_in_combobox, #window1__destroy, #window1__key_press_event

Constructor Details

#initialize(text, length_to_display = 20) ⇒ BlobCol

  • text - String value of the field

  • length_to_display - Integer number of characters to display in the listview. Default: 20



32
33
34
35
# File 'lib/treeview/columns/BlobCol.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/BlobCol.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/BlobCol.rb', line 27

def text
  @text
end

Instance Method Details

#<=>(text_col) ⇒ Object



59
60
61
# File 'lib/treeview/columns/BlobCol.rb', line 59

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

#before_showObject



37
38
39
# File 'lib/treeview/columns/BlobCol.rb', line 37

def before_show()
  @builder["window1"].resize 650, 360
end

#buttonCancel__clicked(*args) ⇒ Object

:nodoc:



55
56
57
# File 'lib/treeview/columns/BlobCol.rb', line 55

def buttonCancel__clicked(*args) # :nodoc:
  @builder["window1"].destroy
end

#buttonSave__clicked(*args) ⇒ Object

:nodoc:



50
51
52
53
# File 'lib/treeview/columns/BlobCol.rb', line 50

def buttonSave__clicked(*args) # :nodoc:
  get_glade_variables()
  @builder["window1"].destroy
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.


46
47
48
# File 'lib/treeview/columns/BlobCol.rb', line 46

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