Class: Alexandria::UndoManager
- Inherits:
-
Object
- Object
- Alexandria::UndoManager
- Includes:
- Observable, Singleton
- Defined in:
- lib/alexandria/undo_manager.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
Instance Method Summary collapse
- #can_redo? ⇒ Boolean
- #can_undo? ⇒ Boolean
-
#initialize ⇒ UndoManager
constructor
A new instance of UndoManager.
- #push(&block) ⇒ Object
- #redo! ⇒ Object
- #undo! ⇒ Object
Constructor Details
#initialize ⇒ UndoManager
Returns a new instance of UndoManager.
27 28 29 30 31 |
# File 'lib/alexandria/undo_manager.rb', line 27 def initialize @undo_actions = [] @redo_actions = [] @within_undo = @withing_redo = false end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
25 26 27 |
# File 'lib/alexandria/undo_manager.rb', line 25 def actions @actions end |
Instance Method Details
#can_redo? ⇒ Boolean
42 43 44 |
# File 'lib/alexandria/undo_manager.rb', line 42 def can_redo? !@redo_actions.empty? end |
#can_undo? ⇒ Boolean
38 39 40 |
# File 'lib/alexandria/undo_manager.rb', line 38 def can_undo? !@undo_actions.empty? end |
#push(&block) ⇒ Object
33 34 35 36 |
# File 'lib/alexandria/undo_manager.rb', line 33 def push(&block) (@within_undo ? @redo_actions : @undo_actions) << block notify end |
#redo! ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/alexandria/undo_manager.rb', line 55 def redo! @within_redo = true begin action(@redo_actions) ensure @within_redo = false end end |
#undo! ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/alexandria/undo_manager.rb', line 46 def undo! @within_undo = true begin action(@undo_actions) ensure @within_undo = false end end |