Class: RubyCurses::ListDataModel
- Inherits:
-
Object
- Object
- RubyCurses::ListDataModel
- Includes:
- Enumerable, EventHandler
- Defined in:
- lib/rbcurse/extras/widgets/rlistbox.rb
Overview
www.java2s.com/Code/JavaAPI/javax.swing.event/ListDataEventCONTENTSCHANGED.htm should we extend array of will that open us to misuse
Instance Attribute Summary collapse
-
#last_regex ⇒ Object
readonly
should i really keep here as public or maintain in listbox.
-
#selected_index ⇒ Object
Returns the value of attribute selected_index.
Instance Method Summary collapse
- #[](off0) ⇒ Object
- #[]=(off0, data) ⇒ Object
- #append(data) ⇒ Object
- #delete(obj) ⇒ Object
- #delete_at(off0) ⇒ Object
-
#each(&blk) ⇒ Object
changd on 2009-01-14 12:28 based on ..
-
#find_match(regex, ix0 = 0, ix1 = length()) ⇒ Object
## added 2009-01-14 01:00 searches between given range of rows (def 0 and end) returns row index of first match of given regex (or nil if not found).
-
#find_next ⇒ Object
continues previous search.
-
#find_prev(regex = @last_regex, start = @search_found_ix) ⇒ Object
find backwards, list_data_model Using this to start a search or continue search.
- #include?(obj) ⇒ Boolean
-
#index(obj) ⇒ Object
not sure how to do this XXX removed on 2009-01-14 12:28 def <=>(other) @list <=> other end.
-
#initialize(anarray = []) ⇒ ListDataModel
constructor
A new instance of ListDataModel.
- #insert(off0, *data) ⇒ Object
- #length ⇒ Object (also: #size)
-
#on_enter_row(object) ⇒ Object
deprecated
Deprecated.
this was just eye candy for some demo
- #remove_all ⇒ Object
-
#slice!(line, howmany) ⇒ Object
added 2010-05-23 12:10 for listeditable.
- #update(off0, data) ⇒ Object
-
#values ⇒ Object
(also: #to_array)
returns a ‘dup()` of the list.
Constructor Details
#initialize(anarray = []) ⇒ ListDataModel
Returns a new instance of ListDataModel.
53 54 55 56 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 53 def initialize anarray=[] @list = anarray.dup @_events = [:LIST_DATA_EVENT, :ENTER_ROW] end |
Instance Attribute Details
#last_regex ⇒ Object (readonly)
should i really keep here as public or maintain in listbox
51 52 53 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 51 def last_regex @last_regex end |
#selected_index ⇒ Object
Returns the value of attribute selected_index.
50 51 52 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 50 def selected_index @selected_index end |
Instance Method Details
#[](off0) ⇒ Object
90 91 92 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 90 def [](off0) @list[off0] end |
#[]=(off0, data) ⇒ Object
87 88 89 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 87 def []=(off0, data) update off0, data end |
#append(data) ⇒ Object
77 78 79 80 81 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 77 def append data @list << data lde = ListDataEvent.new(@list.length-1, @list.length-1, self, :INTERVAL_ADDED) fire_handler :LIST_DATA_EVENT, lde end |
#delete(obj) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 106 def delete obj off0 = @list.index obj return nil if off0.nil? ret=@list.delete_at off0 lde = ListDataEvent.new(off0, off0, self, :INTERVAL_REMOVED) fire_handler :LIST_DATA_EVENT, lde return ret end |
#delete_at(off0) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 93 def delete_at off0 ret=@list.delete_at off0 lde = ListDataEvent.new(off0, off0, self, :INTERVAL_REMOVED) fire_handler :LIST_DATA_EVENT, lde return ret end |
#each(&blk) ⇒ Object
changd on 2009-01-14 12:28 based on .. www.ruby-forum.com/topic/175637#769030
59 60 61 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 59 def each(&blk) @list.each(&blk) end |
#find_match(regex, ix0 = 0, ix1 = length()) ⇒ Object
## added 2009-01-14 01:00 searches between given range of rows (def 0 and end) returns row index of first match of given regex (or nil if not found)
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 131 def find_match regex, ix0=0, ix1=length() $log.debug " find_match got #{regex} #{ix0} #{ix1}" @last_regex = regex @search_start_ix = ix0 @search_end_ix = ix1 #@search_found_ix = nil @list.each_with_index do |row, ix| next if ix < ix0 break if ix > ix1 if !row.match(regex).nil? @search_found_ix = ix return ix end end return nil end |
#find_next ⇒ Object
continues previous search
149 150 151 152 153 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 149 def find_next raise "No previous search" if @last_regex.nil? start = @search_found_ix && @search_found_ix+1 || 0 return find_match @last_regex, start, @search_end_ix end |
#find_prev(regex = @last_regex, start = @search_found_ix) ⇒ Object
find backwards, list_data_model Using this to start a search or continue search
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 157 def find_prev regex=@last_regex, start = @search_found_ix raise "No previous search" if regex.nil? # @last_regex.nil? $log.debug " find_prev #{@search_found_ix} : #{@current_index}" start -= 1 unless start == 0 @last_regex = regex @search_start_ix = start start.downto(0) do |ix| row = @list[ix] if !row.match(regex).nil? @search_found_ix = ix return ix end end return nil #return find_match @last_regex, start, @search_end_ix end |
#include?(obj) ⇒ Boolean
114 115 116 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 114 def include?(obj) return @list.include?(obj) end |
#index(obj) ⇒ Object
not sure how to do this XXX removed on 2009-01-14 12:28 def <=>(other)
@list <=> other
end
66 67 68 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 66 def index obj @list.index(obj) end |
#insert(off0, *data) ⇒ Object
72 73 74 75 76 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 72 def insert off0, *data @list.insert off0, *data lde = ListDataEvent.new(off0, off0+data.length-1, self, :INTERVAL_ADDED) fire_handler :LIST_DATA_EVENT, lde end |
#length ⇒ Object Also known as: size
69 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 69 def length ; @list.length; end |
#on_enter_row(object) ⇒ Object
this was just eye candy for some demo
why do we have this here in data, we should remove this
123 124 125 126 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 123 def on_enter_row object $log.debug " XXX on_enter_row of list_data" fire_handler :ENTER_ROW, object end |
#remove_all ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 99 def remove_all return if @list.nil? || @list.empty? # 2010-09-21 13:25 lde = ListDataEvent.new(0, @list.size, self, :INTERVAL_REMOVED) @list = [] @current_index = 0 fire_handler :LIST_DATA_EVENT, lde end |
#slice!(line, howmany) ⇒ Object
added 2010-05-23 12:10 for listeditable
175 176 177 178 179 180 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 175 def slice!(line, howmany) ret = @list.slice!(line, howmany) lde = ListDataEvent.new(line, line+howmany-1, self, :INTERVAL_REMOVED) fire_handler :LIST_DATA_EVENT, lde return ret end |
#update(off0, data) ⇒ Object
82 83 84 85 86 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 82 def update off0, data @list[off0] = data lde = ListDataEvent.new(off0, off0, self, :CONTENTS_CHANGED) fire_handler :LIST_DATA_EVENT, lde end |
#values ⇒ Object Also known as: to_array
returns a ‘dup()` of the list
118 119 120 |
# File 'lib/rbcurse/extras/widgets/rlistbox.rb', line 118 def values @list.dup end |