3 class LabelListMode < LineCursorMode
5 k.add :select_label, "Search by label", :enter
6 k.add :reload, "Discard label list and reload", '@'
7 k.add :toggle_show_unread_only, "Toggle between all labels and those with unread mail", :tab
21 def lines; @text.length end
22 def [] i; @text[i] end
26 "No labels with unread messages"
33 def toggle_show_unread_only
34 @unread_only = !@unread_only
40 buffer.mark_dirty if buffer
45 labels = LabelManager.listable_labels
47 counts = labels.map do |label|
48 string = LabelManager.string_for label
49 total = Index.num_results_for :label => label
50 unread = Index.num_results_for :labels => [label, :unread]
51 [label, string, total, unread]
52 end.sort_by { |l, s, t, u| s.downcase }
54 width = counts.max_of { |l, s, t, u| s.length }
57 counts.delete_if { | l, s, t, u | u == 0 }
61 counts.map do |label, string, total, unread|
62 if total == 0 && !LabelManager::RESERVED_LABELS.include?(label)
63 Redwood::log "no hits for label #{label}, deleting"
64 LabelManager.delete label
68 @text << [[(unread == 0 ? :labellist_old_color : :labellist_new_color),
69 sprintf("%#{width + 1}s %5d %s, %5d unread", string, total, total == 1 ? " message" : "messages", unread)]]
71 yield i if block_given?
76 @value, string = @labels[curpos]
78 LabelSearchResultsMode.spawn_nicely @value