Class: RubyCurses::DefaultListSelectionModel

Inherits:
Object
  • Object
show all
Includes:
EventHandler
Defined in:
lib/rbcurse/defaultlistselectionmodel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Constructor Details

#initializeDefaultListSelectionModel



10
11
12
13
14
15
16
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 10

def initialize
  @selected_indices=[]
  @anchor_selection_index = -1
  @lead_selection_index = -1
  @selection_mode = 'multiple'
  $log.debug " created DefaultListSelectionModel XXX"
end

Instance Attribute Details

#anchor_selection_indexObject (readonly)

Returns the value of attribute anchor_selection_index.



8
9
10
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 8

def anchor_selection_index
  @anchor_selection_index
end

#lead_selection_indexObject (readonly)

Returns the value of attribute lead_selection_index.



9
10
11
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 9

def lead_selection_index
  @lead_selection_index
end

#selection_modeObject

Returns the value of attribute selection_mode.



7
8
9
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 7

def selection_mode
  @selection_mode
end

Instance Method Details

#add_selection_interval(ix0, ix1) ⇒ Object

TODO should go in sorted, and no dupes



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 38

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, self, :INSERT)
  fire_handler :LIST_SELECTION_EVENT, lse
  $log.debug " DLSM firing LIST_SELECTION EVENT #{lse}"
end

#clear_selectionObject



18
19
20
21
22
23
24
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 18

def clear_selection
  ix0 = @selected_indices.first
  ix1 = @selected_indices.last
  @selected_indices=[]
  lse = ListSelectionEvent.new(ix0, ix1, self, :DELETE)
  fire_handler :LIST_SELECTION_EVENT, lse
end

#get_max_selection_indexObject



28
29
30
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 28

def get_max_selection_index
  @selected_indices[-1]
end

#get_min_selection_indexObject



31
32
33
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 31

def get_min_selection_index
  @selected_indices[0]
end

#get_selected_rowsObject



34
35
36
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 34

def get_selected_rows
  @selected_indices
end

#insert_index_interval(ix0, len) ⇒ Object



57
58
59
60
61
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 57

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



25
26
27
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 25

def is_selected_index ix
  @selected_indices.include? ix
end

#remove_selection_interval(ix0, ix1) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/rbcurse/defaultlistselectionmodel.rb', line 50

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, self, :DELETE)
  fire_handler :LIST_SELECTION_EVENT, lse
end