Module: RubyCurses::ListSelectable
Instance Attribute Summary collapse
-
#column_selection_allowed ⇒ Object
Returns the value of attribute column_selection_allowed.
-
#row_selection_allowed ⇒ Object
Returns the value of attribute row_selection_allowed.
Instance Method Summary collapse
- #add_row_selection_interval(ix0, ix1) ⇒ Object
- #clear_selection ⇒ Object
-
#create_default_list_selection_model ⇒ Object
NOTE: I HAD removed this and put in listbox, but its required by rtable also create a default list selection model and set it NOTE: I am now checking if one is not already created, since a second creation would wipe out any listeners on it.
- #do_next_selection ⇒ Object
- #do_prev_selection ⇒ Object
- #is_selected?(row) ⇒ Boolean (also: #is_row_selected)
-
#list_selection_model(*lsm) ⇒ Object
modified on 2009-02-13 23:41 to return model if no param passed sets or returns a list selection model Also listbox listens to it for selections, so it can tell those who are interested 2010-09-21 16:02.
- #remove_row_selection_interval(ix0, ix1) ⇒ Object
-
#selected_row ⇒ Object
(also: #selected_index)
returns index of first selected row (lowest index) TODO: if param passed set that as selected_index.
- #selected_row_count ⇒ Object
-
#selected_rows ⇒ Object
@list end returns selected indices TODO : if array passed, set those as selected indices.
-
#selected_value ⇒ Object
returns value of first selected row (lowest index).
-
#selected_values(&block) ⇒ Object
returns an array of selected values or yields values to given block.
- #toggle_row_selection(row = @current_index) ⇒ Object
Instance Attribute Details
#column_selection_allowed ⇒ Object
Returns the value of attribute column_selection_allowed.
121 122 123 |
# File 'lib/rbcurse/listselectable.rb', line 121 def column_selection_allowed @column_selection_allowed end |
#row_selection_allowed ⇒ Object
Returns the value of attribute row_selection_allowed.
120 121 122 |
# File 'lib/rbcurse/listselectable.rb', line 120 def row_selection_allowed @row_selection_allowed end |
Instance Method Details
#add_row_selection_interval(ix0, ix1) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/rbcurse/listselectable.rb', line 29 def add_row_selection_interval ix0, ix1 $log.debug " def add_row_selection_interval #{ix0}, #{ix1}" # if row_selection_allowed @list_selection_model.add_selection_interval ix0, ix1 @repaint_required = true end |
#clear_selection ⇒ Object
49 50 51 52 |
# File 'lib/rbcurse/listselectable.rb', line 49 def clear_selection @list_selection_model.clear_selection @repaint_required = true end |
#create_default_list_selection_model ⇒ Object
NOTE: I HAD removed this and put in listbox, but its required by rtable also create a default list selection model and set it NOTE: I am now checking if one is not already created, since a second creation would wipe out any listeners on it.
114 115 116 117 118 |
# File 'lib/rbcurse/listselectable.rb', line 114 def create_default_list_selection_model if @list_selection_model.nil? list_selection_model DefaultListSelectionModel.new(self) end end |
#do_next_selection ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/rbcurse/listselectable.rb', line 94 def do_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 |
#do_prev_selection ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/rbcurse/listselectable.rb', line 101 def do_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 |
#is_selected?(row) ⇒ Boolean Also known as: is_row_selected
23 24 25 |
# File 'lib/rbcurse/listselectable.rb', line 23 def is_selected? row @list_selection_model.is_selected_index row end |
#list_selection_model(*lsm) ⇒ Object
modified on 2009-02-13 23:41 to return model if no param passed sets or returns a list selection model Also listbox listens to it for selections, so it can tell those who are interested 2010-09-21 16:02
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rbcurse/listselectable.rb', line 10 def list_selection_model(*lsm) if lsm.empty? @list_selection_model else @list_selection_model = lsm[0] # the listbox is listening to selection events on the # selection model and will inform any listeners of the same. @list_selection_model.bind :LIST_SELECTION_EVENT do |ev| fire_handler :LIST_SELECTION_EVENT, ev end end #@list_selection_model.selection_mode = @selection_mode || :MULTIPLE end |
#remove_row_selection_interval(ix0, ix1) ⇒ Object
35 36 37 |
# File 'lib/rbcurse/listselectable.rb', line 35 def remove_row_selection_interval ix0, ix1 @list_selection_model.remove_selection_interval ix0, ix1 end |
#selected_row ⇒ Object Also known as: selected_index
returns index of first selected row (lowest index) TODO: if param passed set that as selected_index
68 69 70 |
# File 'lib/rbcurse/listselectable.rb', line 68 def selected_row @list_selection_model.get_min_selection_index end |
#selected_row_count ⇒ Object
63 64 65 |
# File 'lib/rbcurse/listselectable.rb', line 63 def selected_row_count selected_rows.size end |
#selected_rows ⇒ Object
@list end returns selected indices TODO : if array passed, set those as selected indices
60 61 62 |
# File 'lib/rbcurse/listselectable.rb', line 60 def selected_rows @list_selection_model.get_selected_rows end |
#selected_value ⇒ Object
returns value of first selected row (lowest index)
74 75 76 77 78 |
# File 'lib/rbcurse/listselectable.rb', line 74 def selected_value #@list[@current_index].to_s # old behavior since curr row was in reverse return nil if selected_row().nil? @list[selected_row()].to_s end |
#selected_values(&block) ⇒ Object
returns an array of selected values or yields values to given block
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rbcurse/listselectable.rb', line 81 def selected_values &block ar = [] selected_rows().each do |i| val = @list[i] if block_given? yield val else ar << val end end return ar unless block_given? end |
#toggle_row_selection(row = @current_index) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rbcurse/listselectable.rb', line 38 def toggle_row_selection row=@current_index if is_selected? row #$log.debug " deleting row #{row}" remove_row_selection_interval(row, row) else #$log.debug " adding row #{row}" add_row_selection_interval(row, row) end @repaint_required = true end |