5 class InboxMode < ThreadIndexMode
7 ## overwrite toggle_archived with archive
8 k.add :archive, "Archive thread (remove from inbox)", 'a'
9 k.add :read_and_archive, "Archive thread (remove from inbox) and mark read", 'A'
10 k.add :refine_search, "Refine search", '|'
14 super [:inbox, :sent, :draft], { :label => :inbox, :skip_killed => true }
15 raise "can't have more than one!" if defined? @@instance
19 def is_relevant? m; (m.labels & [:spam, :deleted, :killed, :inbox]) == Set.new([:inbox]) end
22 text = BufferManager.ask :search, "refine query: ", "label:inbox AND "
23 return unless text && text !~ /^\s*$/
24 SearchResultsMode.spawn_from_query text
27 ## label-list-mode wants to be able to raise us if the user selects
28 ## the "inbox" label, so we need to keep our singletonness around
29 def self.instance; @@instance; end
30 def killable?; false; end
33 return unless cursor_thread
34 thread = cursor_thread # to make sure lambda only knows about 'old' cursor_thread
36 UndoManager.register "archiving thread" do
37 thread.apply_label :inbox
38 add_or_unhide thread.first
41 cursor_thread.remove_label :inbox
42 hide_thread cursor_thread
46 def multi_archive threads
47 UndoManager.register "archiving #{threads.size.pluralize 'thread'}" do
63 return unless cursor_thread
64 thread = cursor_thread # to make sure lambda only knows about 'old' cursor_thread
66 UndoManager.register "reading and archiving thread" do
67 thread.apply_label :inbox
68 thread.apply_label :unread
69 add_or_unhide thread.first
72 cursor_thread.remove_label :unread
73 cursor_thread.remove_label :inbox
74 hide_thread cursor_thread
78 def multi_read_and_archive threads
79 old_labels = threads.map { |t| t.labels.dup }
82 t.remove_label :unread
88 UndoManager.register "reading and archiving #{threads.size.pluralize 'thread'}" do
89 threads.zip(old_labels).each do |t, l|
98 def handle_unarchived_update sender, m
102 def handle_archived_update sender, m
103 t = thread_containing(m) or return
109 super + " #{Index.size} messages in index"