rkumar-rbcurse 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,10 +83,6 @@ if $0 == __FILE__
83
83
  #
84
84
  ## key bindings fo texta
85
85
  # column widths
86
- $log.debug " tcm #{tcm.inspect}"
87
- $log.debug " tcms #{tcm.columns}"
88
- $log.debug " tcm0 #{tcm.column(0).identifier}"
89
- $log.debug " tcm0 #{tcm.column(0).width}"
90
86
  tcm.column(0).width 24
91
87
  tcm.column(1).width 5
92
88
  tcm.column(2).width 18
@@ -20,6 +20,7 @@ class TestTabbedPane
20
20
  width 50
21
21
  row 5
22
22
  col 10
23
+ button_type :ok
23
24
  end
24
25
  @tab1 = @tp.add_tab "&Language"
25
26
  f1 = @tab1.form
@@ -95,6 +96,7 @@ if $0 == __FILE__
95
96
  $log = Logger.new("view.log")
96
97
  $log.level = Logger::DEBUG
97
98
  n = TestTabbedPane.new
99
+ n.run
98
100
  rescue => ex
99
101
  ensure
100
102
  VER::stop_ncurses
@@ -13,23 +13,53 @@ require 'rbcurse/keylabelprinter'
13
13
  require 'rbcurse/applicationheader'
14
14
  require 'rbcurse/action'
15
15
 
16
+ # TODO move the csv to a database so you can update. this sucketh.
17
+ #
16
18
  class TodoList
17
19
  def initialize file
18
20
  @file = file
19
21
  end
20
22
  def load
21
- @todomap = YAML::load(File.open(@file));
23
+ #@todomap = YAML::load(File.open(@file));
24
+ @data =[]
25
+ @statuses=[]
26
+ @categories=[]
27
+ @modules=[]
28
+ require 'csv'
29
+ CSV::Reader.parse(File.open(@file, 'r')) do |row|
30
+ @data << row
31
+ $log.debug " #{row.inspect} "
32
+ @categories << row[0] unless @categories.include? row[0]
33
+ @statuses << row[4] unless @statuses.include? row[4]
34
+ @modules << row[1] unless @modules.include? row[1]
35
+ end
36
+ $log.debug " MOD #{@modules}"
22
37
  end
23
38
  def get_statuses
24
- @todomap['__STATUSES']
39
+ # @todomap['__STATUSES']
40
+ @statuses
25
41
  end
26
42
  def get_modules
27
- @todomap['__MODULES'].sort
43
+ #@todomap['__MODULES'].sort
44
+ @modules.sort
28
45
  end
29
46
  def get_categories
30
- @todomap.keys.delete_if {|k| k.match(/^__/) }
47
+ #@todomap.keys.delete_if {|k| k.match(/^__/) }
48
+ @categories
31
49
  end
32
50
  def get_tasks_for_category categ
51
+ @data.select do |row|
52
+ row[0] == categ
53
+ end
54
+ end
55
+ def insert_task_for_category task, categ
56
+ task[0] = categ
57
+ @data << task
58
+ end
59
+ def delete_task task
60
+ @data.delete task
61
+ end
62
+ def oldget_tasks_for_category categ
33
63
  c = @todomap[categ]
34
64
  d = []
35
65
  c.each_pair {|k,v|
@@ -44,6 +74,14 @@ class TodoList
44
74
  return d
45
75
  end
46
76
  def set_tasks_for_category categ, data
77
+ $log.debug " def set_tasks_for_category #{categ}, #{data.size} old #{@data.size}"
78
+ @data.delete_if { |row| row[0] == categ }
79
+ $log.debug " 2 def set_tasks_for_category #{categ}, #{data.size} old #{@data.size}"
80
+ data.each { |row| row[0] = categ }
81
+ @data.insert -1, *data
82
+ $log.debug " 3 def set_tasks_for_category #{categ}, #{data.size} old #{@data.size}"
83
+ end
84
+ def old_set_tasks_for_category categ, data
47
85
  d = {}
48
86
  data.each do |row|
49
87
  #key = row.delete_at 0
@@ -55,6 +93,7 @@ class TodoList
55
93
  $log.debug " NEW DATA #{categ}: #{data}"
56
94
  end
57
95
  def convert_to_text
96
+ =begin
58
97
  d = []
59
98
  cats = get_categories
60
99
  cats.each do |c|
@@ -65,8 +104,10 @@ class TodoList
65
104
  d << n
66
105
  end
67
106
  end
68
- File.open("todo.csv", "w") { |f| YAML.dump( d, f )}
107
+ #File.open("todo.yml", "w") { |f| YAML.dump( d, f )}
69
108
  buf =''
109
+ =end
110
+ d = @data
70
111
  require 'csv'
71
112
  CSV.open('todocsv.csv', 'w') do |writer|
72
113
  #writer << [nil, nil]
@@ -105,7 +146,7 @@ class TodoApp
105
146
  @window = VER::Window.root_window
106
147
  @form = Form.new @window
107
148
 
108
- @todo = TodoList.new "todo.yml"
149
+ @todo = TodoList.new "todocsv.csv"
109
150
  @todo.load
110
151
  end
111
152
  def make_popup table
@@ -218,14 +259,14 @@ class TodoApp
218
259
  data = todo.get_tasks_for_category 'TODO'
219
260
  @data = data
220
261
  $log.debug " data is #{data}"
221
- colnames = %w[ Module Prior Task Status]
262
+ colnames = %w[ Categ Module Prior Task Status]
222
263
 
223
264
  table_ht = 15
224
265
  atable = Table.new @form do
225
266
  name "tasktable"
226
267
  row r+2
227
268
  col c
228
- width 78
269
+ width 84
229
270
  height table_ht
230
271
  #title "A Table"
231
272
  #title_attrib (Ncurses::A_REVERSE | Ncurses::A_BOLD)
@@ -238,8 +279,8 @@ class TodoApp
238
279
  data = todo.get_tasks_for_category fld.getvalue;
239
280
  @data = data
240
281
  $log.debug " DATA is #{data.inspect} : #{data.length}"
241
- data = [[nil, 5, "NEW ", "TODO", Time.now]] if data.nil? or data.empty? or data.size == 0
242
- $log.debug " DATA is #{data.inspect} : #{data.length}"
282
+ data = [['FIXME',nil, 5, "NEW ", "TODO", Time.now]] if data.nil? or data.empty? or data.size == 0
283
+ #$log.debug " DATA is #{data.inspect} : #{data.length}"
243
284
  atable.table_model.data = data
244
285
  end
245
286
 
@@ -247,12 +288,15 @@ class TodoApp
247
288
  #
248
289
  ## key bindings fo atable
249
290
  # column widths
250
- $log.debug " tcm #{tcm.inspect}"
251
- $log.debug " tcms #{tcm.columns}"
252
- tcm.column(0).width 8
253
- tcm.column(1).width 5
254
- tcm.column(2).width 50
255
- tcm.column(3).width 8
291
+ #$log.debug " tcm #{tcm.inspect}"
292
+ #$log.debug " tcms #{tcm.columns}"
293
+ tcm.column(0).width 5
294
+ tcm.column(0).editable false
295
+ tcm.column(1).width 8
296
+ tcm.column(2).width 5
297
+ tcm.column(3).width 50
298
+ tcm.column(3).edit_length 80
299
+ tcm.column(4).width 8
256
300
  app = self
257
301
  atable.configure() do
258
302
  #bind_key(330) { atable.remove_column(tcm.column(atable.focussed_col)) rescue "" }
@@ -303,11 +347,11 @@ class TodoApp
303
347
  atable.set_default_cell_renderer_for_class "Float", num_renderer
304
348
  atable.set_default_cell_renderer_for_class "TrueClass", bool_renderer
305
349
  atable.set_default_cell_renderer_for_class "FalseClass", bool_renderer
306
- atable.get_table_column_model.column(3).cell_editor = combo_editor
307
- atable.get_table_column_model.column(0).cell_editor = combo_editor1
350
+ atable.get_table_column_model.column(4).cell_editor = combo_editor
351
+ atable.get_table_column_model.column(1).cell_editor = combo_editor1
308
352
  ce = atable.get_default_cell_editor_for_class "String"
309
353
  # increase the maxlen of task
310
- ce.component.maxlen = 80
354
+ # ce.component.maxlen = 80 # this is obsolete, use edit_length
311
355
  # I want up and down to go up and down rows inside the combo box, i can use M-down for changing.
312
356
  combo_editor.component.unbind_key(KEY_UP)
313
357
  combo_editor.component.unbind_key(KEY_DOWN)
@@ -416,17 +460,21 @@ class TodoApp
416
460
  amod = mods[@mb.selected_index]
417
461
  row = atable.focussed_row
418
462
  d = todo.get_tasks_for_category amod
463
+ $log.debug " retrieved #{d.size} rows for #{amod}"
419
464
  r = []
420
- tcm = atable.get_table_column_model
465
+ tcm = atable.table_column_model
421
466
  tcm.each_with_index do |acol, colix|
422
467
  r << atable.get_value_at(row, colix)
423
468
  end
424
469
  # here i ignore the 5th row tht coud have been added
425
470
  r << Time.now
426
471
  d << r
472
+ $log.debug " sending #{d.size} rows for #{amod}"
427
473
  todo.set_tasks_for_category amod, d
474
+ $log.debug " MOVE #{data.size} rows for #{categ.getvalue}"
428
475
  tm = atable.table_model
429
476
  ret = tm.delete_at row
477
+ $log.debug " MOVE after del #{data.size} rows for #{categ.getvalue}"
430
478
  todo.set_tasks_for_category categ.getvalue, data
431
479
  alert("Moved row #{row} to #{amod}.")
432
480
  }
@@ -469,15 +517,17 @@ class TodoApp
469
517
  #@new_act = Action.new("New Row", "mnemonic"=>"N") {
470
518
  @new_act = Action.new("&New Row") {
471
519
  mod = nil
520
+ cat = 'TODO'
472
521
  cc = atable.get_table_column_model.column_count
473
522
  if atable.row_count < 1
474
523
  frow = 0
475
524
  else
476
525
  frow = atable.focussed_row
477
526
  #frow += 1 # why ?
478
- mod = atable.get_value_at(frow,0) unless frow.nil?
527
+ cat = atable.get_value_at(frow,0) unless frow.nil?
528
+ mod = atable.get_value_at(frow,1) unless frow.nil?
479
529
  end
480
- tmp = [mod, 5, "", "TODO", Time.now]
530
+ tmp = [cat,mod, 5, "", "TODO", Time.now]
481
531
  tm = atable.table_model
482
532
  tm.insert frow, tmp
483
533
  atable.set_focus_on frow
@@ -488,7 +538,7 @@ class TodoApp
488
538
  @save_cmd = lambda {
489
539
  todo.set_tasks_for_category categ, data
490
540
  todo.dump
491
- alert("Rewritten yaml file")
541
+ alert("Rewritten csv file")
492
542
  }
493
543
  @del_cmd = lambda {
494
544
  row = atable.focussed_row
@@ -0,0 +1,28 @@
1
+ FIXME,MSGBOX,5,Confirm dialog: box vertical line overwritten in 2 spots,TODO
2
+ FIXME,MSGBOX,5,Confirm dialog: use normal key as hotkey also,TODO,Tue Jan 20 11:44:49 +0530 2009
3
+ FIXME,MSGBOX,5,Confirm dialog: arrow keys not navigating anylonger,TODO,Tue Jan 20 11:45:27 +0530 2009
4
+ FIXME,GEN,9,Message Box sizing,TODO,Thu Jan 22 20:39:21 +0530 2009
5
+ DONE,LIST,5,case insensitive char search in list and combo,TESTED,Sat Feb 21 20:43:05 +0530 2009
6
+ DONE,TABLE,5,increase the maxlen of this field please. Let us see how it goes.,TESTED
7
+ DONE,TABLE,5,Can we disable down arrow in Chkbox in table?,TESTED,Mon Jan 19 00:00:00 +0530 2009
8
+ DONE,TABLE,0,editing on enter,TESTED,Mon Jan 19 01:37:00 +0530 2009
9
+ DONE,TABLE,5,cell editors pcol is not being reset each time,TESTED,Mon Jan 19 17:47:00 +0530 2009
10
+ DONE,TABLE,5,Use TAB for intercell navig. use M-TAB for next f,TESTED,Tue Jan 20 00:38:19 +0530 2009
11
+ DONE,TABLE,5,Searching,TESTED,Sat Feb 21 20:42:10 +0530 2009
12
+ DONE,TABLE,3,Columns editable or not,TESTED,Sat Feb 21 20:43:10 +0530 2009
13
+ DONE,TABLE,1,Any way to start a table with no data and pop late,TODO,Sat Feb 21 20:43:33 +0530 2009
14
+ DONE,GEN,5,Make widget of Keylabelprinter,TESTED,Tue Jan 20 00:38:43 +0530 2009
15
+ DONE,GEN,5,Added Action class shared by Button Menuitem ,TESTED,Thu Jan 22 18:08:28 +0530 2009
16
+ DONE,GEN,5,Added PopupMenu 2009-01-22 18:09 ,TESTED,Thu Jan 22 18:09:34 +0530 2009
17
+ DONE,LIST,0,call on_enter and on_leave of component,TOTEST,Sun Feb 22 12:19:38 +0530 2009
18
+ TODO,TABLE,1,table.set_data should check if models already created.,TODO
19
+ TODO,TABLE,5,"Set column_class in TableColumn, to avoid hassles",TODO
20
+ TODO,TABLE,2,Table sorting and filtering is required - using VIEW,TODO
21
+ TODO,TABLE,5,Table height and col widths auto sizing or FILLING extra space.,TODO
22
+ TODO,TEXTAREA,9,"Textarea: wrap options NONE, COLUMN",TODO,Tue Jan 20 01:04:15 +0530 2009
23
+ TODO,GEN,5,"Modified should check if value changed, not UP etc",TOTEST
24
+ TODO,GEN,5,Give a decent FileChooser and FileSaver,TODO
25
+ TODO,GEN,5,Focus Traversable vs focusable,TODO
26
+ TODO,GEN,5,Action class: fire event for listeners,TODO,Thu Jan 22 20:09:50 +0530 2009
27
+ TODO,FIELD,5,Field: OVERWRITE Mode,TODO
28
+ TODO,FIELD,5,Field: Auto-skip when reaching end of maxlen,TODO
@@ -3,5 +3,5 @@ require 'ver/window'
3
3
  require 'rbcurse/rwidget'
4
4
  require 'rbcurse/rdialogs'
5
5
  class Rbcurse
6
- VERSION = '0.1.0'
6
+ VERSION = '0.1.2'
7
7
  end
@@ -1,3 +1,6 @@
1
+ require 'rbcurse/listselectable'
2
+ ##
3
+ # Added ListSelectionEvents on 2009-02-13 23:33
1
4
  module RubyCurses
2
5
  class DefaultListSelectionModel
3
6
  include EventHandler
@@ -9,10 +12,15 @@ module RubyCurses
9
12
  @anchor_selection_index = -1
10
13
  @lead_selection_index = -1
11
14
  @selection_mode = :MULTIPLE
15
+ $log.debug " created DefaultListSelectionModel XXX"
12
16
  end
13
17
 
14
18
  def clear_selection
19
+ ix0 = @selected_indices.first
20
+ ix1 = @selected_indices.last
15
21
  @selected_indices=[]
22
+ lse = ListSelectionEvent.new(ix0, ix1, self, :DELETE)
23
+ fire_handler :LIST_SELECTION_EVENT, lse
16
24
  end
17
25
  def is_selected_index ix
18
26
  @selected_indices.include? ix
@@ -28,17 +36,23 @@ module RubyCurses
28
36
  end
29
37
  ## TODO should go in sorted, and no dupes
30
38
  def add_selection_interval ix0, ix1
39
+ $log.debug " def add_selection_interval #{ix0}, ix1"
31
40
  if @selection_mode != :MULTIPLE
32
41
  clear_selection
33
42
  end
34
43
  @anchor_selection_index = ix0
35
44
  @lead_selection_index = ix1
36
45
  ix0.upto(ix1) {|i| @selected_indices << i unless @selected_indices.include? i }
46
+ lse = ListSelectionEvent.new(ix0, ix1, self, :INSERT)
47
+ fire_handler :LIST_SELECTION_EVENT, lse
48
+ $log.debug " DLSM firing LIST_SELECTION EVENT #{lse}"
37
49
  end
38
50
  def remove_selection_interval ix0, ix1
39
51
  @anchor_selection_index = ix0
40
52
  @lead_selection_index = ix1
41
53
  @selected_indices.delete_if {|x| x >= ix0 and x <= ix1}
54
+ lse = ListSelectionEvent.new(ix0, ix1, self, :DELETE)
55
+ fire_handler :LIST_SELECTION_EVENT, lse
42
56
  end
43
57
  def insert_index_interval ix0, len
44
58
  @anchor_selection_index = ix0
@@ -93,6 +93,13 @@ module RubyCurses
93
93
  graphic.printstring r, c, str % [len, _value], @color_pair,@attr
94
94
  r += 1
95
95
  end
96
+ =begin
97
+ if @parent.search_found_ix == row_index
98
+ if !@parent.find_offset.nil?
99
+ graphic.mvchgat(y=r, x=@parent.find_offset, @parent.find_offset1, Ncurses::A_NORMAL, $reversecolor, nil)
100
+ end
101
+ end
102
+ =end
96
103
  end
97
104
  # ADD HERE
98
105
  end
@@ -5,14 +5,17 @@ module RubyCurses
5
5
  # any changes to the vars after construction won't have an effect.
6
6
  def install_list_keys
7
7
  @KEY_ROW_SELECTOR ||= ?\C-x
8
+ @KEY_BLOCK_SELECTOR ||= ?\M-x
8
9
  @KEY_GOTO_TOP ||= ?\M-0
9
10
  @KEY_GOTO_BOTTOM ||= ?\M-9
10
- @KEY_ASK_FIND_FORWARD ||= ?\M-f
11
- @KEY_ASK_FIND_BACKWARD ||= ?\M-F
12
- @KEY_FIND_NEXT ||= ?\M-g
13
- @KEY_FIND_PREV ||= ?\M-G
11
+ #@KEY_ASK_FIND_FORWARD ||= ?\M-f
12
+ #@KEY_ASK_FIND_BACKWARD ||= ?\M-F
13
+ #@KEY_FIND_NEXT ||= ?\M-g
14
+ #@KEY_FIND_PREV ||= ?\M-G
14
15
  @KEY_SCROLL_FORWARD ||= ?\C-n
15
16
  @KEY_SCROLL_BACKWARD ||= ?\C-p
17
+ @KEY_SCROLL_RIGHT ||= ?\M-8
18
+ @KEY_SCROLL_LEFT ||= ?\M-7
16
19
 
17
20
  @KEY_CLEAR_SELECTION ||= ?\M-e
18
21
  @KEY_PREV_SELECTION ||= ?\M-"
@@ -8,6 +8,7 @@
8
8
  # @pcol (used for horiz scrolling, starts at 0)
9
9
  #
10
10
  module ListScrollable
11
+ attr_reader :search_found_ix, :find_offset, :find_offset1
11
12
  def previous_row
12
13
  @oldrow = @current_index
13
14
  @current_index -= 1 if @current_index > 0
@@ -61,9 +62,9 @@ module ListScrollable
61
62
  def bounds_check
62
63
  h = scrollatrow()
63
64
  rc = row_count
64
- $log.debug " PRE CURR:#{@current_index}, TR: #{@toprow} RC: #{rc} H:#{h}"
65
+ #$log.debug " PRE CURR:#{@current_index}, TR: #{@toprow} RC: #{rc} H:#{h}"
65
66
  @current_index = 0 if @current_index < 0 # not lt 0
66
- @current_index = rc-1 if @current_index >= rc # not gt rowcount
67
+ @current_index = rc-1 if @current_index >= rc and rc>0 # not gt rowcount
67
68
  @toprow = rc-h-1 if rc > h and @toprow > rc - h - 1 # toprow shows full page if possible
68
69
  # curr has gone below table, move toprow forward
69
70
  if @current_index - @toprow > h
@@ -74,11 +75,12 @@ module ListScrollable
74
75
  end
75
76
  #$log.debug " POST CURR:#{@current_index}, TR: #{@toprow} RC: #{rc} H:#{h}"
76
77
  if @oldrow != @current_index
77
- $log.debug "going to call on leave and on enter"
78
+ #$log.debug "going to call on leave and on enter"
78
79
  on_leave_row @oldrow if respond_to? :on_leave_row # to be defined by widget that has included this
79
80
  on_enter_row @current_index if respond_to? :on_enter_row # to be defined by widget that has included this
80
81
  end
81
82
  set_form_row
83
+ #set_form_col 0 # added 2009-02-15 23:33 # this works for lists but we don't want this in TextArea's
82
84
  @repaint_required = true
83
85
  end
84
86
  # the cursor should be appropriately positioned
@@ -129,13 +131,13 @@ module ListScrollable
129
131
  when KEY_UP
130
132
  #select_prev_row
131
133
  #up
132
- $log.debug " GOT KEY UP NEW SCROLL"
134
+ #$log.debug " GOT KEY UP NEW SCROLL"
133
135
  previous_row
134
136
  when KEY_LEFT
135
137
  when KEY_RIGHT
136
138
  when KEY_DOWN
137
139
  #down
138
- $log.debug " GOT KEY DOWN NEW SCROLL"
140
+ #$log.debug " GOT KEY DOWN NEW SCROLL"
139
141
  next_row
140
142
  when KEY_ENTER, 10, 13
141
143
  if respond_to? :fire
@@ -203,14 +205,149 @@ module ListScrollable
203
205
  sar = scrollatrow + 1
204
206
  @toprow = (@current_index / sar) * sar
205
207
 
206
- $log.debug "1 set_focus #{total}, sar #{sar}, toprow #{@toprow}, current_index #{@current_index}"
208
+ #$log.debug "1 set_focus #{total}, sar #{sar}, toprow #{@toprow}, current_index #{@current_index}"
207
209
  if total - @toprow < sar
208
210
  @toprow = (total - sar)
209
211
  end
210
- $log.debug "2 set_focus #{total}, sar #{sar}, toprow #{@toprow}, current_index #{@current_index}"
212
+ #$log.debug "2 set_focus #{total}, sar #{sar}, toprow #{@toprow}, current_index #{@current_index}"
211
213
  set_form_row # 2009-01-17 12:44
212
214
  @repaint_required = true
213
215
  #bounds_check
214
216
  end
217
+ def install_keys
218
+ =begin
219
+ @KEY_ASK_FIND_FORWARD ||= ?\M-f
220
+ @KEY_ASK_FIND_BACKWARD ||= ?\M-F
221
+ @KEY_FIND_NEXT ||= ?\M-g
222
+ @KEY_FIND_PREV ||= ?\M-G
223
+ =end
224
+ @KEY_ASK_FIND ||= ?\M-f
225
+ @KEY_FIND_MORE ||= ?\M-g
226
+ end
227
+ def ask_search
228
+ options = ["Search backwards", "case insensitive", "Wrap around"]
229
+ sel,regex,hash = get_string_with_options("Enter regex to search", 20, @last_regex||"", "checkboxes"=>options, "checkbox_defaults"=>[@search_direction_prev,@search_case,@search_wrap])
230
+ return if sel != 0
231
+ @search_direction_prev = hash[options[0]]
232
+ @search_case = hash[options[1]]
233
+ @search_wrap = hash[options[2]]
234
+ if @search_direction_prev == true
235
+ ix = _find_prev regex, @current_index
236
+ else
237
+ ix = _find_next regex, @current_index
238
+ end
239
+ if ix.nil?
240
+ alert("No matching data for: #{regex}")
241
+ else
242
+ set_focus_on(ix)
243
+ set_form_col @find_offset1
244
+ @cell_editor.component.curpos = (@find_offset||0) if @cell_editing_allowed
245
+ end
246
+ end
247
+ def find_more
248
+ if @search_direction_prev
249
+ find_prev
250
+ else
251
+ find_next
252
+ end
253
+ end
254
+ # find forwards
255
+ # Using this to start a search or continue search
256
+ def _find_next regex=@last_regex, start = @search_found_ix
257
+ raise "No previous search" if regex.nil?
258
+ #$log.debug " _find_next #{@search_found_ix} : #{@current_index}"
259
+ fend = @list.size-1
260
+ if start != fend
261
+ start += 1 unless start == fend
262
+ @last_regex = regex
263
+ @search_start_ix = start
264
+ regex = Regexp.new(regex, Regexp::IGNORECASE) if @search_case
265
+ start.upto(fend) do |ix|
266
+ row = @list[ix]
267
+ m=row.match(regex)
268
+ if !m.nil?
269
+ @find_offset = m.offset(0)[0]
270
+ @find_offset1 = m.offset(0)[1]
271
+ @search_found_ix = ix
272
+ return ix
273
+ end
274
+ end
275
+ end
276
+ fend = start-1
277
+ start = 0
278
+ if @search_wrap
279
+ start.upto(fend) do |ix|
280
+ row = @list[ix]
281
+ m=row.match(regex)
282
+ if !m.nil?
283
+ @find_offset = m.offset(0)[0]
284
+ @find_offset1 = m.offset(0)[1]
285
+ @search_found_ix = ix
286
+ return ix
287
+ end
288
+ end
289
+ end
290
+ return nil
291
+ end
292
+ def find_next
293
+ ix = _find_next
294
+ regex = @last_regex
295
+ if ix.nil?
296
+ alert("No more matching data for: #{regex}")
297
+ else
298
+ set_focus_on(ix)
299
+ set_form_col @find_offset1
300
+ @cell_editor.component.curpos = (@find_offset||0) if @cell_editing_allowed
301
+ end
302
+ end
303
+ def find_prev
304
+ ix = _find_prev
305
+ regex = @last_regex
306
+ if ix.nil?
307
+ alert("No previous matching data for: #{regex}")
308
+ else
309
+ set_focus_on(ix)
310
+ set_form_col @find_offset
311
+ @cell_editor.component.curpos = (@find_offset||0) if @cell_editing_allowed
312
+ end
313
+ end
314
+ ##
315
+ # find backwards
316
+ # Using this to start a search or continue search
317
+ def _find_prev regex=@last_regex, start = @search_found_ix
318
+ raise "No previous search" if regex.nil?
319
+ #$log.debug " _find_prev #{@search_found_ix} : #{@current_index}"
320
+ if start != 0
321
+ start -= 1 unless start == 0
322
+ @last_regex = regex
323
+ @search_start_ix = start
324
+ regex = Regexp.new(regex, Regexp::IGNORECASE) if @search_case
325
+ start.downto(0) do |ix|
326
+ row = @list[ix]
327
+ m=row.match(regex)
328
+ if !m.nil?
329
+ @find_offset = m.offset(0)[0]
330
+ @find_offset1 = m.offset(0)[1]
331
+ @search_found_ix = ix
332
+ return ix
333
+ end
334
+ end
335
+ end
336
+ fend = start-1
337
+ start = @list.size-1
338
+ if @search_wrap
339
+ start.downto(fend) do |ix|
340
+ row = @list[ix]
341
+ m=row.match(regex)
342
+ if !m.nil?
343
+ @find_offset = m.offset(0)[0]
344
+ @find_offset1 = m.offset(0)[1]
345
+ @search_found_ix = ix
346
+ return ix
347
+ end
348
+ end
349
+ end
350
+ return nil
351
+ end
215
352
 
216
353
  end