Class: RubyCurses::CellEditor

Inherits:
Object
  • Object
show all
Includes:
ConfigSetup, Utils
Defined in:
lib/rbcurse/celleditor.rb

Instance Method Summary collapse

Methods included from Utils

#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #wrap_text

Methods included from ConfigSetup

#cget, #config_setup, #configure, #variable_set

Constructor Details

#initialize(component, config = {}, &block) ⇒ CellEditor

Returns a new instance of CellEditor.



21
22
23
24
25
26
27
28
29
# File 'lib/rbcurse/celleditor.rb', line 21

def initialize component, config={}, &block
  @component = component
  s = @component.class.to_s.downcase()
  s.slice!("rubycurses::")
  @_class = s.to_sym
  #$log.debug " CELL EIDOTR got #{@_class}"
  config_setup config # @config.each_pair { |k,v| variable_set(k,v) }
  instance_eval &block if block_given?
end

Instance Method Details

#cancel_editorObject

This may not really be necessary since we paint the cell editor only if editing is on



109
110
111
112
113
114
115
116
117
118
# File 'lib/rbcurse/celleditor.rb', line 109

def cancel_editor
  widget = component()
  # NOOO THIS IS CALLED BY CANCEL AND STOP
  # somehow we need to ensure that if on_leave fails you can't get out. Here its a bit late
  # i think FIXME TODO
  #widget.on_leave # call so any triggers or validations can fire
  widget.focusable = false
  widget.visible = false
  widget.attr = Ncurses::A_REVERSE 
end

#checkbox_getvalueObject



48
49
50
# File 'lib/rbcurse/celleditor.rb', line 48

def checkbox_getvalue
  @component.getvalue
end

#combobox_getvalueObject



51
52
53
54
55
# File 'lib/rbcurse/celleditor.rb', line 51

def combobox_getvalue
  #@component.on_leave # added 2009-01-19 12:12 
  @component.getvalue
  #@component.selected_item
end

#componentObject



70
71
72
# File 'lib/rbcurse/celleditor.rb', line 70

def component
  @component
end

#field_getvalueObject

maybe this should check valid (on_leave) and throw exception



43
44
45
46
47
# File 'lib/rbcurse/celleditor.rb', line 43

def field_getvalue
  #@component.on_leave # throws exception! Added 2009-01-17 00:47 
  @component.init_vars # 2009-01-18 01:13 should not carry over to next row curpos and pcol
  return @component.getvalue
end

#getvalueObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rbcurse/celleditor.rb', line 30

def getvalue
  case @_class
  when :field
    return field_getvalue
  when :checkbox
    return checkbox_getvalue
  when :combobox
    return combobox_getvalue
  else
    raise "Unknown class #{@_class} in CellEditor getv"
  end
end

#on_leave(row, col) ⇒ Object

should be called from on_leave_cell of table, but is beng called from editing_stopped FIXME



74
75
76
77
78
79
80
81
# File 'lib/rbcurse/celleditor.rb', line 74

def on_leave row, col
  f = @component
  f.on_leave
  if f.respond_to? :editable and f.modified?
    $log.debug " Table about to fire CHANGED for #{f} "
    f.fire_handler(:CHANGED, f) 
  end
end

#prepare_editor(parent, row, col, value) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rbcurse/celleditor.rb', line 82

def prepare_editor parent, row, col,  value
  #value = value.dup if value.respond_to? :dup
  value = value.dup rescue value
  setvalue value #.dup
  widget = component()
  widget.row = row
  widget.col = col
  # unfortunately 2009-01-11 19:47 combo boxes editable allows changing value
  # FIXME so combo's can be editable, but no new value added
  if @_class == :combobox
    widget.editable = false if widget.respond_to? :editable  # chb's don't ???
  else
    widget.editable = true if widget.respond_to? :editable  # chb's don't ???
  end
  widget.focusable = true
  widget.visible = true
  widget.form = parent.form
  #$log.debug " prepare editor value #{widget.display_length} displlen #{widget.maxlen}"
  $log.debug " prepare editor form: #{widget.form} "
  #widget.display_length = widget.display_length -1
  widget.bgcolor = 'yellow'
  widget.color = 'black'
  widget.on_enter
  #widget.attr = Ncurses::A_REVERSE | Ncurses::A_BOLD
  #$log.debug " prepare editor value #{value} : fr:#{row}, fc:#{col}"
end

#setvalue(value) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rbcurse/celleditor.rb', line 56

def setvalue value
  case @_class
  when :field
    @component.set_buffer value
  when :checkbox
    @component.checked value
  when :combobox
    @component.set_buffer value
    #index = @component.list.index value
    #@component.current_index = index
  else
    raise "Unknown class #{@_class} in CellEditor setv"
  end
end