rbcurse 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/CHANGELOG +33 -0
  2. data/README.markdown +7 -1
  3. data/TODO2.txt +21 -15
  4. data/VERSION +1 -1
  5. data/examples/abasiclist.rb +2 -2
  6. data/examples/alpmenu.rb +1 -1
  7. data/examples/app.rb +0 -1
  8. data/examples/appdirtree.rb +4 -2
  9. data/examples/appemail.rb +7 -3
  10. data/examples/appemaillb.rb +1 -1
  11. data/examples/appgcompose.rb +2 -2
  12. data/examples/appgmail.rb +1 -1
  13. data/examples/appmethods.rb +20 -2
  14. data/examples/atree.rb +9 -1
  15. data/examples/dbdemo.rb +460 -0
  16. data/examples/dirtree.rb +1 -1
  17. data/examples/menu1.rb +37 -5
  18. data/examples/multispl.rb +1 -1
  19. data/examples/rfe.rb +9 -2
  20. data/examples/splitp.rb +1 -1
  21. data/examples/sqlc.rb +6 -10
  22. data/examples/sqlm.rb +2 -20
  23. data/examples/sqlt.rb +408 -0
  24. data/examples/term2.rb +1 -1
  25. data/examples/test2.rb +169 -97
  26. data/examples/testapp.rb +1 -1
  27. data/examples/testapp2.rb +1 -1
  28. data/examples/testkeypress.rb +4 -2
  29. data/examples/testtable.rb +6 -0
  30. data/examples/testtpane.rb +35 -23
  31. data/examples/testvimsplit.rb +3 -2
  32. data/lib/rbcurse.rb +1 -1
  33. data/lib/rbcurse/action.rb +8 -0
  34. data/lib/rbcurse/app.rb +39 -23
  35. data/lib/rbcurse/extras/bottomline.rb +101 -13
  36. data/lib/rbcurse/extras/directorylist.rb +14 -5
  37. data/lib/rbcurse/extras/divider.rb +1 -1
  38. data/lib/rbcurse/extras/listselectable.rb +42 -8
  39. data/lib/rbcurse/extras/masterdetail.rb +2 -2
  40. data/lib/rbcurse/extras/scrollbar.rb +11 -2
  41. data/lib/rbcurse/extras/statusline.rb +56 -0
  42. data/lib/rbcurse/extras/stdscrwindow.rb +11 -0
  43. data/lib/rbcurse/extras/tabular.rb +2 -1
  44. data/lib/rbcurse/extras/tabularwidget.rb +60 -17
  45. data/lib/rbcurse/extras/viewer.rb +16 -4
  46. data/lib/rbcurse/keylabelprinter.rb +34 -4
  47. data/lib/rbcurse/listeditable.rb +5 -1
  48. data/lib/rbcurse/listkeys.rb +1 -1
  49. data/lib/rbcurse/listscrollable.rb +15 -8
  50. data/lib/rbcurse/rbasiclistbox.rb +44 -23
  51. data/lib/rbcurse/rcommandwindow.rb +8 -14
  52. data/lib/rbcurse/rdialogs.rb +187 -2
  53. data/lib/rbcurse/rlistbox.rb +38 -19
  54. data/lib/rbcurse/rmenu.rb +313 -93
  55. data/lib/rbcurse/rmessagebox.rb +3 -2
  56. data/lib/rbcurse/rmulticontainer.rb +5 -3
  57. data/lib/rbcurse/rmultisplit.rb +2 -11
  58. data/lib/rbcurse/rmultitextview.rb +4 -5
  59. data/lib/rbcurse/rtabbedpane.rb +223 -69
  60. data/lib/rbcurse/rtable.rb +6 -10
  61. data/lib/rbcurse/rtextarea.rb +57 -36
  62. data/lib/rbcurse/rtextview.rb +12 -15
  63. data/lib/rbcurse/rtree.rb +79 -22
  64. data/lib/rbcurse/rvimsplit.rb +16 -25
  65. data/lib/rbcurse/rwidget.rb +376 -523
  66. data/lib/rbcurse/tree/treecellrenderer.rb +24 -11
  67. data/lib/rbcurse/tree/treemodel.rb +1 -1
  68. data/lib/ver/window.rb +130 -66
  69. metadata +5 -3
  70. data/examples/term.rb +0 -48
@@ -46,6 +46,8 @@ module RubyCurses
46
46
  bind_key(?+, :ask_select)
47
47
  bind_key(?-, :ask_unselect)
48
48
  bind_key(?I) { @hide_dot_files = !@hide_dot_files; prune_entries; }
49
+ #bind_key(?v, :view_current) # does not respond to ??? XXX
50
+ bind_key(?v) {view_current}
49
51
  super
50
52
  end
51
53
  # changing the current path, refreshes files
@@ -83,10 +85,8 @@ module RubyCurses
83
85
  list @entries
84
86
  @list.insert 0, @_header
85
87
  @title = @current_path
86
- #@current_index = @_first_data_index
87
- # this next line will keep the cursor on header after sorting
88
- # earlier cursor would appear in header but selection would be data row
89
- @current_index = @_header_row_index # FFI 2011-09-16 keeping cursor synched with selection
88
+ @current_index = @_first_data_index
89
+ set_form_row
90
90
  end
91
91
  # called by parent's repaint
92
92
  def convert_value_to_text file, crow
@@ -227,7 +227,11 @@ module RubyCurses
227
227
  @reverse = false
228
228
  end
229
229
  sort_by header.strip, @reverse
230
+ # this next line will keep the cursor on header after sorting
231
+ # earlier cursor would appear in header but selection would be data row
232
+ @current_index = @_header_row_index # FFI 2011-09-16 keeping cursor synched with selection
230
233
  @_last_header_sorted = header
234
+ set_form_row
231
235
  return
232
236
  end
233
237
  value = current_value
@@ -399,6 +403,12 @@ module RubyCurses
399
403
  populate @current_path
400
404
  set_form_row
401
405
  end
406
+ def view_current
407
+ file = self.current_value
408
+ require 'rbcurse/extras/viewer.rb'
409
+ RubyCurses::Viewer.view("#{current_path}/#{file}", :close_key => KEY_RETURN, :title => "<Enter> to close, M-l M-h to scroll")
410
+ end
411
+ # ADD HERE
402
412
  ##
403
413
  end # class
404
414
 
@@ -452,7 +462,6 @@ module RubyCurses
452
462
  graphic.printstring r, c, "%-*s" % [len, value], @color_pair,@attr
453
463
  end
454
464
  end
455
- # ADD HERE
456
465
  end
457
466
  end # module
458
467
  # set filetype=ruby
@@ -44,7 +44,7 @@ module RubyCurses
44
44
  dsl_property :parent
45
45
  # which row is focussed, current_index of listbox, required.
46
46
  # how many total rows of data does the list have, same as @list.length, required.
47
- dsl_accessor :next
47
+ dsl_accessor :next_component # 'next' bombing in dsl_accessor 2011-10-2 PLS CHANGE ELSEWHERE
48
48
 
49
49
  # TODO: if parent passed, we shold bind to ON_ENTER and get current_index, so no extra work is required.
50
50
 
@@ -5,6 +5,7 @@
5
5
  # the original gets into models and has complicated operation as well
6
6
  # as difficult to remember method names. This attempts to be a simple plugin.
7
7
  # Currently being used by rbasiclistbox and now tabularwidget.
8
+ # NOTE: pls define @_header_adjustment to 0 if you don't use it or know what it means.
8
9
  # TODO: of course we need to fire events so user can do something.
9
10
  module RubyCurses
10
11
  module NewListSelectable
@@ -24,16 +25,22 @@ module RubyCurses
24
25
  when :multiple
25
26
  if @selected_indices.include? crow
26
27
  @selected_indices.delete crow
28
+ lse = ListSelectionEvent.new(crow, crow, self, :DELETE)
29
+ fire_handler :LIST_SELECTION_EVENT, lse
27
30
  else
28
- #clear_selection
29
- #@selected_indices[0] = crow
30
31
  @selected_indices << crow
32
+ lse = ListSelectionEvent.new(crow, crow, self, :INSERT)
33
+ fire_handler :LIST_SELECTION_EVENT, lse
31
34
  end
32
35
  else
33
36
  if @selected_index == crow
34
37
  @selected_index = nil
38
+ lse = ListSelectionEvent.new(crow, crow, self, :DELETE)
39
+ fire_handler :LIST_SELECTION_EVENT, lse
35
40
  else
36
41
  @selected_index = crow
42
+ lse = ListSelectionEvent.new(crow, crow, self, :INSERT)
43
+ fire_handler :LIST_SELECTION_EVENT, lse
37
44
  end
38
45
  end
39
46
  end
@@ -53,19 +60,29 @@ module RubyCurses
53
60
  if @selected_indices.include? crow
54
61
  # delete from last_clicked until this one in any direction
55
62
  min.upto(max){ |i| @selected_indices.delete i }
63
+ lse = ListSelectionEvent.new(min, max, self, :DELETE)
64
+ fire_handler :LIST_SELECTION_EVENT, lse
56
65
  else
57
66
  # add to selection from last_clicked until this one in any direction
58
67
  min.upto(max){ |i| @selected_indices << i unless @selected_indices.include?(i) }
68
+ lse = ListSelectionEvent.new(min, max, self, :INSERT)
69
+ fire_handler :LIST_SELECTION_EVENT, lse
59
70
  end
60
71
  else
61
72
  end
62
73
  @repaint_required = true
74
+ self
63
75
  end
64
76
  # clears selected indices, typically called when multiple select
65
77
  # Key binding is application specific
66
78
  def clear_selection
79
+ return if @selected_indices.nil? || @selected_indices.empty?
67
80
  @selected_indices = []
68
81
  @selected_index = nil
82
+ # Not sure what event type I should give, DELETE or a new one, user should
83
+ # understand that selection has been cleared, and ignore first two params
84
+ lse = ListSelectionEvent.new(0, @list.size, self, :CLEAR)
85
+ fire_handler :LIST_SELECTION_EVENT, lse
69
86
  @repaint_required = true
70
87
  end
71
88
  def is_row_selected crow=@current_index-@_header_adjustment
@@ -100,8 +117,8 @@ module RubyCurses
100
117
  @anchor_selection_index = ix0
101
118
  @lead_selection_index = ix1
102
119
  ix0.upto(ix1) {|i| @selected_indices << i unless @selected_indices.include? i }
103
- #lse = ListSelectionEvent.new(ix0, ix1, @parent, :INSERT)
104
- #fire_handler :LIST_SELECTION_EVENT, lse
120
+ lse = ListSelectionEvent.new(ix0, ix1, self, :INSERT)
121
+ fire_handler :LIST_SELECTION_EVENT, lse
105
122
  #$log.debug " DLSM firing LIST_SELECTION EVENT #{lse}"
106
123
  end
107
124
  alias :add_row_selection_interval :add_selection_interval
@@ -109,8 +126,8 @@ module RubyCurses
109
126
  @anchor_selection_index = ix0
110
127
  @lead_selection_index = ix1
111
128
  @selected_indices.delete_if {|x| x >= ix0 and x <= ix1}
112
- #lse = ListSelectionEvent.new(ix0, ix1, @parent, :DELETE)
113
- #fire_handler :LIST_SELECTION_EVENT, lse
129
+ lse = ListSelectionEvent.new(ix0, ix1, self, :DELETE)
130
+ fire_handler :LIST_SELECTION_EVENT, lse
114
131
  end
115
132
  alias :remove_row_selection_interval :remove_selection_interval
116
133
  # convenience method to select next len rows
@@ -122,13 +139,13 @@ module RubyCurses
122
139
  # select all rows, you may specify starting row.
123
140
  # if header row, then 1 else should be 0. Actually we should have a way to determine
124
141
  # this, and the default should be zero.
125
- def select_all start_row=0
142
+ def select_all start_row=0 #+@_header_adjustment
126
143
  @repaint_required = true
127
144
  # don't select header row - need to make sure this works for all cases. we may
128
145
  # need a variable instead of hardoded value
129
146
  add_row_selection_interval start_row, row_count()
130
147
  end
131
- def invert_selection start_row=1
148
+ def invert_selection start_row=0 #+@_header_adjustment
132
149
  start_row.upto(row_count()){|i| invert_row_selection i }
133
150
  end
134
151
 
@@ -189,6 +206,8 @@ module RubyCurses
189
206
  bind_key(?a, :select_all)
190
207
  bind_key(?*, :invert_selection)
191
208
  bind_key(?u, :clear_selection)
209
+ @_header_adjustment ||= 0 # incase caller does not use
210
+ @_events << :LIST_SELECTION_EVENT unless @_events.include? :LIST_SELECTION_EVENT
192
211
  end
193
212
  def list_init_vars
194
213
  @selected_indices = []
@@ -219,4 +238,19 @@ module RubyCurses
219
238
  @selected_indices
220
239
  end
221
240
  end # mod
241
+ class ListSelectionEvent
242
+ attr_accessor :firstrow, :lastrow, :source, :type
243
+ def initialize firstrow, lastrow, source, type
244
+ @firstrow = firstrow
245
+ @lastrow = lastrow
246
+ @source = source
247
+ @type = type
248
+ end
249
+ def to_s
250
+ "#{@type.to_s}, firstrow: #{@firstrow}, lastrow: #{@lastrow}, source: #{@source}"
251
+ end
252
+ def inspect
253
+ to_s
254
+ end
255
+ end
222
256
  end # mod
@@ -28,7 +28,7 @@ class MasterDetail < Widget
28
28
  if @first_time
29
29
  @first_time = nil
30
30
  [@vim, @left, @right1, @right2].each { |e|
31
- e.set_buffering(:target_window => @target_window || @form.window, :form => @form)
31
+ e.set_buffering(:target_window => @target_window || @form.window, :form => @form) # removed on 2011-09-29
32
32
  }
33
33
  end
34
34
  @vim.repaint
@@ -61,7 +61,7 @@ class MasterDetail < Widget
61
61
  # what if user gives in wrong order !!
62
62
  @gb = @vim.add :divider, :SECOND, 0
63
63
  @right2 = @vim.add comp, :SECOND, weight
64
- @gb.next(@right2)
64
+ @gb.next_component(@right2)
65
65
  _add_component comp
66
66
  @right2
67
67
  end
@@ -42,6 +42,7 @@ module RubyCurses
42
42
  super
43
43
  @color_pair = get_color $datacolor, @color, @bgcolor
44
44
  @scroll_pair = get_color $bottomcolor, :green, :white
45
+ #$log.debug "SCROLLBAR COLOR cp #{@color_pair} sp #{@scroll_pair} " if $log.debug?
45
46
  @window = form.window
46
47
  @editable = false
47
48
  @focusable = false
@@ -55,6 +56,11 @@ module RubyCurses
55
56
  @repaint_required = true #requred otherwise at end when same value sent, prop handler
56
57
  # will not be fired (due to optimization).
57
58
  end
59
+ # in some cases, on leaving a listbox or other component redraws itself to reduce
60
+ # selected or highlighted object, so the scrollbar gets overwritten. We need to repaint it.
61
+ @parent.bind :LEAVE do |p|
62
+ @repaint_required = true
63
+ end
58
64
  end
59
65
  end
60
66
 
@@ -82,10 +88,11 @@ module RubyCurses
82
88
  bc = $datacolor
83
89
  bordercolor = @border_color || bc
84
90
  borderatt = @border_attrib || Ncurses::A_REVERSE
91
+ #$log.debug "SCROLL bordercolor #{bordercolor} , #{borderatt} " if $log.debug?
85
92
 
86
93
 
87
94
  @graphic.attron(Ncurses.COLOR_PAIR(bordercolor) | borderatt)
88
- $log.debug " XXX SCROLL #{@row} #{@col} #{@length} "
95
+ #$log.debug " XXX SCROLL #{@row} #{@col} #{@length} "
89
96
  @graphic.mvvline(@row+0, @col, 1, @length-0)
90
97
  @graphic.attroff(Ncurses.COLOR_PAIR(bordercolor) | borderatt)
91
98
 
@@ -95,14 +102,16 @@ module RubyCurses
95
102
  @current_index = 0 if @current_index < 0
96
103
  @current_index = listlen-1 if @current_index >= listlen
97
104
  sclen = (pht/listlen)* @length
105
+ sclen = 1 if sclen < 1 # sometimes 0.7 for large lists 100 items 2011-10-1
98
106
  scloc = (@current_index/listlen)* @length
99
107
  scloc = (@length - sclen) if scloc > @length - sclen # don't exceed end
100
108
  if @current_index == @list_length - 1
101
- scloc = @length - sclen + 1
109
+ scloc = @length - sclen + 0 # earlier 1, but removed since sclen min 1 2011-10-1
102
110
  end
103
111
  @graphic.attron(Ncurses.COLOR_PAIR(@scroll_pair) | borderatt)
104
112
  r = @row + scloc
105
113
  c = @col + 0
114
+ #$log.debug " XXX SCROLLBAR #{r} #{c} #{sclen} "
106
115
  @graphic.mvvline(r, c, 1, sclen)
107
116
  @graphic.attroff(Ncurses.COLOR_PAIR(@scroll_pair) | borderatt)
108
117
  @repaint_required = false
@@ -0,0 +1,56 @@
1
+ require 'rbcurse'
2
+
3
+ module RubyCurses
4
+
5
+ #
6
+ # A vim-like application status bar that can display time and various other statuses
7
+ # at the bottom, typically above the dock (3rd line from last).
8
+ #
9
+ class StatusLine < Widget
10
+
11
+ def initialize form, config={}, &block
12
+ @row = Ncurses.LINES-3
13
+ @col = 0
14
+ super
15
+ @focusable = false
16
+ @editable = false
17
+ @command = nil
18
+ @repaint_required = true
19
+ bind(:PROPERTY_CHANGE) { |e| @color_pair = nil ; }
20
+ end
21
+ #
22
+ # command that returns a string that populates the status line.
23
+ # See dbdemo.rb
24
+ # e.g.
25
+ # @l.command { "%-20s [DB: %-s | %-s ]" % [ Time.now, $current_db || "None", $current_table || "----"] }
26
+ #
27
+ def command *args, &blk
28
+ @command = blk
29
+ @args = args
30
+ end
31
+
32
+ # NOTE: I have not put a check of repaint_required, so this will print on each key-stroke OR
33
+ # rather whenever form.repaint is called.
34
+ def repaint
35
+ @color_pair ||= get_color($datacolor, @color, @bgcolor)
36
+
37
+ # first print dashes through
38
+ @form.window.printstring @row, @col, "%s" % "-" * Ncurses.COLS, @color_pair, Ncurses::A_REVERSE
39
+
40
+ # now call the block to get current values
41
+ if @command
42
+ ftext = @command.call(self, @args) if @command
43
+ else
44
+ status = $status_message ? $status_message.value : ""
45
+ ftext = " %-20s | %s" % [Time.now, status] # should we print a default value just in case user doesn't
46
+ end
47
+ @form.window.printstring @row, @col, ftext, $datacolor, Ncurses::A_REVERSE
48
+
49
+ @repaint_required = false
50
+ end
51
+ def handle_keys ch
52
+ return :UNHANDLED
53
+ end
54
+
55
+ end # class
56
+ end # module
@@ -12,6 +12,12 @@ module RubyCurses
12
12
  # FFI: 2011-09-9 The change to FFI has affected this a lot since I do not get window
13
13
  # methods in rbcurse for stdscr whereas suprisingly if i run the samples, i get them
14
14
  # all.
15
+ #
16
+ # NOTE:
17
+ # WARNING: Pls do not use this class. This was just experimentation. Using stdscr
18
+ # mucks up the display and overwrites objects on the screen. I will remove this class
19
+ # at some time.
20
+ #
15
21
  class StdscrWindow
16
22
  attr_reader :width, :height, :top, :left
17
23
 
@@ -264,7 +270,9 @@ module RubyCurses
264
270
  # 2010-09-13 00:22 WE should not use these any longer.
265
271
  # Application should create a label and map a Variable named
266
272
  # $errormessage to it. We should only update the Variable
273
+ # CLEANUP DEPRECATED
267
274
  def print_error_message text=$error_message
275
+ raise "DEPRECATED CLEANUP use global method of same name"
268
276
  r = $error_message_row || Ncurses.LINES-1
269
277
  c = $error_message_col || (Ncurses.COLS-text.length)/2
270
278
 
@@ -274,7 +282,9 @@ module RubyCurses
274
282
  $error_message_clear_pending = true
275
283
  end
276
284
  # added by rk 2008-11-29 19:01
285
+ # CLEANUP DEPRECATED
277
286
  def print_status_message text=$status_message
287
+ raise "DEPRECATED CLEANUP use global method of same name"
278
288
  r = $status_message_row || Ncurses.LINES-1
279
289
  clear_error r, $datacolor
280
290
  # print it in centre
@@ -284,6 +294,7 @@ module RubyCurses
284
294
  # I am not only clearing if something was printed. This is since
285
295
  # certain small forms like TabbedForm top form throw an error on printstring.
286
296
  #
297
+ #raise "DEPRECATED CLEANUP use global method of same name"
287
298
  def clear_error r = $error_message_row, color = $datacolor
288
299
  return unless $error_message_clear_pending
289
300
  c = $error_message_col || (Ncurses.COLS-text.length)/2
@@ -26,6 +26,7 @@
26
26
  module RubyCurses
27
27
 
28
28
  class Tabular
29
+ GUESSCOLUMNS = 20
29
30
 
30
31
  def yield_or_eval &block
31
32
  return unless block
@@ -187,7 +188,7 @@ module RubyCurses
187
188
  private
188
189
  def _guess_col_widths #:nodoc:
189
190
  @list.each_with_index { |r, i|
190
- break if i > 10
191
+ break if i > GUESSCOLUMNS
191
192
  next if r == :separator
192
193
  r.each_with_index { |c, j|
193
194
  x = c.to_s.length
@@ -156,6 +156,11 @@ module RubyCurses
156
156
  bind_key(?b, :previous_column)
157
157
  list_bindings
158
158
  end
159
+
160
+ #
161
+ # set column names
162
+ # @param [Array] column names or headings
163
+ #
159
164
  def columns=(array)
160
165
  @_header_adjustment = 1
161
166
  @columns = array
@@ -168,7 +173,7 @@ module RubyCurses
168
173
  end
169
174
  alias :headings= :columns=
170
175
  ##
171
- # send in a list
176
+ # send in a list of data
172
177
  #
173
178
  # @param [Array / Tabular] data to be displayed
174
179
  def set_content list
@@ -325,17 +330,11 @@ module RubyCurses
325
330
  end
326
331
 
327
332
  def repaint # Tabularwidget :nodoc:
328
- if @screen_buffer.nil?
329
- safe_create_buffer
330
- @screen_buffer.name = "Pad::TABW_PAD_#{@name}" unless @screen_buffer.nil?
331
- $log.debug " tabularwid creates pad #{@screen_buffer} #{@name}"
332
- end
333
333
 
334
334
  #return unless @repaint_required # 2010-02-12 19:08 TRYING - won't let footer print for col move
335
335
  paint if @repaint_required
336
336
  # raise "TV 175 graphic nil " unless @graphic
337
337
  print_foot if @print_footer && @repaint_footer_required
338
- buffer_to_window
339
338
  end
340
339
  def getvalue
341
340
  @list
@@ -367,10 +366,12 @@ module RubyCurses
367
366
  when KEY_UP, ?k.getbyte(0)
368
367
  #select_prev_row
369
368
  ret = up
369
+ get_window.ungetch(KEY_BTAB) if ret == :NO_PREVIOUS_ROW
370
370
  check_curpos
371
371
 
372
372
  when KEY_DOWN, ?j.getbyte(0)
373
373
  ret = down
374
+ get_window.ungetch(KEY_TAB) if ret == :NO_NEXT_ROW
374
375
  check_curpos
375
376
  when KEY_LEFT, ?h.getbyte(0)
376
377
  cursor_backward
@@ -390,9 +391,9 @@ module RubyCurses
390
391
  blen = @buffer.rstrip.length
391
392
  set_form_col blen
392
393
  # search related
393
- when @KEY_ASK_FIND
394
+ when @KEY_ASK_FIND # FIXME
394
395
  ask_search
395
- when @KEY_FIND_MORE
396
+ when @KEY_FIND_MORE # FIXME
396
397
  find_more
397
398
  when 10, 13, KEY_ENTER
398
399
  #fire_handler :PRESS, self
@@ -428,8 +429,9 @@ module RubyCurses
428
429
  begin
429
430
  ret = process_key ch, self
430
431
  rescue => err
431
- $error_message = err
432
- @form.window.print_error_message
432
+ $error_message.value = err.to_s
433
+ # @form.window.print_error_message # changed 2011 dts
434
+ alert err.to_s
433
435
  $log.error " Tabularwidget ERROR #{err} "
434
436
  $log.debug(err.backtrace.join("\n"))
435
437
  # XXX caller app has no idea error occurred so can't do anything !
@@ -570,16 +572,16 @@ module RubyCurses
570
572
  @graphic = my_win unless @graphic
571
573
  @win_left = my_win.left
572
574
  @win_top = my_win.top
573
- #_guess_col_widths
574
575
  tm = get_content
576
+ rc = tm.length
577
+ _estimate_column_widths if rc > 0 # will set preferred_width 2011-10-4
575
578
  @left_margin ||= @row_selected_symbol.length
576
579
  @width ||= @preferred_width
580
+
577
581
  @height ||= [tm.length+3, 10].min
578
582
  _prepare_format
579
583
 
580
584
  print_borders if (@suppress_borders == false && @repaint_all) # do this once only, unless everything changes
581
- rc = tm.length
582
- _estimate_column_widths if rc > 0
583
585
  _maxlen = @maxlen || @width-@internal_width
584
586
  $log.debug " #{@name} Tabularwidget repaint width is #{@width}, height is #{@height} , maxlen #{maxlen}/ #{@maxlen}, #{@graphic.name} roff #{@row_offset} coff #{@col_offset}"
585
587
  tr = @toprow
@@ -621,7 +623,6 @@ module RubyCurses
621
623
  end
622
624
  @repaint_required = false
623
625
  @repaint_footer_required = true
624
- @buffer_modified = true # required by form to call buffer_to_screen
625
626
  @repaint_all = false
626
627
 
627
628
  end
@@ -630,12 +631,33 @@ module RubyCurses
630
631
  def print_data_row r, c, len, value, color, attr
631
632
  @graphic.printstring r, c, "%-*s" % [len,value], color, attr
632
633
  end
634
+ #
635
+ # Truncates data to fit into display area.
636
+ # Copied from listscrollable since we need to take care of left_margin
637
+ # 2011-10-6 This may need to be reflected in listbox and others FIXME
638
+ def truncate content #:nodoc:
639
+ #maxlen = @maxlen || @width-2
640
+ _maxlen = @maxlen || @width-@internal_width
641
+ _maxlen = @width-@internal_width if _maxlen > @width-@internal_width
642
+ _maxlen -= @left_margin
643
+ if !content.nil?
644
+ if content.length > _maxlen # only show maxlen
645
+ @longest_line = content.length if content.length > @longest_line
646
+ #content = content[@pcol..@pcol+_maxlen-1]
647
+ content.replace content[@pcol..@pcol+_maxlen-1]
648
+ else
649
+ # can this be avoided if pcol is 0 XXX
650
+ content.replace content[@pcol..-1] if @pcol > 0
651
+ end
652
+ end
653
+ content
654
+ end
633
655
 
634
656
  # print header row
635
657
  # allows user to override
636
658
  def print_header_row r, c, len, value, color, attr
637
659
  #acolor = $promptcolor
638
- @graphic.printstring r, c, "%-*s" % [len ,value], color, attr
660
+ @graphic.printstring r, c+@left_margin, "%-*s" % [len-@left_margin ,value], color, attr
639
661
  end
640
662
  def separator
641
663
  #return @separ if @separ
@@ -843,6 +865,8 @@ module RubyCurses
843
865
  # FIXME we can create this once and reuse
844
866
  #++
845
867
  def fire_action_event
868
+ return unless @list
869
+ return unless @table_row_sorter
846
870
  require 'rbcurse/ractionevent'
847
871
  # the header event must only be used if columns passed
848
872
  if header_row?
@@ -1023,6 +1047,25 @@ module RubyCurses
1023
1047
  @current_index == @max_index
1024
1048
  end
1025
1049
  end
1050
+ # for some compatibility with Table
1051
+ def set_data data, colnames_array
1052
+ set_content data
1053
+ columns = colnames_array
1054
+ end
1055
+ def get_column_name index
1056
+ @columns[index]
1057
+ end
1058
+ alias :column_name :get_column_name
1059
+ alias :column :get_column
1060
+ def method_missing(name, *args)
1061
+ name = name.to_s
1062
+ case name
1063
+ when 'cell_editing_allowed', 'editing_policy'
1064
+ # silently ignore to keep compatible with Table
1065
+ else
1066
+ raise NoMethodError, "Undefined method #{name} for TabularWidget"
1067
+ end
1068
+ end
1026
1069
 
1027
1070
  end # class tabluarw
1028
1071
 
@@ -1044,7 +1087,7 @@ App.new do
1044
1087
  b << ["russia","europe","a hot country" ]
1045
1088
  #b.column_width 2, 30
1046
1089
  end
1047
- s = TabularWidget.new @form , :row => 12, :col => 32 do |b|
1090
+ s = TabularWidget.new @form , :row => 12, :col => 32 do |b|
1048
1091
  b.columns = %w{ place continent text }
1049
1092
  b << ["india","asia","a warm country" ]
1050
1093
  b << ["japan","asia","a cool country" ]