]> git.notmuchmail.org Git - sup/commitdiff
Added undo for starring
authorMike Stipicevic <stipim@rpi.edu>
Mon, 16 Feb 2009 05:03:57 +0000 (00:03 -0500)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 16 Mar 2009 12:00:00 +0000 (08:00 -0400)
lib/sup/modes/thread-index-mode.rb

index 120acadb180c0d47bd677e658096b613aac6c780..62fdb85dc4bc62a677e83b6c8dec00c8ab4c2b07 100644 (file)
@@ -237,24 +237,41 @@ EOS
   end
 
   def actually_toggle_starred t
+    thread = t # cargo cult programming
+    pos = curpos
     if t.has_label? :starred # if ANY message has a star
+      undo = lambda {
+        thread.first.add_label :starred
+        update_text_for_line pos
+        UpdateManager.relay self, :starred, thread.first
+      }
       t.remove_label :starred # remove from all
       UpdateManager.relay self, :unstarred, t.first
     else
+      undo = lambda {
+        thread.remove_label :starred
+        update_text_for_line pos
+        UpdateManager.relay self, :unstarred, thread.first
+      }
       t.first.add_label :starred # add only to first
       UpdateManager.relay self, :starred, t.first
     end
+
+    return undo
   end  
 
   def toggle_starred 
     t = cursor_thread or return
-    actually_toggle_starred t
+    undo = actually_toggle_starred t
+    UndoManager.register("starring/unstarring thread #{t.first.id}",undo)
     update_text_for_line curpos
     cursor_down
   end
 
   def multi_toggle_starred threads
-    threads.each { |t| actually_toggle_starred t }
+    undo = threads.map { |t| actually_toggle_starred t }
+    UndoManager.register("starring/unstarring #{threads.size} #{threads.size.pluralize 'thread'}",
+                         undo)
     regen_text
   end