3 class LabelListMode < LineCursorMode
5 k.add :select_label, "Select label", :enter
6 k.add :reload, "Discard label list and reload", 'D'
21 def lines; @text.length end
22 def [] i; @text[i] end
28 buffer.mark_dirty if buffer
33 @labels = LabelManager.listable_label_strings
35 counts = @labels.map do |string|
36 label = LabelManager.label_for string
37 total = Index.num_results_for :label => label
38 unread = Index.num_results_for :labels => [label, :unread]
39 [label, string, total, unread]
42 width = @labels.max_of { |string| string.length }
44 counts.map do |label, string, total, unread|
45 if total == 0 && !LabelManager::RESERVED_LABELS.include?(label)
46 Redwood::log "no hits for label #{label}, deleting"
51 @text << [[(unread == 0 ? :labellist_old_color : :labellist_new_color),
52 sprintf("%#{width + 1}s %5d %s, %5d unread", string, total, total == 1 ? " message" : "messages", unread)]]
53 yield i if block_given?
58 @value, string = @labels[curpos]
59 @done = true if @value