Class: Rediscover::SetElementList
- Inherits:
-
Wx::ListCtrl
- Object
- Wx::ListCtrl
- Rediscover::SetElementList
- Includes:
- Wx
- Defined in:
- lib/rediscover/set_element_list.rb
Instance Method Summary collapse
- #delete(selections) ⇒ Object
- #do_on_save ⇒ Object
- #get_ctx_menu_for_selections(selections) ⇒ Object
-
#initialize(parent, key, elements) ⇒ SetElementList
constructor
A new instance of SetElementList.
- #list_item_right_click_evt(event) ⇒ Object
- #on_save(&block) ⇒ Object
- #set_elements(elements) ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize(parent, key, elements) ⇒ SetElementList
Returns a new instance of SetElementList.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rediscover/set_element_list.rb', line 5 def initialize(parent, key, elements) @parent, @key = parent, key @redis = get_app.redis @logger = get_app.logger super(parent, :style => LC_REPORT) setup set_elements(elements) end |
Instance Method Details
#delete(selections) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rediscover/set_element_list.rb', line 29 def delete(selections) delete_elements = selections.map { |index| @elements[index] } delete_elements.each do |element| @elements.delete(element) @redis.srem(@key, element) delete_item(find_item(0, element)) end update do_on_save end |
#do_on_save ⇒ Object
65 66 67 |
# File 'lib/rediscover/set_element_list.rb', line 65 def do_on_save @on_save_block.call() if @on_save_block end |
#get_ctx_menu_for_selections(selections) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rediscover/set_element_list.rb', line 45 def (selections) return nil if selections.empty? @ctx_menu = Menu.new # delete menu item @ctx_delete_item = MenuItem.new(@ctx_menu, -1, 'Delete') (@ctx_delete_item) do if ID_YES == Dialog::Confirm.new(self, 'Really delete selected element(s)?', 'Really delete?').show_modal delete(selections) end end @ctx_menu.append_item(@ctx_delete_item) @ctx_menu end |
#list_item_right_click_evt(event) ⇒ Object
40 41 42 43 |
# File 'lib/rediscover/set_element_list.rb', line 40 def list_item_right_click_evt(event) = (get_selections) (, event.get_point) if end |
#on_save(&block) ⇒ Object
61 62 63 |
# File 'lib/rediscover/set_element_list.rb', line 61 def on_save(&block) @on_save_block = block end |
#set_elements(elements) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/rediscover/set_element_list.rb', line 22 def set_elements(elements) delete_all_items i = 0 elements.each { |element| insert_item(i, element); i += 1 } @elements = elements end |
#setup ⇒ Object
16 17 18 19 20 |
# File 'lib/rediscover/set_element_list.rb', line 16 def setup insert_column(0, 'Elements') set_column_width(LIST_AUTOSIZE, -1) evt_list_item_right_click self, :list_item_right_click_evt end |