From 0e1a7157417f7ae60544cb6453e384919b1de27c Mon Sep 17 00:00:00 2001 From: William Morgan Date: Sun, 17 May 2009 13:18:25 -0700 Subject: [PATCH] make UndoManager#register take a block Also clean up logging messages, argument handling, etc. --- lib/sup/undo.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/sup/undo.rb b/lib/sup/undo.rb index 250433d..5a93c31 100644 --- a/lib/sup/undo.rb +++ b/lib/sup/undo.rb @@ -15,23 +15,20 @@ class UndoManager 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 -- 2.45.2