Module: RubyCurses::ListSelectable

Included in:
Listbox, Table
Defined in:
lib/rbcurse/listselectable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#column_selection_allowedObject

Returns the value of attribute column_selection_allowed.



71
72
73
# File 'lib/rbcurse/listselectable.rb', line 71

def column_selection_allowed
  @column_selection_allowed
end

#row_selection_allowedObject

Returns the value of attribute row_selection_allowed.



70
71
72
# File 'lib/rbcurse/listselectable.rb', line 70

def row_selection_allowed
  @row_selection_allowed
end

Instance Method Details

#add_row_selection_interval(ix0, ix1) ⇒ Object



22
23
24
25
26
# File 'lib/rbcurse/listselectable.rb', line 22

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
end

#clear_selectionObject



40
41
42
# File 'lib/rbcurse/listselectable.rb', line 40

def clear_selection
  @list_selection_model.clear_selection
end

#create_default_list_selection_modelObject



15
16
17
# File 'lib/rbcurse/listselectable.rb', line 15

def create_default_list_selection_model
  list_selection_model DefaultListSelectionModel.new
end

#do_next_selectionObject



55
56
57
58
59
60
61
# File 'lib/rbcurse/listselectable.rb', line 55

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_selectionObject



62
63
64
65
66
67
68
# File 'lib/rbcurse/listselectable.rb', line 62

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_row_selected(row) ⇒ Object



18
19
20
# File 'lib/rbcurse/listselectable.rb', line 18

def is_row_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



7
8
9
10
11
12
13
14
# File 'lib/rbcurse/listselectable.rb', line 7

def list_selection_model(*lsm)
  if lsm.empty?
    @list_selection_model 
  else
    @list_selection_model = lsm[0]
  end
  #@list_selection_model.selection_mode = @selection_mode || :MULTIPLE
end

#remove_row_selection_interval(ix0, ix1) ⇒ Object



27
28
29
# File 'lib/rbcurse/listselectable.rb', line 27

def remove_row_selection_interval ix0, ix1
  @list_selection_model.remove_selection_interval ix0, ix1
end

#selected_itemObject



43
44
45
# File 'lib/rbcurse/listselectable.rb', line 43

def selected_item
#  @list[@current_index]
end

#selected_rowObject Also known as: selected_index



52
53
54
# File 'lib/rbcurse/listselectable.rb', line 52

def selected_row
  @list_selection_model.get_min_selection_index
end

#selected_row_countObject



49
50
51
# File 'lib/rbcurse/listselectable.rb', line 49

def selected_row_count
  selected_rows.size
end

#selected_rowsObject

@list



46
47
48
# File 'lib/rbcurse/listselectable.rb', line 46

def selected_rows
  @list_selection_model.get_selected_rows
end

#toggle_row_selection(row = @current_index) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/rbcurse/listselectable.rb', line 30

def toggle_row_selection row=@current_index
  if is_row_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
end