bm.spawn_unless_exists("Buffer List") { BufferListMode.new }
when :list_contacts
b = bm.spawn_unless_exists("Contact List") { ContactListMode.new }
- b.mode.load_more b.content_height
+ b.mode.load_in_background
when :search
text = bm.ask :search, "query: "
next unless text && text !~ /^\s*$/
rescue Ferret::QueryParser::QueryParseException => e
bm.flash "Couldn't parse query."
end
-
when :list_labels
b = bm.spawn_unless_exists("Label List") { LabelListMode.new }
b.mode.load_in_background
register_keymap do |k|
k.add :load_more, "Load #{LOAD_MORE_CONTACTS_NUM} more contacts", 'M'
- k.add :reload, "Reload contacts", 'R'
+ k.add :reload, "Drop contact list and reload", 'D'
k.add :alias, "Edit alias for contact", 'a'
k.add :toggle_tagged, "Tag/untag current line", 't'
k.add :apply_to_tagged, "Apply next command to all tagged items", ';'
def initialize mode = :regular
@mode = mode
@tags = Tagger.new self
- @num = 0
+ @num = nil
+ @text = []
super()
end
def apply_to_tagged; @tags.apply_to_tagged; end
- def load; regen_text; end
def load_more num=LOAD_MORE_CONTACTS_NUM
@num += num
+ load
regen_text
BufferManager.flash "Added #{num} contacts."
end
def reload
@tags.drop_all_tags
+ @num = nil
load
end
end
end
+ def load_in_background
+ Redwood::reporting_thread do
+ load
+ regen_text
+ BufferManager.draw_screen
+ end
+ end
+
+ def load
+ @num ||= buffer.content_height
+ @user_contacts = ContactManager.contacts.invert
+ num = [@num - @user_contacts.length, 0].max
+ BufferManager.say("Loading #{num} contacts from index...") do
+ recentc = Index.load_contacts AccountManager.user_emails, :num => num
+ @contacts = (@user_contacts.keys + recentc).sort_by { |p| p.sort_by_me }.uniq
+ end
+ end
+
protected
def update_text_for_line line
end
def regen_text
- @user_contacts = ContactManager.contacts.invert
- recent = Index.load_contacts AccountManager.user_emails, :num => [@num - @user_contacts.length, 0].max
-
- @contacts = (@user_contacts.keys + recent.select { |p| !@user_contacts[p] }).sort_by { |p| p.sort_by_me + (p.name || "") + p.email }.remove_successive_dupes
-
@awidth, @nwidth = 0, 0
@contacts.each do |p|
aalias = @user_contacts[p]
end
@text = @contacts.map { |p| text_for_contact p }
- buffer.mark_dirty if buffer
+ buffer.mark_dirty
end
end
def lines; @text.length; end
def [] i; @text[i]; end
- def load; regen_text; end
-
def load_in_background
Redwood::reporting_thread do
- regen_text do |i|
- if i % 10 == 0
- buffer.mark_dirty
- BufferManager.draw_screen
- sleep 0.1 # ok, dirty trick.
- end
- end
- buffer.mark_dirty
+ BufferManager.say("Counting labels...") { regen_text }
BufferManager.draw_screen
end
end
def regen_text
@text = []
- @labels = LabelManager::LISTABLE_LABELS.sort_by { |t| t.to_s } +
- LabelManager.user_labels.sort_by { |t| t.to_s }
+ @labels = (LabelManager::LISTABLE_LABELS + LabelManager.user_labels).sort_by { |t| t.to_s }
counts = @labels.map do |t|
total = Index.num_results_for :label => t
sprintf("%#{width + 1}s %5d %s, %5d unread", label, total, total == 1 ? " message" : "messages", unread)]]
yield i if block_given?
end.compact
+
+ buffer.mark_dirty
end
def view_results