lib/knj/gtk2_cb.rb in knjrbfw-0.0.38 vs lib/knj/gtk2_cb.rb in knjrbfw-0.0.39

- old
+ new

@@ -9,11 +9,11 @@ end class Gtk::ComboBox def init(items) @knj = { - "items" => [] + :items => [] } ls = Gtk::ListStore.new(String, String) cr = Gtk::CellRendererText.new self.pack_start(cr, false) @@ -23,34 +23,33 @@ items.each do |appendob| iter = ls.append if appendob.is_a?(String) iter[0] = appendob - elsif appendob.respond_to?("is_knj?") + elsif appendob.respond_to?(:is_knj?) iter[0] = appendob.title - @knj["items"] << { - "iter" => iter, - "object" => appendob + @knj[:items] << { + :iter => iter, + :object => appendob } end end else - raise "Unsupported type: " + items.class.to_s + raise "Unsupported type: '#{items.class.name}'." end self.model = ls - self.active = 0 end def sel iter = self.active_iter - if @knj["items"].length > 0 - @knj["items"].each do |item| - if item["iter"] == iter - return item["object"] + if @knj[:items].length > 0 + @knj[:items].each do |item| + if item[:iter] == iter + return item[:object] end end return false else @@ -60,14 +59,14 @@ } end end def sel=(actob) - if actob.respond_to?("is_knj?") - @knj["items"].each do |item| - if item["object"].id == actob.id - self.active_iter = item["iter"] + if actob.respond_to?(:is_knj?) + @knj[:items].each do |item| + if item[:object].id == actob.id + self.active_iter = item[:iter] return nil end end else self.model.each do |model, path, iter| @@ -78,8 +77,8 @@ return nil end end end - raise "Could not find such a row: " + textval + raise "Could not find such a row: '#{actob}'." end end \ No newline at end of file