Class: Okayu::LiveListCtrl
- Inherits:
-
Wx::ListCtrl
- Object
- Wx::ListCtrl
- Okayu::LiveListCtrl
- Defined in:
- lib/views/live_panel.rb
Constant Summary collapse
- COLUMNS =
{ :no => 0, :message => 1, :mail => 2, :time => 3, :name => 4, :id => 5, :premium => 6, :ngword => 7 }
Instance Attribute Summary collapse
-
#base_time ⇒ Object
Returns the value of attribute base_time.
Instance Method Summary collapse
- #get_message(index) ⇒ Object
-
#initialize(parent) ⇒ LiveListCtrl
constructor
A new instance of LiveListCtrl.
- #insert_comment(comment) ⇒ Object
- #is_colored?(index) ⇒ Boolean
- #load_column_width ⇒ Object
- #on_activated(event) ⇒ Object
- #on_color_set(index, color_index = nil) ⇒ Object
- #on_color_unset(index) ⇒ Object
- #on_column_resized(event) ⇒ Object
- #on_list_item_right_click(event) ⇒ Object
- #on_name_set(index, name) ⇒ Object
- #on_name_unset(index, name) ⇒ Object
- #on_selected(event) ⇒ Object
- #redraw ⇒ Object
- #rewrite_item(item_index) ⇒ Object
- #same_text_color?(a, b) ⇒ Boolean
- #set_color(target, color) ⇒ Object
- #set_color_to_an_item(index, color) ⇒ Object
- #set_name_to_an_item(index, name) ⇒ Object
- #set_name_to_listener(listener_id, name) ⇒ Object
- #set_name_to_visitor(visitor_id, listener_id, name) ⇒ Object
- #show_color_dialog ⇒ Object
- #show_name_dialog ⇒ Object
Constructor Details
#initialize(parent) ⇒ LiveListCtrl
Returns a new instance of LiveListCtrl.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/views/live_panel.rb', line 27 def initialize(parent) super(parent, :id => Wx::ID_ANY, :style => Wx::LC_REPORT) insert_column COLUMNS[:no], "No", Wx::LIST_FORMAT_LEFT, -1 insert_column COLUMNS[:message], "Message", Wx::LIST_FORMAT_LEFT, -1 insert_column COLUMNS[:mail], "Command", Wx::LIST_FORMAT_LEFT, -1 insert_column COLUMNS[:time], "Time", Wx::LIST_FORMAT_LEFT, -1 insert_column COLUMNS[:name], "Name", Wx::LIST_FORMAT_LEFT, -1 insert_column COLUMNS[:id], "Id", Wx::LIST_FORMAT_LEFT, -1 insert_column COLUMNS[:premium], "Premium", Wx::LIST_FORMAT_LEFT, -1 insert_column COLUMNS[:ngword], "NG word", Wx::LIST_FORMAT_LEFT, -1 load_column_width evt_list_col_end_drag(Wx::ID_ANY){|event| on_column_resized(event)} evt_list_item_right_click(get_id) {|event| on_list_item_right_click(event)} evt_list_item_activated(Wx::ID_ANY) {|event| on_activated(event)} evt_list_item_selected(Wx::ID_ANY) {|event| on_selected(event)} evt_key_down(){|event| get_parent.on_key_down(event)} (DYE){show_color_dialog} (NAME){show_name_dialog} end |
Instance Attribute Details
#base_time ⇒ Object
Returns the value of attribute base_time.
25 26 27 |
# File 'lib/views/live_panel.rb', line 25 def base_time @base_time end |
Instance Method Details
#get_message(index) ⇒ Object
215 216 217 |
# File 'lib/views/live_panel.rb', line 215 def index get_item_data(index)[:message] end |
#insert_comment(comment) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/views/live_panel.rb', line 62 def insert_comment comment item = Wx::ListItem.new item.set_data({:id => comment.id, :message => comment., :visitor_id => comment.visitor_id, :listener_id => comment.visitor.listener_id}) item.set_id 0 item.set_column COLUMNS[:no] item.set_text comment.number.to_s if comment.visitor.listener if color_index = comment.visitor.listener.color_index item.color COLORS[color_index] end elsif comment.visitor if color_index = comment.visitor.color_index item.color COLORS[color_index] end end insert_item(item) item.set_column COLUMNS[:message] item.set_text comment. set_item(item) item.set_column COLUMNS[:mail] item.set_text comment.mail set_item(item) item.set_column COLUMNS[:time] item.set_text Time.at(comment.commented_at - @base_time).strftime("%M:%S") set_item(item) if comment.visitor.listener item.set_column COLUMNS[:name] item.set_text comment.visitor.listener.name set_item(item) end item.set_column COLUMNS[:id] item.set_text comment.user_id || comment.visitor.user_id set_item(item) item.set_column COLUMNS[:premium] if comment.owner item.set_text '主' elsif comment.premium item.set_text 'P' elsif comment.command item.set_text 'System' else item.set_text '' end set_item(item) end |
#is_colored?(index) ⇒ Boolean
219 220 221 222 |
# File 'lib/views/live_panel.rb', line 219 def is_colored? index get_item_background_colour(index) != Wx::NULL_COLOUR && get_item_background_colour(index) != COLORS[WHITE][:color] end |
#load_column_width ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/views/live_panel.rb', line 50 def load_column_width return unless UserInfo.column_width set_column_width COLUMNS[:no], UserInfo.column_width[:no] set_column_width COLUMNS[:message], UserInfo.column_width[:message] set_column_width COLUMNS[:mail], UserInfo.column_width[:mail] set_column_width COLUMNS[:time], UserInfo.column_width[:time] set_column_width COLUMNS[:name], UserInfo.column_width[:name] set_column_width COLUMNS[:id], UserInfo.column_width[:id] set_column_width COLUMNS[:premium], UserInfo.column_width[:premium] set_column_width COLUMNS[:ngword], UserInfo.column_width[:ngword] end |
#on_activated(event) ⇒ Object
224 225 226 227 228 229 230 231 |
# File 'lib/views/live_panel.rb', line 224 def on_activated event @selected_index = event.get_index if is_colored?(@selected_index) on_color_unset @selected_index else on_color_set @selected_index end end |
#on_color_set(index, color_index = nil) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/views/live_panel.rb', line 241 def on_color_set index, color_index=nil color_index = rand(COLORS.length) unless color_index data = get_item_data(index) return unless data if data[:listener_id] listener = Listener.find(data[:listener_id]) same_text_color = same_text_color?(listener.color_index, color_index) listener.color_index = color_index listener.save if same_text_color set_color({:listener_id => data[:listener_id]}, COLORS[color_index]) else redraw end else visitor = Visitor.find(data[:visitor_id]) same_text_color = same_text_color?(visitor.color_index, color_index) visitor.color_index = color_index visitor.save if same_text_color set_color({:visitor_id => data[:visitor_id]}, COLORS[color_index]) else redraw end end end |
#on_color_unset(index) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/views/live_panel.rb', line 269 def on_color_unset index data = get_item_data(index) return unless data if data[:listener_id] listener = Listener.find(data[:listener_id]) old_color_index = listener.color_index listener.color_index = nil listener.save if COLORS[old_color_index||WHITE][:white_text] redraw else set_color({:listener_id => data[:listener_id]}, COLORS[WHITE]) end else visitor = Visitor.find(data[:visitor_id]) old_color_index = visitor.color_index visitor.color_index = nil visitor.save if COLORS[old_color_index||WHITE][:white_text] redraw else set_color({:visitor_id => data[:visitor_id]}, COLORS[WHITE]) end end end |
#on_column_resized(event) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/views/live_panel.rb', line 164 def on_column_resized event column = event.get_column if UserInfo[:column_width] UserInfo[:column_width][COLUMNS.index(column)] = get_column_width(column) else UserInfo[:column_width] = { :no => get_column_width(COLUMNS[:no]), :message => get_column_width(COLUMNS[:message]), :mail => get_column_width(COLUMNS[:mail]), :time => get_column_width(COLUMNS[:time]), :name => get_column_width(COLUMNS[:name]), :id => get_column_width(COLUMNS[:id]), :premium => get_column_width(COLUMNS[:premium]), :ngword => get_column_width(COLUMNS[:ngword]) } end end |
#on_list_item_right_click(event) ⇒ Object
182 183 184 185 186 187 188 |
# File 'lib/views/live_panel.rb', line 182 def on_list_item_right_click event @selected_item_text = get_item_text(event.get_index) # code for windows = Wx::Menu.new .append(DYE, "色をつける(&C)", "") .append(NAME, "名前をつける(&M)", "") (, event.get_point) end |
#on_name_set(index, name) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/views/live_panel.rb', line 325 def on_name_set index, name data = get_item_data(index) return unless data if data[:listener_id] listener = Listener.find(data[:listener_id]) listener.name = name listener.save set_name_to_listener(data[:listener_id], name) else visitor = Visitor.find(data[:visitor_id]) visitor.create_listener(:name => name) visitor.save set_name_to_visitor(data[:visitor_id], visitor.listener_id, name) end end |
#on_name_unset(index, name) ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/views/live_panel.rb', line 342 def on_name_unset index, name data = get_item_data(index) return unless data visitor = Visitor.find(data[:visitor_id]) visitor.listener_id = nil visitor.save if data[:listener_id] listener = Listener.find data[:listener_id] if listener.visitors.size == 0 listener.destroy end end set_name_to_visitor data[:visitor_id], nil, '' end |
#on_selected(event) ⇒ Object
233 234 235 |
# File 'lib/views/live_panel.rb', line 233 def on_selected event @selected_index = event.get_index end |
#redraw ⇒ Object
312 313 314 315 316 |
# File 'lib/views/live_panel.rb', line 312 def redraw get_parent.pause get_parent.redraw_list @selected_index get_parent.resume end |
#rewrite_item(item_index) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/views/live_panel.rb', line 120 def rewrite_item item_index item = get_item(item_index) comment = Comment.find item.get_data[:id] item.set_id 0 item.set_column COLUMNS[:no] item.set_text comment.number.to_s set_item(item) item.set_column COLUMNS[:message] item.set_text comment. set_item(item) item.set_column COLUMNS[:mail] item.set_text comment.mail set_item(item) item.set_column COLUMNS[:time] item.set_text Time.at(comment.commented_at - @base_time).strftime("%M:%S") set_item(item) if comment.visitor.listener item.set_column COLUMNS[:name] item.set_text comment.visitor.listener.name set_item(item) end item.set_column COLUMNS[:id] item.set_text comment.user_id || comment.visitor.user_id set_item(item) item.set_column COLUMNS[:premium] if comment.owner item.set_text '主' elsif comment.premium item.set_text 'P' elsif comment.command item.set_text 'System' else item.set_text '' end set_item(item) end |
#same_text_color?(a, b) ⇒ Boolean
237 238 239 |
# File 'lib/views/live_panel.rb', line 237 def same_text_color? a, b COLORS[a||WHITE][:white_text] == COLORS[b||WHITE][:white_text] end |
#set_color(target, color) ⇒ Object
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/views/live_panel.rb', line 296 def set_color target, color if target[:listener_id] self.each do |index| if get_item_data(index)[:listener_id] == target[:listener_id] set_color_to_an_item(index, color) end end elsif target[:visitor_id] self.each do |index| if get_item_data(index)[:visitor_id] == target[:visitor_id] set_color_to_an_item(index, color) end end end end |
#set_color_to_an_item(index, color) ⇒ Object
318 319 320 321 322 323 |
# File 'lib/views/live_panel.rb', line 318 def set_color_to_an_item index, color set_item_background_colour(index, color[:color]) if color[:white_text] get_item(index).set_text_colour(COLORS[WHITE][:color]) end end |
#set_name_to_an_item(index, name) ⇒ Object
378 379 380 381 382 383 |
# File 'lib/views/live_panel.rb', line 378 def set_name_to_an_item index, name item = get_item(index) item.set_column COLUMNS[:name] item.set_text(name) set_item(item) end |
#set_name_to_listener(listener_id, name) ⇒ Object
359 360 361 362 363 364 365 |
# File 'lib/views/live_panel.rb', line 359 def set_name_to_listener listener_id, name self.each do |index| if get_item_data(index)[:listener_id] == listener_id set_name_to_an_item(index, name) end end end |
#set_name_to_visitor(visitor_id, listener_id, name) ⇒ Object
367 368 369 370 371 372 373 374 375 376 |
# File 'lib/views/live_panel.rb', line 367 def set_name_to_visitor visitor_id, listener_id, name self.each do |index| data = get_item_data(index) if data[:visitor_id] == visitor_id data[:listener_id] = listener_id set_item_data(index, data) set_name_to_an_item(index, name) end end end |
#show_color_dialog ⇒ Object
190 191 192 193 194 195 196 197 198 |
# File 'lib/views/live_panel.rb', line 190 def show_color_dialog dialog = ColorDialog.new(self) color_index = dialog.show_modal item_index = get_selections.first # get_selections won't work in windows item_index = find_item(-1, @selected_item_text) unless item_index # code for windows if color_index >= 0 && color_index < COLORS.length on_color_set item_index, color_index end end |
#show_name_dialog ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/views/live_panel.rb', line 200 def show_name_dialog = (@selected_index) =~ /(@|@)(.*)/ default_name = $2 || '' dialog = Wx::TextEntryDialog.new(self, "名前を入力してください", "名前の設定", default_name) dialog.show_modal item_index = get_selections.first # get_selections won't work in windows item_index = find_item(-1, @selected_item_text) unless item_index # code for windows if (name = dialog.get_value) != '' on_name_set(item_index, name) else on_name_unset(item_index, name) end end |