]> git.cworth.org Git - sup/commitdiff
fixed label and contact-list modes to be a little better
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Thu, 11 Jan 2007 19:52:28 +0000 (19:52 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Thu, 11 Jan 2007 19:52:28 +0000 (19:52 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@243 5c8cc53c-5e98-4d25-b20a-d8db53a31250

bin/sup
lib/sup/modes/contact-list-mode.rb
lib/sup/modes/label-list-mode.rb
lib/sup/util.rb

diff --git a/bin/sup b/bin/sup
index 8c785e477584ad1f62202d7dfdb7c8e09e0f7559..a83abe6871f5fac563589bf8826efd1ccdc4ed74 100644 (file)
--- 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
index e5c3c5ec2a936f1732628deaa03767a6ea1898d0..6b7d0c48330e599e3771a0224d98b842af561650 100644 (file)
@@ -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
 
index 18ce9aa8d1c5cb412218b1b4c6fadae4a1d61295..5c1242fec81bf5436096009333f7597cbe4adffa 100644 (file)
@@ -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
index f3e0a2c3182062db7f9754940fe864d8a1832742..0e06ecd904d6eeed109f15bd0dc64ebf733c5626 100644 (file)
@@ -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