Sha256: bd9169522f1e364c9d00ad0bb174035c7fc4c382aac77bfb312cd6f0722d502d
Contents?: true
Size: 930 Bytes
Versions: 2
Compression:
Stored size: 930 Bytes
Contents
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, &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.empty? actionset = @@actionlist.pop 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
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sup-0.8.1 | lib/sup/undo.rb |
sup-0.8 | lib/sup/undo.rb |