Module: Alexandria::ComboBoxOverrides
- Extended by:
- GetText
- Includes:
- GetText
- Defined in:
- lib/alexandria/ui/libraries_combo.rb
Instance Method Summary collapse
- #populate_with_libraries(libraries, selected_library) ⇒ Object
- #selection_from_libraries(libraries) ⇒ Object
Instance Method Details
#populate_with_libraries(libraries, selected_library) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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 set_row_separator_func do |model, iter| # TODO: Replace with iter[1] if possible model.get_value(iter, 1) == '-' end self.model = Gtk::ListStore.new(GdkPixbuf::Pixbuf, String, TrueClass) libraries_names.each do |library_name| iter = model.append iter[0] = Alexandria::UI::Icons::LIBRARY_SMALL iter[1] = library_name iter[2] = false end model.append[1] = '-' iter = model.append iter[0] = Alexandria::UI::Icons::LIBRARY_SMALL iter[1] = _('New Library') iter[2] = 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) 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) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/alexandria/ui/libraries_combo.rb', line 64 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 |