Class: RubyCurses::ListSelectionModel
- Inherits:
-
Object
- Object
- RubyCurses::ListSelectionModel
- Defined in:
- lib/rbcurse/experimental/widgets/tablewidget.rb
Overview
Handles selection of items in a list or table or tree that uses stable indices. Indexes are in the order they were places, not sorted. This is just a wrapper over an array, except that it fires an event so users can bind to row selection and deselection TODO - fire events to listeners
Instance Method Summary collapse
- #_fire_event(firsti, lasti, event) ⇒ Object
- #clear_selection ⇒ Object
-
#initialize(component) ⇒ ListSelectionModel
constructor
obj is the source object, I am wondering whether i need it or not.
- #is_row_selected?(crow) ⇒ Boolean
- #is_selection_empty? ⇒ Boolean
-
#remove_index(crow) ⇒ Object
if row deleted in list, then synch with list (No listeners are informed).
- #select(ix) ⇒ Object (also: #add_to_selection)
- #select_all ⇒ Object
-
#selected_rows ⇒ Object
returns a list of selected indices in the same order as added.
- #toggle_row_selection(crow) ⇒ Object
- #unselect(ix) ⇒ Object (also: #remove_from_selection)
Constructor Details
#initialize(component) ⇒ ListSelectionModel
obj is the source object, I am wondering whether i need it or not
820 821 822 823 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 820 def initialize component @obj = component @selected_indices = [] end |
Instance Method Details
#_fire_event(firsti, lasti, event) ⇒ Object
856 857 858 859 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 856 def _fire_event firsti, lasti, event lse = ListSelectionEvent.new(firsti, lasti, self, event) fire_handler :LIST_SELECTION_EVENT, lse end |
#clear_selection ⇒ Object
841 842 843 844 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 841 def clear_selection @selected_indices = [] _fire_event 0, 0, :CLEAR end |
#is_row_selected?(crow) ⇒ Boolean
845 846 847 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 845 def is_row_selected? crow @selected_indices.include? crow end |
#is_selection_empty? ⇒ Boolean
848 849 850 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 848 def is_selection_empty? return @selected_indices.empty? end |
#remove_index(crow) ⇒ Object
if row deleted in list, then synch with list (No listeners are informed)
853 854 855 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 853 def remove_index crow @selected_indices.delete crow end |
#select(ix) ⇒ Object Also known as: add_to_selection
831 832 833 834 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 831 def select ix @selected_indices << ix _fire_event ix, ix, :INSERT end |
#select_all ⇒ Object
861 862 863 864 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 861 def select_all # how do we do this since we don't know what the indices are. # What is the user using as identifier? end |
#selected_rows ⇒ Object
returns a list of selected indices in the same order as added
867 868 869 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 867 def selected_rows @selected_indices end |
#toggle_row_selection(crow) ⇒ Object
824 825 826 827 828 829 830 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 824 def toggle_row_selection crow if is_row_selected? crow unselect crow else select crow end end |
#unselect(ix) ⇒ Object Also known as: remove_from_selection
835 836 837 838 |
# File 'lib/rbcurse/experimental/widgets/tablewidget.rb', line 835 def unselect ix @selected_indices.delete ix _fire_event ix, ix, :DELETE end |