Skip to content

Commit

Permalink
Add Listbox.index and Listbox.rename.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomthom committed Aug 15, 2014
1 parent 32c415e commit 274b38b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def self.show

list = %w{ Hello World Lorem Ipsum Single'Quote Double'Quote }
lst_list = SKUI::Listbox.new( list )
lst_list.name = :lst_test
lst_list.size = 4
lst_list.multiple = true
lst_list.value = lst_list.items.first
Expand Down
8 changes: 8 additions & 0 deletions src/SKUI/js/ui.listbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ Listbox.remove_item = function( ui_id, index ) {
return index;
};

Listbox.rename = function( ui_id, index, value ) {
$control = $('#' + ui_id);
$select = $control.children('select');
$items = $select.children('option');
$items.eq(index).text(value);
return;
};

Listbox.prototype.set_items = function( value ) {
$select = this.control.children('select');
$select.empty();
Expand Down
33 changes: 33 additions & 0 deletions src/SKUI/listbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ def clear
nil
end

# @param [String] string
#
# @return [Integer]
# @since 1.0.0
def index( value )
unless value.is_a?(String)
raise( ArgumentError, 'Value must be a string.' )
end
items.index( value )
end

# @overload insert(index, string, ...)
# @param [String] string
#
Expand Down Expand Up @@ -150,6 +161,28 @@ def remove_item( arg )
nil
end

# @param [Integer] index
# @param [String] value
#
# @return [Boolean]
# @since 1.0.0
def rename( index, value )
unless index.is_a?(Integer)
raise( ArgumentError, 'Index must be an integer.' )
end
unless value.is_a?(String)
raise( ArgumentError, 'Value must be a string.' )
end
puts "rename"
if index > 0 && index < @properties[ :items ].size
@properties[ :items ][ index ] = value
window.bridge.call( 'UI.Listbox.rename', ui_id, index, value )
true
else
false
end
end

# @param [Integer] value
#
# @return [Integer]
Expand Down

0 comments on commit 274b38b

Please sign in to comment.