Class: RubyCurses::DefaultListSelectionModel
- Includes:
- EventHandler
- Defined in:
- lib/rbcurse/defaultlistselectionmodel.rb
Instance Attribute Summary collapse
-
#anchor_selection_index ⇒ Object
readonly
Returns the value of attribute anchor_selection_index.
-
#lead_selection_index ⇒ Object
readonly
Returns the value of attribute lead_selection_index.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#selection_mode ⇒ Object
Returns the value of attribute selection_mode.
Instance Method Summary collapse
-
#add_selection_interval(ix0, ix1) ⇒ Object
TODO should go in sorted, and no dupes.
-
#clear_selection ⇒ Object
end.
- #get_max_selection_index ⇒ Object
- #get_min_selection_index ⇒ Object
- #get_selected_indices ⇒ Object (also: #get_selected_rows)
-
#initialize(parent) ⇒ DefaultListSelectionModel
constructor
A new instance of DefaultListSelectionModel.
- #insert_index_interval(ix0, len) ⇒ Object
- #is_selected_index(ix) ⇒ Object
- #remove_selection_interval(ix0, ix1) ⇒ Object
Methods included from EventHandler
#bind, #fire_handler, #fire_property_change
Constructor Details
#initialize(parent) ⇒ DefaultListSelectionModel
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 15 def initialize parent raise ArgumentError "Parent cannot be nil. Please pass List while creating" if parent.nil? @parent = parent @selected_indices=[] @anchor_selection_index = -1 @lead_selection_index = -1 @selection_mode = 'multiple' @_events = [:LIST_SELECTION_EVENT] #$log.debug " created DefaultListSelectionModel XXX" end |
Instance Attribute Details
#anchor_selection_index ⇒ Object (readonly)
Returns the value of attribute anchor_selection_index.
12 13 14 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 12 def anchor_selection_index @anchor_selection_index end |
#lead_selection_index ⇒ Object (readonly)
Returns the value of attribute lead_selection_index.
13 14 15 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 13 def lead_selection_index @lead_selection_index end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
14 15 16 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 14 def parent @parent end |
#selection_mode ⇒ Object
Returns the value of attribute selection_mode.
11 12 13 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 11 def selection_mode @selection_mode end |
Instance Method Details
#add_selection_interval(ix0, ix1) ⇒ Object
TODO should go in sorted, and no dupes
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 54 def add_selection_interval ix0, ix1 $log.debug " def add_selection_interval #{ix0}, #{ix1}, mode: #{@selection_mode} " if @selection_mode != :multiple clear_selection end @anchor_selection_index = ix0 @lead_selection_index = ix1 ix0.upto(ix1) {|i| @selected_indices << i unless @selected_indices.include? i } lse = ListSelectionEvent.new(ix0, ix1, @parent, :INSERT) fire_handler :LIST_SELECTION_EVENT, lse $log.debug " DLSM firing LIST_SELECTION EVENT #{lse}" end |
#clear_selection ⇒ Object
end
32 33 34 35 36 37 38 39 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 32 def clear_selection ix0 = @selected_indices.first ix1 = @selected_indices.last @selected_indices=[] return if ix0.nil? lse = ListSelectionEvent.new(ix0, ix1, @parent, :DELETE) fire_handler :LIST_SELECTION_EVENT, lse end |
#get_max_selection_index ⇒ Object
43 44 45 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 43 def get_max_selection_index @selected_indices[-1] end |
#get_min_selection_index ⇒ Object
46 47 48 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 46 def get_min_selection_index @selected_indices[0] end |
#get_selected_indices ⇒ Object Also known as: get_selected_rows
49 50 51 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 49 def get_selected_indices @selected_indices end |
#insert_index_interval(ix0, len) ⇒ Object
73 74 75 76 77 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 73 def insert_index_interval ix0, len @anchor_selection_index = ix0 @lead_selection_index = ix0+len add_selection_interval @anchor_selection_index, @lead_selection_index end |
#is_selected_index(ix) ⇒ Object
40 41 42 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 40 def is_selected_index ix @selected_indices.include? ix end |
#remove_selection_interval(ix0, ix1) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 66 def remove_selection_interval ix0, ix1 @anchor_selection_index = ix0 @lead_selection_index = ix1 @selected_indices.delete_if {|x| x >= ix0 and x <= ix1} lse = ListSelectionEvent.new(ix0, ix1, @parent, :DELETE) fire_handler :LIST_SELECTION_EVENT, lse end |