Module: RubyCurses::ListSelectable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#column_selection_allowedObject

Returns the value of attribute column_selection_allowed.



123
124
125
# File 'lib/rbcurse/extras/include/listselectable.rb', line 123

def column_selection_allowed
  @column_selection_allowed
end

#row_selection_allowedObject

Returns the value of attribute row_selection_allowed.



122
123
124
# File 'lib/rbcurse/extras/include/listselectable.rb', line 122

def row_selection_allowed
  @row_selection_allowed
end

Instance Method Details

#add_row_selection_interval(ix0, ix1) ⇒ Object



31
32
33
34
35
36
# File 'lib/rbcurse/extras/include/listselectable.rb', line 31

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_selectionObject



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

def clear_selection
  @list_selection_model.clear_selection
  @repaint_required = true
end

#create_default_list_selection_modelObject

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.



116
117
118
119
120
# File 'lib/rbcurse/extras/include/listselectable.rb', line 116

def create_default_list_selection_model
  if @list_selection_model.nil?
    list_selection_model DefaultListSelectionModel.new(self)
  end
end

#do_next_selectionObject



96
97
98
99
100
101
102
# File 'lib/rbcurse/extras/include/listselectable.rb', line 96

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



103
104
105
106
107
108
109
# File 'lib/rbcurse/extras/include/listselectable.rb', line 103

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

Returns:

  • (Boolean)


25
26
27
# File 'lib/rbcurse/extras/include/listselectable.rb', line 25

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



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rbcurse/extras/include/listselectable.rb', line 12

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



37
38
39
# File 'lib/rbcurse/extras/include/listselectable.rb', line 37

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

#selected_rowObject Also known as: selected_index

returns index of first selected row (lowest index) TODO: if param passed set that as selected_index



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

def selected_row
  @list_selection_model.get_min_selection_index
end

#selected_row_countObject



65
66
67
# File 'lib/rbcurse/extras/include/listselectable.rb', line 65

def selected_row_count
  selected_rows.size
end

#selected_rowsObject

@list end returns selected indices TODO : if array passed, set those as selected indices



62
63
64
# File 'lib/rbcurse/extras/include/listselectable.rb', line 62

def selected_rows
  @list_selection_model.get_selected_rows
end

#selected_valueObject

returns value of first selected row (lowest index)



76
77
78
79
80
# File 'lib/rbcurse/extras/include/listselectable.rb', line 76

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



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rbcurse/extras/include/listselectable.rb', line 83

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



40
41
42
43
44
45
46
47
48
49
# File 'lib/rbcurse/extras/include/listselectable.rb', line 40

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