class Alexandria::UI::CompletionModels
Constants
- TAG
Public Class Methods
new()
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 82 def initialize @models = [] @libraries = [] 5.times { @models << Gtk::ListStore.new(String) } @models << Gtk::ListStore.new(String) touch end
Public Instance Methods
add_source(library)
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 90 def add_source(library) @libraries << library library.add_observer(self) touch end
borrower_model()
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 132 def borrower_model rebuilds_models if dirty? @models[BORROWER] end
edition_model()
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 127 def edition_model rebuild_models if dirty? @models[EDITION] end
models()
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 107 def models rebuild_models if dirty? @models end
publisher_model()
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 122 def publisher_model rebuild_models if dirty? @models[PUBLISHER] end
remove_source(library)
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 96 def remove_source(library) @libraries.delete_if { |x| x.name == library.name } library.delete_observer(self) touch end
tag_model()
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 137 def tag_model rebuilds_models if dirty? @models[TAG] end
title_model()
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 112 def title_model rebuild_models if dirty? @models[TITLE] end
update(_library, _kind, _book)
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 102 def update(_library, _kind, _book) # FIXME: Do not rebuild all the models there. touch end
Private Instance Methods
dirty?()
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 148 def dirty? @dirty end
fill_model(model, values)
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 184 def fill_model(model, values) model.clear iter = nil values.uniq.each do |value| next if value.nil? iter = iter ? model.insert_after(iter) : model.append iter[0] = value end end
rebuild_models()
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 152 def rebuild_models titles = [] authors = [] publishers = [] editions = [] borrowers = [] tags = [] @libraries.each do |library| library.each do |book| titles << book.title authors.concat(book.authors) publishers << book.publisher editions << book.edition borrowers << book.loaned_to # TODO: Ensure #tags is always an array tags.concat(book.tags) if book.tags end end borrowers.uniq! tags.uniq! fill_model(@models[TITLE], titles) fill_model(@models[AUTHOR], authors) fill_model(@models[EDITION], editions) fill_model(@models[PUBLISHER], publishers) fill_model(@models[BORROWER], borrowers) fill_model(@models[TAG], tags) @dirty = false end
touch()
click to toggle source
# File lib/alexandria/ui/completion_models.rb, line 144 def touch @dirty = true end