Module: Bewildr::ControlTypeAdditions::ComboBoxAdditions
- Defined in:
- lib/bewildr/control_type_additions/combo_box_additions.rb
Instance Method Summary collapse
-
#collapse_combo ⇒ Object
Collapses the combobox.
-
#count ⇒ Object
Returns the number of items in the combobox.
-
#expand_combo ⇒ Object
Expands the combobox.
-
#items ⇒ Object
Returns a string array containing the element’s item names.
-
#list_items ⇒ Object
Returns an array containing the combobox items.
-
#select(input) ⇒ Object
Selects a combobox item.
-
#select_by_index(input) ⇒ Object
Selects the item at the supplied position.
-
#select_by_name(input) ⇒ Object
Selects the first item whose name matches the input.
-
#selected ⇒ Object
Returns the selected combobox item.
Instance Method Details
#collapse_combo ⇒ Object
Collapses the combobox
76 77 78 79 80 81 |
# File 'lib/bewildr/control_type_additions/combo_box_additions.rb', line 76 def collapse_combo collapse Timeout.timeout(30) do sleep 0.2 until == :collapsed end end |
#count ⇒ Object
Returns the number of items in the combobox
22 23 24 |
# File 'lib/bewildr/control_type_additions/combo_box_additions.rb', line 22 def count items.size end |
#expand_combo ⇒ Object
Expands the combobox
68 69 70 71 72 73 |
# File 'lib/bewildr/control_type_additions/combo_box_additions.rb', line 68 def Timeout.timeout(30) do sleep 0.2 until == :expanded end end |
#items ⇒ Object
Returns a string array containing the element’s item names
7 8 9 |
# File 'lib/bewildr/control_type_additions/combo_box_additions.rb', line 7 def items list_items.collect {|item| item.name} end |
#list_items ⇒ Object
Returns an array containing the combobox items
12 13 14 15 16 17 18 19 |
# File 'lib/bewildr/control_type_additions/combo_box_additions.rb', line 12 def list_items begin get(:type => :list_item, :scope => :children, :how_many => :all) ensure collapse_combo end end |
#select(input) ⇒ Object
Selects a combobox item. Takes a string (and selects the first item whose name matches) or an integer and selects the respective element
27 28 29 30 31 32 33 |
# File 'lib/bewildr/control_type_additions/combo_box_additions.rb', line 27 def select(input) case input when String then select_by_name(input) when Integer then select_by_index(input) else raise ArgumentError, "Select by name or by index" end end |
#select_by_index(input) ⇒ Object
Selects the item at the supplied position
48 49 50 51 52 53 54 55 56 |
# File 'lib/bewildr/control_type_additions/combo_box_additions.rb', line 48 def select_by_index(input) raise "Index must be 0 or greater" if input < 0 begin list_items[input].select ensure collapse_combo end end |
#select_by_name(input) ⇒ Object
Selects the first item whose name matches the input
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bewildr/control_type_additions/combo_box_additions.rb', line 36 def select_by_name(input) begin my_item = list_items.find {|item| item.name == input} raise Bewildr::NoSuchItemInComboBox if my_item.nil? my_item.select ensure collapse_combo end end |
#selected ⇒ Object
Returns the selected combobox item
59 60 61 62 63 64 65 |
# File 'lib/bewildr/control_type_additions/combo_box_additions.rb', line 59 def selected #TODO: find a way to not need to expand and collapse before getting the selected item collapse_combo #get_selection.first get_selection.first end |