]> git.cworth.org Git - sup/blobdiff - lib/sup/undo.rb
Merge branch 'hook-local-vars' into next
[sup] / lib / sup / undo.rb
index 250433d46bf8b4a070f71f69ad1717fac3287923..9ccf84a01724af3d7f7a2077e9f774f85d9579a8 100644 (file)
@@ -12,26 +12,22 @@ class UndoManager
 
   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})
+  def register desc, *actions, &b
+    actions = [*actions.flatten]
+    actions << b if b
+    raise ArgumentError, "need at least one action" unless actions.length > 0
+    @@actionlist.push :desc => desc, :actions => actions
   end
 
   def undo
-    unless @@actionlist.length == 0 then
+    unless @@actionlist.empty?
       actionset = @@actionlist.pop
-      Redwood::log "undoing #{actionset[:desc]}..."
-      actionset[:actions].each{|action|
-        action.call
-      }
+      actionset[:actions].each { |action| action.call }
       BufferManager.flash "undid #{actionset[:desc]}"
     else
-      BufferManager.flash "nothing more to undo"
+      BufferManager.flash "nothing more to undo!"
     end
   end