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 if !$config[:inbox_newest_first].nil?
15 $config[:inbox_newest_first]
22 super [:inbox, :sent, :draft], { :label => :inbox, :skip_killed => true }
23 raise "can't have more than one!" if defined? @@instance
25 @newest_first = InboxMode.newest_first
28 def is_relevant? m; (m.labels & [:spam, :deleted, :killed, :inbox]) == Set.new([:inbox]) end
31 text = BufferManager.ask :search, "refine query: ", "label:inbox AND "
32 return unless text && text !~ /^\s*$/
33 SearchResultsMode.spawn_from_query text, @newest_first
36 ## label-list-mode wants to be able to raise us if the user selects
37 ## the "inbox" label, so we need to keep our singletonness around
38 def self.instance; @@instance; end
39 def killable?; false; end
42 return unless cursor_thread
43 thread = cursor_thread # to make sure lambda only knows about 'old' cursor_thread
45 UndoManager.register "archiving thread" do
46 thread.apply_label :inbox
47 add_or_unhide thread.first
50 cursor_thread.remove_label :inbox
51 hide_thread cursor_thread
55 def multi_archive threads
56 UndoManager.register "archiving #{threads.size.pluralize 'thread'}" do
72 return unless cursor_thread
73 thread = cursor_thread # to make sure lambda only knows about 'old' cursor_thread
75 UndoManager.register "reading and archiving thread" do
76 thread.apply_label :inbox
77 thread.apply_label :unread
78 add_or_unhide thread.first
81 cursor_thread.remove_label :unread
82 cursor_thread.remove_label :inbox
83 hide_thread cursor_thread
87 def multi_read_and_archive threads
88 old_labels = threads.map { |t| t.labels.dup }
91 t.remove_label :unread
97 UndoManager.register "reading and archiving #{threads.size.pluralize 'thread'}" do
98 threads.zip(old_labels).each do |t, l|
100 add_or_unhide t.first
107 def handle_unarchived_update sender, m
111 def handle_archived_update sender, m
112 t = thread_containing(m) or return
118 super + " #{Index.size} messages in index"