class Alexandria::UndoManager

Attributes

actions[R]

Public Class Methods

new() click to toggle source
# File lib/alexandria/undo_manager.rb, line 27
def initialize
  @undo_actions = []
  @redo_actions = []
  @within_undo = @withing_redo = false
end

Public Instance Methods

can_redo?() click to toggle source
# File lib/alexandria/undo_manager.rb, line 42
def can_redo?
  !@redo_actions.empty?
end
can_undo?() click to toggle source
# File lib/alexandria/undo_manager.rb, line 38
def can_undo?
  !@undo_actions.empty?
end
push(&block) click to toggle source
# File lib/alexandria/undo_manager.rb, line 33
def push(&block)
  (@within_undo ? @redo_actions : @undo_actions) << block
  notify
end
redo!() click to toggle source
# File lib/alexandria/undo_manager.rb, line 55
def redo!
  @within_redo = true
  begin
    action(@redo_actions)
  ensure
    @within_redo = false
  end
end
undo!() click to toggle source
# File lib/alexandria/undo_manager.rb, line 46
def undo!
  @within_undo = true
  begin
    action(@undo_actions)
  ensure
    @within_undo = false
  end
end

Private Instance Methods

action(array) click to toggle source
# File lib/alexandria/undo_manager.rb, line 66
def action(array)
  action = array.pop
  raise if action.nil?

  action.call
  notify
end
notify() click to toggle source
# File lib/alexandria/undo_manager.rb, line 74
def notify
  changed
  notify_observers(self)
end