Class: Alexandria::UndoManager

Inherits:
Object
  • Object
show all
Includes:
Observable, Singleton
Defined in:
lib/alexandria/undo_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUndoManager

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

#actionsObject (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

Returns:

  • (Boolean)


42
43
44
# File 'lib/alexandria/undo_manager.rb', line 42

def can_redo?
  !@redo_actions.empty?
end

#can_undo?Boolean

Returns:

  • (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