Subject: [sup-talk] (no subject)

From: [email-masked] (Michael John Stipicevic)
Date: Mon, 16 Feb 2009 01:45:13 -0500

>From d1b5ff3d022e0e6aeabf410b0778fd11a5449ed0 Mon Sep 17 00:00:00 2001
From: Mike Stipicevic <stipim at rpi.edu>
Date: Mon, 16 Feb 2009 00:08:03 -0500
Subject: [PATCH] Added undo for thread deletion

---
 lib/sup/modes/thread-index-mode.rb |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index 1e02b5b..ae7c299 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -326,12 +326,26 @@ EOS
 
   def actually_toggle_deleted t
     if t.has_label? :deleted
+      undo = lambda {
+        t.apply_label :deleted
+        hide_thread t
+        UpdateManager.relay self, :deleted, t.first
+      }
       t.remove_label :deleted
+      add_or_unhide t.first
       UpdateManager.relay self, :undeleted, t.first
     else
+      undo = lambda {
+        t.remove_label :deleted
+        add_or_unhide t.first
+        UpdateManager.relay self, :undeleted, t.first
+      }
       t.apply_label :deleted
+  hide_thread t
       UpdateManager.relay self, :deleted, t.first
     end
+
+    return undo
   end
 
   def toggle_archived 
@@ -418,10 +432,9 @@ EOS
 
   ## see comment for multi_toggle_spam
   def multi_toggle_deleted threads
-    threads.each do |t|
-      actually_toggle_deleted t
-      hide_thread t 
-    end
+    undo = threads.map{ |t| actually_toggle_deleted t}
+    UndoManager.register("deleting/undeleting #{threads.size} #{threads.size.pluralize 'thread'}",
+                         undo << lambda {regen_text})
     regen_text
   end
 
-- 
1.5.3