From: stipim@rpi.edu (Michael John Stipicevic)
Subject: [sup-talk] (no subject)
Date: Mon, 16 Feb 2009 01:44:54 -0500 [thread overview]
Message-ID: <200902160644.n1G6isMF003158@rmtacc26-la.rcs.rpi.edu> (raw)
From 9b863d8c86226b3d148e56060092556e2b13a5df Mon Sep 17 00:00:00 2001
From: Mike Stipicevic <stipim at rpi.edu>
Date: Mon, 16 Feb 2009 00:39:50 -0500
Subject: [PATCH] Added UndoManager class
The UndoManager keeps a list of lambdas that undo actions. It's designed to be used by keypress hooks. It is initialized in the main sup thread along with UpdateManager, etc.
---
lib/sup.rb | 2 +
lib/sup/modes/thread-index-mode.rb | 6 +++++
lib/sup/undo.rb | 42 ++++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 0 deletions(-)
create mode 100644 lib/sup/undo.rb
diff --git a/lib/sup.rb b/lib/sup.rb
index 93369a5..eda673b 100644
--- a/lib/sup.rb
+++ b/lib/sup.rb
@@ -125,6 +125,7 @@ module Redwood
Redwood::PollManager.new
Redwood::SuicideManager.new Redwood::SUICIDE_FN
Redwood::CryptoManager.new
+ Redwood::UndoManager.new
end
def finish
@@ -281,6 +282,7 @@ require "sup/tagger"
require "sup/draft"
require "sup/poll"
require "sup/crypto"
+require "sup/undo"
require "sup/horizontal-selector"
require "sup/modes/line-cursor-mode"
require "sup/modes/help-mode"
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index 4de4613..ee30284 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -44,6 +44,7 @@ EOS
k.add :tag_matching, "Tag matching threads", 'g'
k.add :apply_to_tagged, "Apply next command to all tagged threads", ';'
k.add :join_threads, "Force tagged threads to be joined into the same thread", '#'
+ k.add :undo, "Undo the previous action", 'u'
end
def initialize hidden_labels=[], load_thread_opts={}
@@ -83,6 +84,7 @@ EOS
def reload
drop_all_threads
+ UndoManager.clear
BufferManager.draw_screen
load_threads :num => buffer.content_height
end
@@ -208,6 +210,10 @@ EOS
add_or_unhide m
end
+ def undo
+ UndoManager.undo
+ end
+
def update
@mutex.synchronize do
## let's see you do THIS in python
diff --git a/lib/sup/undo.rb b/lib/sup/undo.rb
new file mode 100644
index 0000000..250433d
--- /dev/null
+++ b/lib/sup/undo.rb
@@ -0,0 +1,42 @@
+module Redwood
+
+## Implements a single undo list for the Sup instance
+##
+## The basic idea is to keep a list of lambdas to undo
+## things. When an action is called (such as 'archive'),
+## a lambda is registered with UndoManager that will
+## undo the archival action
+
+class UndoManager
+ include Singleton
+
+ def initialize
+ @@actionlist = []
+ self.class.i_am_the_instance self
+ end
+
+ def register desc, actions
+ actions = [actions] unless actions.is_a?Array
+ raise StandardError, "when would I need to undo 'nothing?'" unless actions.length > 0
+ Redwood::log "registering #{actions.length} actions: #{desc}"
+ @@actionlist.push({:desc => desc, :actions => actions})
+ end
+
+ def undo
+ unless @@actionlist.length == 0 then
+ actionset = @@actionlist.pop
+ Redwood::log "undoing #{actionset[:desc]}..."
+ actionset[:actions].each{|action|
+ action.call
+ }
+ BufferManager.flash "undid #{actionset[:desc]}"
+ else
+ BufferManager.flash "nothing more to undo"
+ end
+ end
+
+ def clear
+ @@actionlist = []
+ end
+end
+end
--
1.5.3
next reply other threads:[~2009-02-16 6:44 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-16 6:44 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:45 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 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
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=200902160644.n1G6isMF003158@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