Class: Alexandria::UI::IconViewTooltips

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/alexandria/ui/iconview_tooltips.rb

Instance Method Summary collapse

Methods included from Logging

included, #log

Constructor Details

#initialize(view) ⇒ IconViewTooltips

Returns a new instance of IconViewTooltips.



22
23
24
# File 'lib/alexandria/ui/iconview_tooltips.rb', line 22

def initialize(view)
  set_view(view)
end

Instance Method Details

#label_for_book(title, authors, publisher, year) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/alexandria/ui/iconview_tooltips.rb', line 42

def label_for_book(title, authors, publisher, year)
  # This is much too complex... but it works for now!
  html = ""
  unless title.empty?
    html += "<b>#{CGI.escapeHTML(title)}</b>"
    html += "\n" unless authors.empty?
  end
  html += "<i>#{CGI.escapeHTML(authors)}</i>" unless authors.empty?
  html += "\n" if !title.empty? || !authors.empty?

  html += "<small>"
  html += CGI.escapeHTML(publisher).to_s if publisher && !publisher.empty?

  if year && !year.empty?
    html += " " if publisher && !publisher.empty?
    html += "(#{year})"
  end

  html + "</small>"
end

#set_view(view) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/alexandria/ui/iconview_tooltips.rb', line 26

def set_view(view)
  view.has_tooltip = true
  view.signal_connect("query-tooltip") do |_widget, x, y, _keyboard_mode, tooltip|
    tree_path = view.get_path_at_pos(x, y)
    if tree_path
      iter = view.model.get_iter(tree_path)

      title = iter[2] # HACK: hardcoded, should use column names...
      authors = iter[4]
      publisher = iter[6]
      year = iter[7]
      tooltip.set_markup label_for_book(title, authors, publisher, year)
    end
  end
end