pub struct UndoBuffer { /* private fields */ }Expand description
Two-stack undo/redo history buffer.
Mirrors the C# UndoBuffer class: when a new action is added the redo
stack is cleared (so a new branch cannot be redone). The undo stack is
size-limited; the oldest entries are dropped when the limit is exceeded.
Implementations§
Source§impl UndoBuffer
impl UndoBuffer
Sourcepub fn with_max_undos(self, n: usize) -> Self
pub fn with_max_undos(self, n: usize) -> Self
Set the maximum number of undo steps retained.
Sourcepub fn add(&mut self, cmd: Box<dyn UndoRedoCommand>)
pub fn add(&mut self, cmd: Box<dyn UndoRedoCommand>)
Push cmd without executing it.
Use this when the action has already been applied to the state; the command only needs to know how to undo (and redo) it. Clears the redo stack.
Sourcepub fn add_and_do(&mut self, cmd: Box<dyn UndoRedoCommand>)
pub fn add_and_do(&mut self, cmd: Box<dyn UndoRedoCommand>)
Execute cmd.do_it() and push it onto the undo stack.
Use this when the action has not yet been applied.
Sourcepub fn redo(&mut self)
pub fn redo(&mut self)
Redo the most recently undone operation. No-op if the redo stack is empty.
Sourcepub fn can_undo(&self) -> bool
pub fn can_undo(&self) -> bool
Returns true if there is at least one operation that can be undone.
Sourcepub fn can_redo(&self) -> bool
pub fn can_redo(&self) -> bool
Returns true if there is at least one operation that can be redone.
Sourcepub fn undo_name(&self) -> Option<&str>
pub fn undo_name(&self) -> Option<&str>
Name of the operation that undo() would reverse, if any.
Sourcepub fn redo_name(&self) -> Option<&str>
pub fn redo_name(&self) -> Option<&str>
Name of the operation that redo() would re-apply, if any.
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Discard all undo and redo history.