]> git.cworth.org Git - sup/blob - lib/sup/modes/inbox-mode.rb
Merge commit 'origin/header-parsing-fix'
[sup] / lib / sup / modes / inbox-mode.rb
1 require 'thread'
2
3 module Redwood
4
5 class InboxMode < ThreadIndexMode
6   register_keymap do |k|
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   end
11
12   def initialize
13     super [:inbox, :sent, :draft], { :label => :inbox, :skip_killed => true }
14     raise "can't have more than one!" if defined? @@instance
15     @@instance = self
16   end
17
18   def is_relevant? m
19     m.has_label?(:inbox) && ([:spam, :deleted, :killed] & m.labels).empty?
20   end
21
22   ## label-list-mode wants to be able to raise us if the user selects
23   ## the "inbox" label, so we need to keep our singletonness around
24   def self.instance; @@instance; end
25   def killable?; false; end
26
27   def archive
28     return unless cursor_thread
29     cursor_thread.remove_label :inbox
30     hide_thread cursor_thread
31     regen_text
32   end
33
34   def multi_archive threads
35     threads.each do |t|
36       t.remove_label :inbox
37       hide_thread t
38     end
39     regen_text
40   end
41
42   def read_and_archive
43     return unless cursor_thread
44     cursor_thread.remove_label :unread
45     cursor_thread.remove_label :inbox
46     hide_thread cursor_thread
47     regen_text
48   end
49
50   def multi_read_and_archive threads
51     threads.each do |t|
52       t.remove_label :unread
53       t.remove_label :inbox
54       hide_thread t
55     end
56     regen_text
57   end
58
59   def handle_unarchived_update sender, m
60     add_or_unhide m
61   end
62
63   def handle_archived_update sender, m
64     t = thread_containing(m) or return
65     hide_thread t
66     regen_text
67   end
68
69   def status
70     super + "    #{Index.size} messages in index"
71   end
72 end
73
74 end