commit cb521812b954e97b1fe62a113d8447de8fd5417b
parent f28defc75f7ae2332c7355171713a5195b8170d8
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date: Thu, 11 Jan 2007 19:52:28 +0000
fixed label and contact-list modes to be a little better
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@243 5c8cc53c-5e98-4d25-b20a-d8db53a31250
Diffstat:
4 files changed, 29 insertions(+), 36 deletions(-)
diff --git a/bin/sup b/bin/sup
@@ -130,7 +130,7 @@ begin
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*$/
@@ -145,7 +145,6 @@ begin
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
diff --git a/lib/sup/modes/contact-list-mode.rb b/lib/sup/modes/contact-list-mode.rb
@@ -5,7 +5,7 @@ class ContactListMode < LineCursorMode
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", ';'
@@ -15,7 +15,8 @@ class ContactListMode < LineCursorMode
def initialize mode = :regular
@mode = mode
@tags = Tagger.new self
- @num = 0
+ @num = nil
+ @text = []
super()
end
@@ -36,9 +37,9 @@ class ContactListMode < LineCursorMode
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
@@ -70,6 +71,7 @@ class ContactListMode < LineCursorMode
def reload
@tags.drop_all_tags
+ @num = nil
load
end
@@ -85,6 +87,24 @@ class ContactListMode < LineCursorMode
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
@@ -99,11 +119,6 @@ protected
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]
@@ -112,7 +127,7 @@ protected
end
@text = @contacts.map { |p| text_for_contact p }
- buffer.mark_dirty if buffer
+ buffer.mark_dirty
end
end
diff --git a/lib/sup/modes/label-list-mode.rb b/lib/sup/modes/label-list-mode.rb
@@ -15,18 +15,9 @@ class LabelListMode < LineCursorMode
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
@@ -41,8 +32,7 @@ protected
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
@@ -71,6 +61,8 @@ protected
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
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -176,19 +176,6 @@ class Array
def rest; self[1..-1]; end
def to_boolean_h; Hash[*map { |x| [x, true] }.flatten]; end
-
- ## apparently uniq doesn't use ==. wtf.
- def remove_successive_dupes
- ret = []
- last = nil
- each do |e|
- unless e == last
- ret << e
- last = e
- end
- end
- ret
- end
end
class Time