Class: Redwood::UndoManager
- Includes:
- Singleton
- Defined in:
- lib/sup/undo.rb
Overview
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
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ UndoManager
constructor
A new instance of UndoManager.
- #register(desc, *actions, &b) ⇒ Object
- #undo ⇒ Object
Methods included from Singleton
Constructor Details
#initialize ⇒ UndoManager
Returns a new instance of UndoManager.
13 14 15 |
# File 'lib/sup/undo.rb', line 13 def initialize @@actionlist = [] end |
Instance Method Details
#clear ⇒ Object
34 35 36 |
# File 'lib/sup/undo.rb', line 34 def clear @@actionlist = [] end |
#register(desc, *actions, &b) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/sup/undo.rb', line 17 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 |
#undo ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/sup/undo.rb', line 24 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 |