Class: RubyCurses::List

Inherits:
Widget show all
Extended by:
Forwardable
Includes:
ListScrollable, NewListSelectable
Defined in:
lib/rbcurse/core/widgets/rlist.rb

Overview

scrollable, selectable list of items

- @selected contains indices of selected objects.

A readonly control for displaying a list of data or values. Although user editing is not allowed, but the list may be repopulated as in a directory listing, or a list dependent on some other control’s value. This is not a drop-in replacement for Listbox as it drops many methods that are redundant. Default selection is single, as opposed to Listbox.

Since:

  • 1.4.1 UNTESTED

Instance Attribute Summary collapse

Attributes included from ListScrollable

#find_offset, #find_offset1, #search_found_ix, #show_caret

Attributes inherited from Widget

#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #key_label, #parent_component, #row_offset, #rows_panned, #state

selection related collapse

Instance Method Summary collapse

Methods included from NewListSelectable

#add_selection_interval, #add_to_selection, #ask_select, #clear_selection, #get_matching_indices, #insert_index_interval, #invert_row_selection, #invert_selection, #is_row_selected, #list_bindings, #list_init_vars, #paint_selector, #remove_selection_interval, #select_all, #select_values, #selected_rows, #toggle_row_selection, #unselect_values

Methods included from ListScrollable

#_convert_index_to_printable_row, #_convert_index_to_visible_row, #_find_next, #_find_prev, #ask_search, #bounds_check, #find_more, #find_next, #find_prev, #focussed_index, #forward_char, #forward_word, #goto_bottom, #goto_last_position, #goto_top, #highlight_focussed_row, #install_keys, #is_visible?, #next_match, #next_row, #previous_row, #scroll_backward, #scroll_forward, #scroll_left, #scroll_right, #selected_item, #set_focus_on, #set_form_row, #set_selection_for_char, #show_caret_func

Methods inherited from Widget

#action_manager, #changed, #click, #color_pair, #command, #destroy, #enter, #event_list, #focus, #get_preferred_size, #getvalue_for_paint, #height, #height=, #hide, #leave, #modified?, #move, #on_leave, #override_graphic, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #set_buffer_modified, #set_buffering, #set_form, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width, #width=

Methods included from Io

#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rbgetstr, #warn

Methods included from Utils

#OLDdefine_key, #_process_key, #bind_key, #bind_keys, #clean_string!, #define_key, #define_prefix_command, #display_app_help, #get_attrib, #get_color, #keycode_tos, #last_line, #one_line_window, #parse_formatted_text, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #wrap_text

Methods included from ConfigSetup

#cget, #config_setup, #configure, #variable_set

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Constructor Details

#initialize(form = nil, config = {}, &block) ⇒ List

basic listbox constructor

Since:

  • 1.4.1 UNTESTED



81
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
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rbcurse/core/widgets/rlist.rb', line 81

def initialize form=nil, config={}, &block
  @focusable = true
  @editable = false
  @sanitization_required = true # cleanup control and non print chars
  @truncation_required = true
  @suppress_borders = false #to_print_borders = 1
  #@row_selected_symbol = '' # thi sprevents default value from being set
  @row = 0
  @col = 0
  # data of listbox this is not an array, its a pointer to the  listdatamodel
  @list = nil 
  # any special attribs such as status to be printed in col1, or color (selection)
  @list_attribs = {}
  @current_index = 0
  @selected_indices = []
  @selected_index = nil
  @row_offset = @col_offset = 1
  @should_show_focus = true # Here's its on since the cellrenderer will show it on repaint
  @one_key_selection = false # use vim keys
  @selection_mode = :multiple # default is multiple, anything else given becomes single
  super
  @_events.push(*[:ENTER_ROW, :LEAVE_ROW, :LIST_SELECTION_EVENT, :PRESS])
  # I have moved this here so user can override keys.
  map_keys unless @keys_mapped
  @win = @graphic    # 2010-01-04 12:36 BUFFERED  replace form.window with graphic
  @win_left = 0
  @win_top = 0

  init_vars
  @internal_width = 2
  #@internal_width = 0 if @suppress_borders # NOTE it is 1 in bordertitle
  bordertitle_init

  if @list && !@selected_index.nil?  # XXX
    set_focus_on @selected_index # the new version
  end
  init_actions
end

Instance Attribute Details

#current_indexObject

dsl_accessor :default_values # array of default values dsl_accessor :is_popup # if it is in a popup and single select, selection closes

Since:

  • 1.4.1 UNTESTED



52
53
54
# File 'lib/rbcurse/core/widgets/rlist.rb', line 52

def current_index
  @current_index
end

#one_key_selectionObject

please set these in he constructor block. Settin them later will have no effect since i would have bound them to actions

Since:

  • 1.4.1 UNTESTED



64
65
66
# File 'lib/rbcurse/core/widgets/rlist.rb', line 64

def one_key_selection
  @one_key_selection
end

#selected_indexObject

index of selected row

Since:

  • 1.4.1 UNTESTED



73
74
75
# File 'lib/rbcurse/core/widgets/rlist.rb', line 73

def selected_index
  @selected_index
end

#toprowObject (readonly)

dsl_accessor :list # the array of data to be sent by user

Since:

  • 1.4.1 UNTESTED



49
50
51
# File 'lib/rbcurse/core/widgets/rlist.rb', line 49

def toprow
  @toprow
end

Instance Method Details

#[](off0) ⇒ Object

get element at

Parameters:

  • index (Fixnum)

    for element

Returns:

Since:

  • 1.2.0 2010-09-06 14:33 making life easier for others.



205
206
207
# File 'lib/rbcurse/core/widgets/rlist.rb', line 205

def [](off0)
  @list[off0]
end

#append(text) ⇒ Object

Since:

  • 1.4.1 UNTESTED



230
231
232
233
234
# File 'lib/rbcurse/core/widgets/rlist.rb', line 230

def append text
  @list.push text
  @widget_scrolled = true
  @repaint_required = true
end

#ask_search_backwardObject

gets string to search and calls data models find prev

Since:

  • 1.4.1 UNTESTED



356
357
358
359
360
361
362
363
364
365
# File 'lib/rbcurse/core/widgets/rlist.rb', line 356

def ask_search_backward
  regex =  get_string("Enter regex to search (backward)")
  @last_regex = regex
  ix = @list.find_prev regex, @current_index
  if ix.nil?
    alert("No matching data for: #{regex}")
  else
    set_focus_on(ix)
  end
end

#ask_search_forwardObject

Since:

  • 1.4.1 UNTESTED



346
347
348
349
350
351
352
353
354
# File 'lib/rbcurse/core/widgets/rlist.rb', line 346

def ask_search_forward
    regex =  get_string("Enter regex to search")
    ix = @list.find_match regex
    if ix.nil?
      alert("No matching data for: #{regex}")
    else
      set_focus_on(ix)
    end
end

#ask_selection_for_charObject

get a keystroke from user and go to first item starting with that key

Since:

  • 1.4.1 UNTESTED



339
340
341
342
343
344
345
# File 'lib/rbcurse/core/widgets/rlist.rb', line 339

def ask_selection_for_char
  ch = @graphic.getch
  if ch < 0 || ch > 255
    return :UNHANDLED
  end
  ret = set_selection_for_char ch.chr
end

#cell_renderer(*val) ⇒ Object

getter and setter for cell_renderer NOTE: due to our optimization of not repainting unless data has changed or scrolling has happened, highlighting focus will repaint the row if you’ve colored it. In that case, set show_show_focus to false

Since:

  • 1.4.1 UNTESTED



396
397
398
399
400
401
402
# File 'lib/rbcurse/core/widgets/rlist.rb', line 396

def cell_renderer(*val)
  if val.empty?
    @cell_renderer ||= create_default_cell_renderer
  else
    @cell_renderer = val[0] 
  end
end

#convert_value_to_text(value, crow) ⇒ Object

the idea here is to allow users who subclass Listbox to easily override parts of the cumbersome repaint method. This assumes your List has some data, but you print a lot more. Now you don’t need to change the data in the renderer, or keep formatted data in the list itself. e.g. @list contains file names, or File objects, and this converts to a long listing. If the renderer did that, the truncation would be on wrong data.

Since:

  • 1.2.0



522
523
524
525
526
527
528
529
# File 'lib/rbcurse/core/widgets/rlist.rb', line 522

def convert_value_to_text value, crow
  case value
  when TrueClass, FalseClass
    value
  else
    value.to_s if value
  end
end

#create_default_cell_rendererObject

Since:

  • 1.4.1 UNTESTED



403
404
405
406
# File 'lib/rbcurse/core/widgets/rlist.rb', line 403

def create_default_cell_renderer
  return ListCellRenderer.new "", {"color"=>@color, "bgcolor"=>@bgcolor, "parent" => self, "display_length"=> @width-@internal_width-@left_margin}
  #return BasicListCellRenderer.new "", {"color"=>@color, "bgcolor"=>@bgcolor, "parent" => self, "display_length"=> @width-2-@left_margin}
end

#current_valueObject Also known as: current_row, text

return object under cursor Note: this should not be confused with selected row/s. User may not have selected this. This is only useful since in some demos we like to change a status bar as a user scrolls down

Since:

  • 1.2.0 2010-09-06 14:33 making life easier for others.



212
213
214
# File 'lib/rbcurse/core/widgets/rlist.rb', line 212

def current_value
  @list[@current_index]
end

#data=(val) ⇒ Object

conv method to insert data, trying to keep names same across along with Tabular, TextView, TextArea and listbox. Don;t use this till i am certain.

Since:

  • 1.4.1 UNTESTED



198
199
200
# File 'lib/rbcurse/core/widgets/rlist.rb', line 198

def data=(val)
  list(val)
end

#fire_action_eventObject

triggered on hitting ENTER button

Since:

  • 1.4.1 UNTESTED



334
335
336
337
# File 'lib/rbcurse/core/widgets/rlist.rb', line 334

def fire_action_event
  require 'rbcurse/core/include/ractionevent'
  fire_handler :PRESS, ActionEvent.new(self, :PRESS, text)
end

#get_contentObject

START FOR scrollable ###

Since:

  • 1.4.1 UNTESTED



240
241
242
# File 'lib/rbcurse/core/widgets/rlist.rb', line 240

def get_content
  @list 
end

#get_selected_indicesObject

Returns selected indices Indices are often required since the renderer may modify the values displayed

Since:

  • 1.4.1 UNTESTED



668
# File 'lib/rbcurse/core/widgets/rlist.rb', line 668

def get_selected_indices; @selected_indices; end

#get_selected_valuesObject Also known as: selected_values

Returns selected values

Since:

  • 1.4.1 UNTESTED



672
673
674
675
676
# File 'lib/rbcurse/core/widgets/rlist.rb', line 672

def get_selected_values
  selected = []
  @selected_indices.each { |i| selected << @list[i] }
  return selected
end

#get_windowObject

:nodoc:

Since:

  • 1.4.1 UNTESTED



243
244
245
# File 'lib/rbcurse/core/widgets/rlist.rb', line 243

def get_window #:nodoc:
  @graphic 
end

#getvalueObject

END FOR scrollable ### override widgets text returns indices of selected rows

Since:

  • 1.4.1 UNTESTED



249
250
251
# File 'lib/rbcurse/core/widgets/rlist.rb', line 249

def getvalue
  selected_rows
end

#goto_next_selectionObject

Since:

  • 1.4.1 UNTESTED



651
652
653
654
655
656
657
# File 'lib/rbcurse/core/widgets/rlist.rb', line 651

def goto_next_selection
  return if selected_rows().length == 0 
  row = selected_rows().sort.find { |i| i > @current_index }
  row ||= @current_index
  @current_index = row
  @repaint_required = true # fire list_select XXX
end

#goto_prev_selectionObject

Since:

  • 1.4.1 UNTESTED



658
659
660
661
662
663
664
# File 'lib/rbcurse/core/widgets/rlist.rb', line 658

def goto_prev_selection
  return if selected_rows().length == 0 
  row = selected_rows().sort{|a,b| b <=> a}.find { |i| i < @current_index }
  row ||= @current_index
  @current_index = row
  @repaint_required = true # fire list_select XXX
end

#handle_key(ch) ⇒ Object

Listbox

Since:

  • 1.4.1 UNTESTED



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/rbcurse/core/widgets/rlist.rb', line 253

def handle_key(ch) #:nodoc:
  #map_keys unless @keys_mapped
  @current_index ||= 0
  @toprow ||= 0
  #h = scrollatrow()
  #rc = row_count
  #$log.debug " basiclistbox got ch #{ch}"
  #$log.debug " when kps #{@KEY_PREV_SELECTION}  "
  case ch
  #when 32
    #return if is_popup and @selection_mode == 'single' # not allowing select this way since there will be a difference 
    #toggle_row_selection @current_index #, @current_index
    #@repaint_required = true
  #when 0 # c-space
    #add_to_selection
  #when @KEY_NEXT_SELECTION # ?'
    #$log.debug "insdie next selection"
    #@oldrow = @current_index
    #do_next_selection 
    #bounds_check
  #when @KEY_PREV_SELECTION # ?"
    #@oldrow = @current_index
    #$log.debug "insdie prev selection"
    #do_prev_selection 
    #bounds_check
  #when @KEY_CLEAR_SELECTION
    #clear_selection 
    #@repaint_required = true
  when 27, ?\C-c.getbyte(0)
    $multiplier = 0
  when @KEY_BLOCK_SELECTOR
    mark_block #selection
  #when ?\C-u.getbyte(0)
    # multiplier. Series is 4 16 64
    # TESTING @multiplier = (@multiplier == 0 ? 4 : @multiplier *= 4)
  #  return 0
  #when ?\C-c.getbyte(0)
    #@multiplier = 0
    #return 0
  else
    # this has to be fixed, if compo does not handle key it has to continue into next part FIXME
    ret = :UNHANDLED # changed on 2009-01-27 13:14 not going into unhandled, tab not released
    if ret == :UNHANDLED
      # beware one-key eats up numbers. we'll be wondering why
      if @one_key_selection
        case ch
        #when ?A.getbyte(0)..?Z.getbyte(0), ?a.getbyte(0)..?z.getbyte(0), ?0.getbyte(0)..?9.getbyte(0)
        when ?A.getbyte(0)..?Z.getbyte(0), ?a.getbyte(0)..?z.getbyte(0)
          # simple motion, key press defines motion
          ret = set_selection_for_char ch.chr
        else
          ret = process_key ch, self
          @multiplier = 0
          # if no block associated with :PRESS (KEY_ENTER) lets allow the form to use ENTER
          # This is for default buttons. Added NO_BLOCK 2011-12-2 
          # 2011-12-2 11:54 PM this was resulting in no repaint even
          # when symbols were being executed??
          # Its risky since symbol can call something which returns
          # UNHNDLED or NO_BLOCK even tho' it executed.
          return :UNHANDLED if ret == :UNHANDLED #|| ret == :NO_BLOCK
        end
      else
        # no motion on single key, we can freak out like in vim, pref f <char> for set_selection
        case ch
        when ?0.getbyte(0)..?9.getbyte(0)
          $multiplier *= 10 ; $multiplier += (ch-48)
          #$log.debug " setting mult to #{$multiplier} in list "
          return 0
        end
        ret = process_key ch, self
        # if no block associated with :PRESS (KEY_ENTER) lets allow the form to use ENTER
        # This is for default buttons. Added NO_BLOCK 2011-12-2 
        return :UNHANDLED if ret == :UNHANDLED #|| ret == :NO_BLOCK1
      end
    end
  end
  $multiplier = 0
end

#highlight_selected_row(r = nil, c = nil, acolor = nil) ⇒ Object

Since:

  • 1.4.1 UNTESTED



492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/rbcurse/core/widgets/rlist.rb', line 492

def highlight_selected_row r=nil, c=nil, acolor=nil
  return unless @selected_index # no selection
  r = _convert_index_to_printable_row(@selected_index) unless r
  return unless r # not on screen
  unless c
    _r, c = rowcol
  end
  acolor ||= get_color $promptcolor, @selected_color, @selected_bgcolor
  att = FFI::NCurses::A_REVERSE
  att = get_attrib(@selected_attrib) if @selected_attrib
  @graphic.mvchgat(y=r, x=c, @width-@internal_width-@left_margin, att , acolor , nil)
end

#init_actionsObject

Define actions that can be popped up by PromptMenu or other menubar Currently, only PromptMenu, but we can start contextually appending to Menubar or others

Since:

  • 1.4.1 UNTESTED



681
682
683
684
685
# File 'lib/rbcurse/core/widgets/rlist.rb', line 681

def init_actions
  am = action_manager()
  am.add_action(Action.new("&Disable selection") { @selection_mode = :none; unbind_key(32); bind_key(32, :scroll_forward); } )
  am.add_action(Action.new("&Edit Toggle") { @edit_toggle = !@edit_toggle; $status_message.value = "Edit toggle is #{@edit_toggle}" })
end

#init_varsObject

this is called several times, from constructor and when list data changed, so only put relevant resets here.

Since:

  • 1.4.1 UNTESTED



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/rbcurse/core/widgets/rlist.rb', line 121

def init_vars
  @repaint_required = true
  @widget_scrolled = true  # 2011-10-15 
  @toprow = @pcol = 0
  if @show_selector
    @row_selected_symbol ||= '>'
    @row_unselected_symbol ||= ' '
    @left_margin ||= @row_selected_symbol.length
  end
  @row_selected_symbol ||= ''
  #@left_margin ||= 0
  @one_key_selection = false if @one_key_selection.nil?
  @row_offset = @col_offset = 0 if @suppress_borders

end

#list(*val) ⇒ ListDataModel

provide data to List in the form of an Array or Variable or ListDataModel. This will create a default ListSelectionModel.

CHANGE as on 2010-09-21 12:53: If explicit nil passed then dummy datamodel and selection model created From now on, constructor will call this, so this can always happen.

NOTE: sometimes this can be added much after its painted. Do not expect this to be called from constructor, although that is the usual case. it can be dependent on some other list or tree.

Parameters:

  • data (Array, Variable, ListDataModel)

    to populate list with

Returns:

  • (ListDataModel)

    just created or assigned

Since:

  • 1.4.1 UNTESTED



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/rbcurse/core/widgets/rlist.rb', line 175

def list *val
  return @list if val.empty?
  alist = val[0]
  case alist
  when Array
      @list = alist
      @current_index = 0
  when NilClass
      @list = [] # or nil ?
  when Variable
    @list = alist.value
  else
    raise ArgumentError, "Listbox list(): do not know how to handle #{alist.class} " 
  end
  clear_selection

  @repaint_required = true
  @widget_scrolled = true  # 2011-10-15 
  @list
end

#list_data_changedObject

be informed when data has changed. required here, was being called by listdatamodel earlier

Since:

  • 1.4.1 UNTESTED



568
569
570
571
572
573
574
575
576
# File 'lib/rbcurse/core/widgets/rlist.rb', line 568

def list_data_changed
  if row_count == 0 # added on 2009-02-02 17:13 so cursor not hanging on last row which could be empty
    init_vars
    @current_index = 0
    set_form_row
  end
  @widget_scrolled = true  # 2011-10-15 
  @repaint_required = true
end

#list_data_modelObject

Since:

  • 1.4.1 UNTESTED



195
# File 'lib/rbcurse/core/widgets/rlist.rb', line 195

def list_data_model; @list; end

#map_keysObject

Since:

  • 1.4.1 UNTESTED



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/rbcurse/core/widgets/rlist.rb', line 136

def map_keys
  return if @keys_mapped
  require 'rbcurse/core/include/listbindings'
  bindings()
  bind_key(?f, 'next row starting with char'){ ask_selection_for_char() }
  bind_key(?\M-v, 'toggle one_key_selection'){ @one_key_selection = !@one_key_selection }
  bind_key(13, 'fire action event'){ fire_action_event }
  list_bindings unless @selection_mode == :none  # listselectable
  @keys_mapped = true

end

#OLDadd_to_selectionObject

Only for multiple mode. add an item to selection, if selection mode is multiple if item already selected, it is deselected, else selected typically bound to Ctrl-Space

Since:

  • 1.4.1 UNTESTED



620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'lib/rbcurse/core/widgets/rlist.rb', line 620

def OLDadd_to_selection
  crow = @current_index
  case @selection_mode 
  when :multiple
    if @selected_indices.include? @current_index
      @selected_indices.delete @current_index
      lse = ListSelectionEvent.new(crow, crow, self, :DELETE)
      fire_handler :LIST_SELECTION_EVENT, lse
    else
      @selected_indices << @current_index
      lse = ListSelectionEvent.new(crow, crow, self, :INSERT)
      fire_handler :LIST_SELECTION_EVENT, lse
    end
  else
  end
  @repaint_required = true
end

#OLDclear_selectionObject

clears selected indices

Since:

  • 1.4.1 UNTESTED



638
639
640
641
# File 'lib/rbcurse/core/widgets/rlist.rb', line 638

def OLDclear_selection
  @selected_indices = []
  @repaint_required = true
end

#OLDis_row_selected(crow = @current_index) ⇒ Object

Since:

  • 1.4.1 UNTESTED



642
643
644
645
646
647
648
649
# File 'lib/rbcurse/core/widgets/rlist.rb', line 642

def OLDis_row_selected crow=@current_index
  case @selection_mode 
  when :multiple
    @selected_indices.include? crow
  else
    crow == @selected_index
  end
end

#OLDtoggle_row_selection(crow = @current_index) ⇒ Object

change selection of current row on pressing space bar If mode is multiple, then other selections are cleared and this is added NOTE: 2011-10-8 allow multiple select on spacebar. Using C-Space was quite unfriendly although it will still work

Since:

  • 1.4.1 UNTESTED



595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
# File 'lib/rbcurse/core/widgets/rlist.rb', line 595

def OLDtoggle_row_selection crow=@current_index
  @repaint_required = true
  row = crow
  case @selection_mode 
  when :multiple
    add_to_selection
    #clear_selection
    #@selected_indices[0] = crow #@current_index
  else
    if @selected_index == crow #@current_index
      @selected_index = nil
      lse = ListSelectionEvent.new(crow, crow, self, :DELETE)
      fire_handler :LIST_SELECTION_EVENT, lse
    else
      @selected_index = crow #@current_index
      lse = ListSelectionEvent.new(crow, crow, self, :INSERT)
      fire_handler :LIST_SELECTION_EVENT, lse
    end
  end
end

#on_enterBoolean

please check for error before proceeding

Returns:

  • (Boolean)

    false if no data

Since:

  • 1.4.1 UNTESTED



368
369
370
371
372
373
374
375
376
377
# File 'lib/rbcurse/core/widgets/rlist.rb', line 368

def on_enter
  if @list.nil? || @list.size == 0
    Ncurses.beep
    return :UNHANDLED
  end
  super  # forgot this 2011-10-9 that's why events not firign
  on_enter_row @current_index
  set_form_row # added 2009-01-11 23:41 
  true
end

#on_enter_row(arow) ⇒ Object

Since:

  • 1.4.1 UNTESTED



378
379
380
381
382
383
384
385
386
387
388
# File 'lib/rbcurse/core/widgets/rlist.rb', line 378

def on_enter_row arow
  # copied from resultsettextview, can this not be in one place like listscrollable ? FIXME
  if @should_show_focus
    highlight_focussed_row :FOCUSSED
    unless @oldrow == @selected_index
      highlight_focussed_row :UNFOCUSSED
    end
  end
  fire_handler :ENTER_ROW, self
  @repaint_required = true
end

#on_leave_row(arow) ⇒ Object

Since:

  • 1.4.1 UNTESTED



389
390
391
# File 'lib/rbcurse/core/widgets/rlist.rb', line 389

def on_leave_row arow
  fire_handler :LEAVE_ROW, self
end

#remove_allObject

Since:

  • 1.4.1 UNTESTED



215
216
217
218
219
# File 'lib/rbcurse/core/widgets/rlist.rb', line 215

def remove_all
  return if @list.nil? || @list.empty? 
  @list = []
  init_vars
end

#repaintObject

this method chops the data to length before giving it to the renderer, this can cause problems if the renderer does some processing. also, it pans the data horizontally giving the renderer a section of it.

Since:

  • 1.4.1 UNTESTED



412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/rbcurse/core/widgets/rlist.rb', line 412

def repaint #:nodoc:
  return unless @repaint_required
  #
  # TRYING OUT dangerous 2011-10-15 
  @repaint_required = false
  @repaint_required = true if @widget_scrolled || @pcol != @old_pcol || @record_changed || @property_changed

  unless @repaint_required
    unhighlight_row @old_selected_index
    highlight_selected_row
  end
  return unless @repaint_required
  $log.debug "BASICLIST REPAINT WILL HAPPEN #{current_index} "
  # not sure where to put this, once for all or repeat 2010-02-17 23:07 RFED16
  my_win = @form ? @form.window : @target_window
  @graphic = my_win unless @graphic
  raise " #{@name} neither form, nor target window given LB paint " unless my_win
  raise " #{@name} NO GRAPHIC set as yet                 LB paint " unless @graphic
  raise "width or height not given w:#{@width} , h:#{@height} " if @width.nil? || @height.nil?
  @win_left = my_win.left
  @win_top = my_win.top
  @left_margin ||= @row_selected_symbol.length
  # we are making sure display len does not exceed width XXX hope this does not wreak havoc elsewhere
  _dl = [@display_length || 100, @width-@internal_width-@left_margin].min # 2011-09-17 RK overwriting when we move grabbar in vimsplit

  $log.debug "basiclistbox repaint  #{@name} graphic #{@graphic}"
  #$log.debug "XXX repaint to_print #{@to_print_borders} "
  print_borders unless @suppress_borders # do this once only, unless everything changes
  #maxlen = @maxlen || @width-2
  tm = list()
  rc = row_count
  @longest_line = @width
  $log.debug " rbasiclistbox #{row_count}, w:#{@width} , maxlen:#{@maxlen} "
  if rc > 0     # just added in case no data passed
    tr = @toprow
    acolor = get_color $datacolor
    h = scrollatrow()
    r,c = rowcol
    0.upto(h) do |hh|
      crow = tr+hh
      if crow < rc
        _focussed = @current_index == crow ? true : false  # row focussed ?
        focus_type = _focussed 
        focus_type = :SOFT_FOCUS if _focussed && !@focussed
        selected = is_row_selected crow
        content = tm[crow]   # 2009-01-17 18:37 chomp giving error in some cases says frozen
        content = convert_value_to_text content, crow # 2010-09-23 20:12 
        # by now it has to be a String
        if content.is_a? String
          content = content.dup
          sanitize content if @sanitization_required
          truncate content if @truncation_required
        end
        ## set the selector symbol if requested
        selection_symbol = ''
        if @show_selector
          if selected
            selection_symbol = @row_selected_symbol
          else
            selection_symbol =  @row_unselected_symbol
          end
          @graphic.printstring r+hh, c, selection_symbol, acolor,@attr
        end
        #renderer = get_default_cell_renderer_for_class content.class.to_s
        renderer = cell_renderer()
        renderer.display_length = _dl # 2011-09-17 RK overwriting when we move grabbar in vimsplit
        renderer.repaint @graphic, r+hh, c+@left_margin, crow, content, focus_type, selected
      else
        # clear rows
        @graphic.printstring r+hh, c, " " * (@width-@internal_width), acolor,@attr
      end
    end
  end # rc == 0
  @repaint_required = false
  # 2011-10-13 
  @widget_scrolled = false
  @record_changed = false
  @property_changed = false
  @old_pcol = @pcol
end

#row_countObject

returns count of row, needed by scrollbar and others.

Since:

  • 1.4.1 UNTESTED



149
150
151
152
# File 'lib/rbcurse/core/widgets/rlist.rb', line 149

def row_count
  return 0 if @list.nil?
  @list.length
end

#sanitize(content) ⇒ Object

takes a block, this way anyone extending this klass can just pass a block to do his job This modifies the string

Since:

  • 1.4.1 UNTESTED



532
533
534
535
536
537
538
539
540
# File 'lib/rbcurse/core/widgets/rlist.rb', line 532

def sanitize content #:nodoc:
  if content.is_a? String
    content.chomp!
    content.gsub!(/\t/, '  ') # don't display tab
    content.gsub!(/[^[:print:]]/, '')  # don't display non print characters
  else
    content
  end
end

#scrollatrowObject

start scrolling when user reaches this row

Since:

  • 1.4.1 UNTESTED



154
155
156
157
158
159
160
# File 'lib/rbcurse/core/widgets/rlist.rb', line 154

def scrollatrow #:nodoc:
  if @suppress_borders
    return @height - 1
  else
    return @height - 3
  end
end

#set_form_col(col1 = 0) ⇒ Object

set cursor column position if i set col1 to @curpos, i can move around left right if key mapped

Since:

  • 1.4.1 UNTESTED



580
581
582
583
584
585
586
587
# File 'lib/rbcurse/core/widgets/rlist.rb', line 580

def set_form_col col1=0               #:nodoc:
  @cols_panned ||= 0 
  # editable listboxes will involve changing cursor and the form issue
  win_col = 0 
  col2 = win_col + @col + @col_offset + col1 + @cols_panned + @left_margin
  $log.debug " set_form_col in rlistbox #{@col}+ left_margin #{@left_margin} ( #{col2} ) "
  setrowcol nil, col2 
end

#truncate(content) ⇒ Object

returns only the visible portion of string taking into account display length and horizontal scrolling. MODIFIES STRING

Since:

  • 1.4.1 UNTESTED



543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
# File 'lib/rbcurse/core/widgets/rlist.rb', line 543

def truncate content # :nodoc:
  maxlen = @maxlen || @width-@internal_width
  maxlen = @width-@internal_width if maxlen > @width-@internal_width
  if maxlen == 0 # (otherwise it becoems -1 below)
    content.replace ""
    return
  end
  if !content.nil? 
    cl = content.length
    if cl > maxlen # only show maxlen
      @longest_line = cl if cl > @longest_line
      #content = content[@pcol..@pcol+maxlen-1] 
      ## taking care of when scrolling is needed but longest_line is misreported
      # So we scroll always and need to check 2013-03-06 - 00:09 
      content.replace(content[@pcol..@pcol+maxlen-1] || " ")
    else
      ## taking care of when scrolling is needed but longest_line is misreported
      # So we scroll always and need to check 2013-03-06 - 00:09 
      content.replace(content[@pcol..-1]||" ") if @pcol > 0 
    end
  end
  content
end

#unhighlight_row(index, r = nil, c = nil, acolor = nil) ⇒ Object

Since:

  • 1.4.1 UNTESTED



504
505
506
507
508
509
510
511
512
513
514
515
# File 'lib/rbcurse/core/widgets/rlist.rb', line 504

def unhighlight_row index,  r=nil, c=nil, acolor=nil
  return unless index # no selection
  r = _convert_index_to_printable_row(index) unless r
  return unless r # not on screen
  unless c
    _r, c = rowcol
  end
  acolor ||= get_color $datacolor
  att = FFI::NCurses::A_NORMAL
  att = get_attrib(@normal_attrib) if @normal_attrib
  @graphic.mvchgat(y=r, x=c, @width-@internal_width-@left_margin, att , acolor , nil)
end