Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
From: stipim@rpi.edu (Michael John Stipicevic)
Subject: [sup-talk] (no subject)
Date: Mon, 16 Feb 2009 01:45:00 -0500	[thread overview]
Message-ID: <200902160645.n1G6j0j7003164@rmtacc26-la.rcs.rpi.edu> (raw)

From 61a256d09ec8091e5ab44cc4e0e5c9c24c81a4cf Mon Sep 17 00:00:00 2001
From: Mike Stipicevic <stipim at rpi.edu>
Date: Mon, 16 Feb 2009 00:40:39 -0500
Subject: [PATCH] Added undo for archive

---
 lib/sup/modes/inbox-mode.rb        |   35 +++++++++++++++++++++++++++++++++++
 lib/sup/modes/thread-index-mode.rb |   21 +++++++++++++++++++--
 2 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/lib/sup/modes/inbox-mode.rb b/lib/sup/modes/inbox-mode.rb
index 559892d..21eb9ac 100644
--- a/lib/sup/modes/inbox-mode.rb
+++ b/lib/sup/modes/inbox-mode.rb
@@ -26,12 +26,28 @@ class InboxMode < ThreadIndexMode
 
   def archive
     return unless cursor_thread
+    thread = cursor_thread # to make sure lambda only knows about 'old' cursor_thread
+
+    undo = lambda {
+      thread.apply_label :inbox
+      add_or_unhide thread.first
+    }
+    UndoManager.register("archiving thread #{thread.first.id}", undo)
+
     cursor_thread.remove_label :inbox
     hide_thread cursor_thread
     regen_text
   end
 
   def multi_archive threads
+    undo = threads.map {|t|
+             lambda{
+               t.apply_label :inbox
+               add_or_unhide t.first
+             }}
+    UndoManager.register("archiving #{threads.size} #{threads.size.pluralize 'thread'}",
+                         undo << lambda {regen_text} )
+
     threads.each do |t|
       t.remove_label :inbox
       hide_thread t
@@ -41,6 +57,15 @@ class InboxMode < ThreadIndexMode
 
   def read_and_archive
     return unless cursor_thread
+    thread = cursor_thread # to make sure lambda only knows about 'old' cursor_thread
+
+    undo = lambda {
+      thread.apply_label :inbox
+      thread.apply_label :unread
+      add_or_unhide thread.first
+    }
+    UndoManager.register("reading and archiving thread ", undo)
+
     cursor_thread.remove_label :unread
     cursor_thread.remove_label :inbox
     hide_thread cursor_thread
@@ -48,6 +73,16 @@ class InboxMode < ThreadIndexMode
   end
 
   def multi_read_and_archive threads
+    undo = threads.map {|t|
+      lambda {
+        t.apply_label :inbox
+        t.apply_label :unread
+        add_or_unhide t.first
+      }
+    }
+    UndoManager.register("reading and archiving #{threads.size} #{threads.size.pluralize 'thread'}",
+                         undo << lambda {regen_text})
+
     threads.each do |t|
       t.remove_label :unread
       t.remove_label :inbox
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index ee30284..120acad 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -259,13 +259,27 @@ EOS
   end
 
   def actually_toggle_archived t
+    thread = t
+    pos = curpos
     if t.has_label? :inbox
       t.remove_label :inbox
+      undo = lambda {
+        thread.apply_label :inbox
+        update_text_for_line pos
+        UpdateManager.relay self,:unarchived, thread.first
+      }
       UpdateManager.relay self, :archived, t.first
     else
       t.apply_label :inbox
+      undo = lambda {
+        thread.remove_label :inbox
+        update_text_for_line pos
+        UpdateManager.relay self, :unarchived, thread.first
+      }
       UpdateManager.relay self, :unarchived, t.first
     end
+
+    return undo
   end
 
   def actually_toggle_spammed t
@@ -290,12 +304,15 @@ EOS
 
   def toggle_archived 
     t = cursor_thread or return
-    actually_toggle_archived t
+    undo = [actually_toggle_archived(t), lambda {self.update_text_for_line curpos}]
+    UndoManager.register("deleting/undeleting thread #{t.first.id}",undo)
     update_text_for_line curpos
   end
 
   def multi_toggle_archived threads
-    threads.each { |t| actually_toggle_archived t }
+    undo = threads.map { |t| actually_toggle_archived t}
+    UndoManager.register("deleting/undeleting #{threads.size} #{threads.size.pluralize 'thread'}",
+                         undo << lambda {self.regen_text})
     regen_text
   end
 
-- 
1.5.3



             reply	other threads:[~2009-02-16  6:45 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-16  6:45 Michael John Stipicevic [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-12-10  3:08 Jason O'Conal
2010-11-15  0:49 Matthias Vallentin
2010-11-15  1:42 ` Edward Z. Yang
2010-11-15  6:57   ` Matthias Vallentin
2010-11-15  8:06     ` Helge Titlestad
2010-11-20 19:04       ` Matthias Vallentin
2010-11-21  1:10         ` Tero Tilus
2010-11-21  1:51           ` Matthias Vallentin
2010-11-15  1:46 ` Ben Walton
2010-11-15  1:50 ` Matias Aguirre
2009-06-08  0:02 Ben Walton
2009-06-11 23:50 ` Ben Walton
2009-06-12  3:44   ` William Morgan
2009-06-12 13:15     ` Ben Walton
2009-06-12 18:23 ` William Morgan
2009-06-01  1:01 Ben Walton
2009-06-01  1:04 ` Ben Walton
2009-06-01  2:13 ` Ben Walton
2009-06-04  2:04 ` Ross Macduff
2009-02-16  6:45 Michael John Stipicevic
2009-02-16  6:45 Michael John Stipicevic
2009-02-16  6:45 Michael John Stipicevic
2009-02-16  6:45 Michael John Stipicevic
2009-02-16  6:45 Michael John Stipicevic
2009-02-16  6:45 Michael John Stipicevic
2009-02-16  6:44 Michael John Stipicevic
2009-02-16  6:27 Michael John Stipicevic
2009-02-16  6:25 Michael John Stipicevic
2009-02-16  6:25 Michael John Stipicevic
2009-02-16  6:25 Michael John Stipicevic
2009-02-16  6:25 Michael John Stipicevic
2009-02-16  6:25 Michael John Stipicevic
2009-02-16  6:25 Michael John Stipicevic
2009-02-16  8:53 ` Ian Smith
2009-02-16 14:08   ` William Morgan
2009-02-16 14:42     ` Mike Stipicevic
2009-02-16  6:25 Michael John Stipicevic
2009-02-16  6:25 Michael John Stipicevic
2008-01-05 19:29 thefed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200902160645.n1G6j0j7003164@rmtacc26-la.rcs.rpi.edu \
    --to=stipim@rpi.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox