Class: Canis::List
- Extended by:
- Forwardable
- Includes:
- ListScrollable, NewListSelectable
- Defined in:
- lib/canis/core/widgets/deprecated/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.
Instance Attribute Summary collapse
-
#current_index ⇒ Object
dsl_accessor :default_values # array of default values dsl_accessor :is_popup # if it is in a popup and single select, selection closes.
-
#one_key_selection ⇒ Object
please set these in he constructor block.
-
#selected_index ⇒ Object
index of selected row.
-
#toprow ⇒ Object
readonly
dsl_accessor :list # the array of data to be sent by user.
Attributes included from ListScrollable
#find_offset, #find_offset1, #search_found_ix, #show_caret
Attributes inherited from Widget
#_object_created, #col_offset, #config, #curpos, #focussed, #form, #handler, #id, #key_label, #parent_component, #row_offset, #state
selection related collapse
-
#get_selected_indices ⇒ Object
Returns selected indices Indices are often required since the renderer may modify the values displayed.
-
#get_selected_values ⇒ Object
(also: #selected_values)
Returns selected values.
- #goto_next_selection ⇒ Object
- #goto_prev_selection ⇒ Object
-
#init_actions ⇒ Object
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.
Instance Method Summary collapse
-
#[](off0) ⇒ Object
get element at.
- #append(text) ⇒ Object
-
#ask_search_backward ⇒ Object
gets string to search and calls data models find prev.
- #ask_search_forward ⇒ Object
-
#ask_selection_for_char ⇒ Object
get a keystroke from user and go to first item starting with that key.
-
#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.
-
#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.
- #create_default_cell_renderer ⇒ Object
-
#current_value ⇒ Object
(also: #current_row, #text)
return object under cursor Note: this should not be confused with selected row/s.
-
#data=(val) ⇒ Object
conv method to insert data, trying to keep names same across along with Tabular, TextView, TextArea and listbox.
-
#fire_action_event ⇒ Object
triggered on hitting ENTER button.
-
#get_content ⇒ Object
START FOR scrollable ###.
-
#get_window ⇒ Object
:nodoc:.
-
#getvalue ⇒ Object
END FOR scrollable ### override widgets text returns indices of selected rows.
-
#handle_key(ch) ⇒ Object
Listbox.
- #highlight_selected_row(r = nil, c = nil, acolor = nil) ⇒ Object
-
#init_vars ⇒ Object
this is called several times, from constructor and when list data changed, so only put relevant resets here.
-
#initialize(form = nil, config = {}, &block) ⇒ List
constructor
basic listbox constructor.
-
#list(*val) ⇒ ListDataModel
provide data to List in the form of an Array or Variable or ListDataModel.
-
#list_data_changed ⇒ Object
be informed when data has changed.
- #list_data_model ⇒ Object
- #map_keys ⇒ Object
-
#on_enter ⇒ Boolean
please check for error before proceeding.
- #on_enter_row(arow) ⇒ Object
- #on_leave_row(arow) ⇒ Object
- #remove_all ⇒ Object
-
#repaint ⇒ Object
this method chops the data to length before giving it to the renderer, this can cause problems if the renderer does some processing.
-
#row_count ⇒ Object
returns count of row, needed by scrollbar and others.
-
#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.
-
#scrollatrow ⇒ Object
start scrolling when user reaches this row.
-
#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.
-
#truncate(content) ⇒ Object
returns only the visible portion of string taking into account display length and horizontal scrolling.
- #unhighlight_row(index, r = nil, c = nil, acolor = nil) ⇒ Object
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, #backward_word, #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, #bgcolor, #color, #color_pair, #command, #destroy, #focus, #focusable, #focusable?, #getvalue_for_paint, #hide, #modified?, #move, #on_leave, #override_graphic, #process_key, #property_set, #remove, #repaint_all, #repaint_required, #rowcol, #set_form, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #unbind_key
Methods included from Io
#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rb_getstr, #warn
Methods included from Utils
#ORIG_process_key, #ORIGbind_key, #ORIGkeycode_tos, #_process_key, #bind_composite_mapping, #bind_key, #bind_keys, #check_composite_mapping, #create_logger, #define_key, #define_prefix_command, #execute_mapping, #get_attrib, #get_color, #key, #key_tos, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #xxxbind_composite_mapping
Methods included from ConfigSetup
Methods included from EventHandler
#bind, #event?, #event_list, #fire_handler, #fire_property_change, #register_events
Constructor Details
#initialize(form = nil, config = {}, &block) ⇒ List
basic listbox constructor
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/canis/core/widgets/deprecated/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_index ⇒ Object
dsl_accessor :default_values # array of default values dsl_accessor :is_popup # if it is in a popup and single select, selection closes
52 53 54 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 52 def current_index @current_index end |
#one_key_selection ⇒ Object
please set these in he constructor block. Settin them later will have no effect since i would have bound them to actions
64 65 66 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 64 def one_key_selection @one_key_selection end |
#selected_index ⇒ Object
index of selected row
73 74 75 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 73 def selected_index @selected_index end |
#toprow ⇒ Object (readonly)
dsl_accessor :list # the array of data to be sent by user
49 50 51 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 49 def toprow @toprow end |
Instance Method Details
#[](off0) ⇒ Object
get element at
209 210 211 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 209 def [](off0) @list[off0] end |
#append(text) ⇒ Object
234 235 236 237 238 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 234 def append text @list.push text @widget_scrolled = true @repaint_required = true end |
#ask_search_backward ⇒ Object
gets string to search and calls data models find prev
360 361 362 363 364 365 366 367 368 369 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 360 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_forward ⇒ Object
350 351 352 353 354 355 356 357 358 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 350 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_char ⇒ Object
get a keystroke from user and go to first item starting with that key
343 344 345 346 347 348 349 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 343 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
400 401 402 403 404 405 406 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 400 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.
526 527 528 529 530 531 532 533 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 526 def convert_value_to_text value, crow case value when TrueClass, FalseClass value else value.to_s if value end end |
#create_default_cell_renderer ⇒ Object
407 408 409 410 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 407 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_value ⇒ Object 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
216 217 218 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 216 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.
202 203 204 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 202 def data=(val) list(val) end |
#fire_action_event ⇒ Object
triggered on hitting ENTER button
338 339 340 341 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 338 def fire_action_event require 'canis/core/include/ractionevent' fire_handler :PRESS, ActionEvent.new(self, :PRESS, text) end |
#get_content ⇒ Object
START FOR scrollable ###
244 245 246 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 244 def get_content @list end |
#get_selected_indices ⇒ Object
Returns selected indices Indices are often required since the renderer may modify the values displayed
612 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 612 def get_selected_indices; @selected_indices; end |
#get_selected_values ⇒ Object Also known as: selected_values
Returns selected values
616 617 618 619 620 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 616 def get_selected_values selected = [] @selected_indices.each { |i| selected << @list[i] } return selected end |
#get_window ⇒ Object
:nodoc:
247 248 249 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 247 def get_window #:nodoc: @graphic end |
#getvalue ⇒ Object
END FOR scrollable ### override widgets text returns indices of selected rows
253 254 255 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 253 def getvalue selected_rows end |
#goto_next_selection ⇒ Object
595 596 597 598 599 600 601 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 595 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_selection ⇒ Object
602 603 604 605 606 607 608 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 602 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
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 331 332 333 334 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 257 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
496 497 498 499 500 501 502 503 504 505 506 507 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 496 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_actions ⇒ Object
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
625 626 627 628 629 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 625 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_vars ⇒ Object
this is called several times, from constructor and when list data changed, so only put relevant resets here.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/canis/core/widgets/deprecated/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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 175 def list *val return @list if val.empty? alist = val[0] case alist when Array @list = alist # I possibly should call init_vars in these 3 cases but am doing the minimal 2013-04-10 - 18:27 # Based no issue: https://github.com/mare-imbrium/canis/issues/15 @current_index = @toprow = @pcol = 0 when NilClass @list = [] # or nil ? @current_index = @toprow = @pcol = 0 when Variable @list = alist.value @current_index = @toprow = @pcol = 0 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_changed ⇒ Object
be informed when data has changed. required here, was being called by listdatamodel earlier
572 573 574 575 576 577 578 579 580 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 572 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_model ⇒ Object
199 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 199 def list_data_model; @list; end |
#map_keys ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 136 def map_keys return if @keys_mapped require 'canis/core/include/deprecated/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 |
#on_enter ⇒ Boolean
please check for error before proceeding
372 373 374 375 376 377 378 379 380 381 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 372 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
382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 382 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
393 394 395 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 393 def on_leave_row arow fire_handler :LEAVE_ROW, self end |
#remove_all ⇒ Object
219 220 221 222 223 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 219 def remove_all return if @list.nil? || @list.empty? @list = [] init_vars end |
#repaint ⇒ Object
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.
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 492 493 494 495 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 416 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_count ⇒ Object
returns count of row, needed by scrollbar and others.
149 150 151 152 |
# File 'lib/canis/core/widgets/deprecated/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
536 537 538 539 540 541 542 543 544 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 536 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 |
#scrollatrow ⇒ Object
start scrolling when user reaches this row
154 155 156 157 158 159 160 |
# File 'lib/canis/core/widgets/deprecated/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
584 585 586 587 588 589 590 591 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 584 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
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 547 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
508 509 510 511 512 513 514 515 516 517 518 519 |
# File 'lib/canis/core/widgets/deprecated/rlist.rb', line 508 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 |