Class: QDA::GUI::CategoryDropDown
- Inherits:
-
Wx::ComboBox
- Object
- Wx::ComboBox
- QDA::GUI::CategoryDropDown
- Includes:
- ListLikeItemData, Subscriber
- Defined in:
- lib/weft/wxgui/controls/category_dropdown.rb
Constant Summary collapse
- MAXIMUM_DROPDOWN_LENGTH =
7
Instance Attribute Summary collapse
-
#sticky ⇒ Object
Returns the value of attribute sticky.
Instance Method Summary collapse
- #append_item(cat) ⇒ Object
-
#current_category ⇒ Object
returns the Category object associated with the currently selected item in the drop down.
- #delete_first ⇒ Object
- #find_and_add_categories ⇒ Object
-
#find_string(str) ⇒ Object
missing in wxruby, but part of WxWidgets this version differs by returning nil rather than -1 on failure.
-
#initialize(app, parent, text_box = nil, locked = false) ⇒ CategoryDropDown
constructor
locked
if true will prevent the dropdown from responding to global category focus events. -
#lock ⇒ Object
make this dropdown receive global :focus_category events.
-
#locked? ⇒ Boolean
is this dropdown responding to global :focus_category events?.
- #on_blur(e) ⇒ Object
-
#on_item_selected(e) ⇒ Object
highlight text coded by the newly-selected category.
- #prepend_item(the_cat) ⇒ Object
- #receive_category_changed(cat) ⇒ Object
-
#receive_category_deleted(cat) ⇒ Object
if a category is deleted it should be removed from the list.
-
#receive_focus_category(cat) ⇒ Object
add the newly-focused category to this dropdown and highlight its text.
- #redraw ⇒ Object
- #remove_item(the_cat) ⇒ Object
- #set_active_category(category) ⇒ Object
-
#set_broken(bool) ⇒ Object
TODO - some visual cue to indicate that no category matched find-first.
-
#set_selection(idx) ⇒ Object
highlight text coded by the category on the way.
- #set_warning(bool) ⇒ Object
- #trim(to_length = MAXIMUM_DROPDOWN_LENGTH) ⇒ Object
-
#unlock ⇒ Object
prevent this dropdown responding to global :focus_category events.
- #update_item(the_cat) ⇒ Object
Methods included from ListLikeItemData
#data, #delete_item_data, #index, #push_item_data, #unshift_item_data
Methods included from ItemData
#get_item_data, #set_item_data, #value_to_ident
Methods included from Subscriber
Constructor Details
#initialize(app, parent, text_box = nil, locked = false) ⇒ CategoryDropDown
locked
if true will prevent the dropdown from responding to global category focus events.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 11 def initialize(app, parent, text_box = nil, locked = false) super(parent, -1, '', Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, []) @locked = locked @client_data = {} @text_box = text_box @sticky = false @app = app evt_kill_focus() do | e | find_and_add_categories() e.skip() end evt_text_enter(self.get_id) do | e | find_and_add_categories() end evt_combobox(self.get_id) do | e | e.skip() on_item_selected(e) end subscribe(@app, :focus_category, :category_deleted, :category_changed) if @app.current_category set_active_category(@app.current_category) end end |
Instance Attribute Details
#sticky ⇒ Object
Returns the value of attribute sticky.
7 8 9 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 7 def sticky @sticky end |
Instance Method Details
#append_item(cat) ⇒ Object
49 50 51 52 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 49 def append_item(cat) push_item_data(cat) append(cat.name, nil) end |
#current_category ⇒ Object
returns the Category object associated with the currently selected item in the drop down.
186 187 188 189 190 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 186 def current_category if curr_sel = get_selection() and curr_sel >= 0 return get_client_data( curr_sel ) end end |
#delete_first ⇒ Object
109 110 111 112 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 109 def delete_first() delete(0) data.shift end |
#find_and_add_categories ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 133 def find_and_add_categories() typed_text = get_value() return if find_string( typed_text ) return if typed_text.empty? matches = @app.app.get_categories_by_path(typed_text) matches.each do | cat | prepend_item(cat) unless cat.parent.nil? end trim(matches.length) if count > MAXIMUM_DROPDOWN_LENGTH set_selection( 0 ) end |
#find_string(str) ⇒ Object
missing in wxruby, but part of WxWidgets this version differs by returning nil rather than -1 on failure
168 169 170 171 172 173 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 168 def find_string(str) ( 0 ... count ).each do | i | return i if str == get_string(i) end return nil end |
#lock ⇒ Object
make this dropdown receive global :focus_category events
82 83 84 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 82 def lock @locked = true end |
#locked? ⇒ Boolean
is this dropdown responding to global :focus_category events?
77 78 79 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 77 def locked? @locked ? true : false end |
#on_blur(e) ⇒ Object
161 162 163 164 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 161 def on_blur(e) find_and_add_categories() e.skip() end |
#on_item_selected(e) ⇒ Object
highlight text coded by the newly-selected category
99 100 101 102 103 104 105 106 107 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 99 def on_item_selected(e) if @text_box if category = current_category @text_box.highlight_codingtable(category.codes) else @text_box.unhighlight() end end end |
#prepend_item(the_cat) ⇒ Object
54 55 56 57 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 54 def prepend_item(the_cat) unshift_item_data(the_cat) redraw() end |
#receive_category_changed(cat) ⇒ Object
156 157 158 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 156 def receive_category_changed(cat) update_item(cat) end |
#receive_category_deleted(cat) ⇒ Object
if a category is deleted it should be removed from the list
152 153 154 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 152 def receive_category_deleted(cat) remove_item(cat) end |
#receive_focus_category(cat) ⇒ Object
add the newly-focused category to this dropdown and highlight its text.
147 148 149 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 147 def receive_focus_category(cat) set_active_category(cat) unless locked? end |
#redraw ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 41 def redraw() delete(0) while count.nonzero? data.each_with_index do | item, i | append(item.name, nil) end set_selection(0) end |
#remove_item(the_cat) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 66 def remove_item(the_cat) if i = value_to_ident(the_cat) delete(i) data.delete_at(i) if count.zero? set_selection(0) end end end |
#set_active_category(category) ⇒ Object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 114 def set_active_category(category) # clear the first node unless it is sticky because it has been used, # or if the category is already in the list delete_first unless @sticky or value_to_ident(category) trim() prepend_item(category) @sticky = false set_selection(0) end |
#set_broken(bool) ⇒ Object
TODO - some visual cue to indicate that no category matched find-first
177 178 179 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 177 def set_broken(bool) end |
#set_selection(idx) ⇒ Object
highlight text coded by the category on the way.
93 94 95 96 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 93 def set_selection(idx) super(idx) on_item_selected(nil) end |
#set_warning(bool) ⇒ Object
181 182 183 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 181 def set_warning(bool) end |
#trim(to_length = MAXIMUM_DROPDOWN_LENGTH) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 125 def trim(to_length = MAXIMUM_DROPDOWN_LENGTH) # clear any remaining excess items while count > to_length data.delete_at(count - 1) delete(count - 1) end end |
#unlock ⇒ Object
prevent this dropdown responding to global :focus_category events
87 88 89 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 87 def unlock @locked = false end |
#update_item(the_cat) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/weft/wxgui/controls/category_dropdown.rb', line 59 def update_item(the_cat) if i = value_to_ident(the_cat) set_item_data(i, the_cat) redraw() end end |