module Alexandria::ComboBoxOverrides
Public Instance Methods
append_entry(icon, label, is_new)
click to toggle source
# File lib/alexandria/ui/libraries_combo.rb, line 77 def append_entry(icon, label, is_new) iter = model.append iter[0] = icon iter[1] = label iter[2] = is_new end
populate_with_libraries(libraries, selected_library)
click to toggle source
# File lib/alexandria/ui/libraries_combo.rb, line 29 def populate_with_libraries(libraries, selected_library) libraries_names = libraries.map(&:name) if selected_library libraries_names.delete selected_library.name libraries_names.unshift selected_library.name end clear self.model = Gtk::ListStore.new(GdkPixbuf::Pixbuf, String, TrueClass) libraries_names.each do |library_name| append_entry(Alexandria::UI::Icons::LIBRARY_SMALL, library_name, false) end append_entry(nil, "-", nil) append_entry(Alexandria::UI::Icons::LIBRARY_SMALL, _("New Library"), true) renderer = Gtk::CellRendererPixbuf.new pack_start(renderer, false) set_attributes(renderer, pixbuf: 0) renderer = Gtk::CellRendererText.new pack_start(renderer, true) set_attributes(renderer, text: 1) set_row_separator_func do |model, iter| # TODO: Replace with iter[1] if possible model.get_value(iter, 1) == "-" end self.active = 0 # self.sensitive = libraries.length > 1 # This prohibits us from adding a "New Library" from this combo # when we only have a single library end
selection_from_libraries(libraries)
click to toggle source
# File lib/alexandria/ui/libraries_combo.rb, line 58 def selection_from_libraries(libraries) iter = active_iter is_new = false library = nil if iter[2] name = Alexandria::Library.generate_new_name(libraries) library = Alexandria::Library.load(name) libraries << library is_new = true else library = libraries.find do |x| x.name == active_iter[1] end end raise unless library [library, is_new] end