3 class ContactListMode < LineCursorMode
4 LOAD_MORE_CONTACTS_NUM = 10
7 k.add :load_more, "Load #{LOAD_MORE_CONTACTS_NUM} more contacts", 'M'
8 k.add :reload, "Reload contacts", 'R'
9 k.add :alias, "Edit alias for contact", 'a'
10 k.add :toggle_tagged, "Tag/untag current line", 't'
11 k.add :apply_to_tagged, "Apply next command to all tagged items", ';'
12 k.add :search, "Search for messages from particular people", 'S'
15 def initialize mode = :regular
17 @tags = Tagger.new self
22 def lines; @text.length; end
23 def [] i; @text[i]; end
26 p = @contacts[curpos] or return
27 @tags.toggle_tag_for p
28 update_text_for_line curpos
32 def multi_toggle_tagged threads
37 def apply_to_tagged; @tags.apply_to_tagged; end
39 def load; regen_text; end
41 @num += LOAD_MORE_CONTACTS_NUM
43 BufferManager.flash "Loaded #{LOAD_MORE_CONTACTS_NUM} more contacts."
46 def multi_select people
49 mode = ComposeMode.new :to => people
50 BufferManager.spawn "new message", mode
56 p = @contacts[curpos] or return
60 def multi_search people
61 mode = PersonSearchResultsMode.new people
62 BufferManager.spawn "personal search results", mode
63 mode.load_more_threads mode.buffer.content_height
67 p = @contacts[curpos] or return
73 @num = LOAD_MORE_CONTACTS_NUM
78 p = @contacts[curpos] or return
79 a = BufferManager.ask(:alias, "alias for #{p.longname}: ", @user_contacts[p]) or return
81 ContactManager.drop_contact p
83 ContactManager.set_contact p, a
85 update_text_for_line curpos
91 def update_text_for_line line
92 @text[line] = text_for_contact @contacts[line]
96 def text_for_contact p
97 aalias = @user_contacts[p] || ""
98 [[:tagged_color, @tags.tagged?(p) ? ">" : " "],
99 [:none, sprintf("%-#{@awidth}s %-#{@nwidth}s %s", aalias, p.name, p.email)]]
103 @user_contacts = ContactManager.contacts.invert
104 recent = Index.load_contacts AccountManager.user_emails,
107 @contacts = (@user_contacts.keys + recent.select { |p| !@user_contacts[p] }).sort_by { |p| p.sort_by_me + (p.name || "") + p.email }.remove_successive_dupes
109 @awidth, @nwidth = 0, 0
110 @contacts.each do |p|
111 aalias = @user_contacts[p]
112 @awidth = aalias.length if aalias && aalias.length > @awidth
113 @nwidth = p.name.length if p.name && p.name.length > @nwidth
116 @text = @contacts.map { |p| text_for_contact p }
117 buffer.mark_dirty if buffer