Struct undo::UndoStack
[−]
[src]
pub struct UndoStack<'a> { /* fields omitted */ }
UndoStack
maintains a stack of UndoCmd
s that can be undone and redone by using methods
on the UndoStack
.
UndoStack
will notice when it's state changes to either dirty or clean, and the user can
set methods that should be called for either state change. This is useful for example if
you want to automatically enable or disable undo or redo buttons based on there are any
more actions that can be undone or redone.
Methods
impl<'a> UndoStack<'a>
[src]
fn new() -> Self
Creates a new UndoStack
.
fn with_capacity(capacity: usize) -> Self
Creates a new UndoStack
with the specified capacity.
fn capacity(&self) -> usize
Returns the capacity of the UndoStack
.
fn shrink_to_fit(&mut self)
Shrinks the capacity of the UndoStack
as much as possible.
fn on_clean<F>(self, f: F) -> Self where F: FnMut() + 'a
Sets what should happen if the state changes from dirty to clean.
By default the UndoStack
does nothing when the state changes.
Consumes the UndoStack
so this method should be called when creating the UndoStack
.
Note: An empty UndoStack
is clean, so the first push will not trigger the on_clean
method.
Example
let mut x = 0; let stack = UndoStack::new() .on_clean(|| x += 1);
fn on_dirty<F>(self, f: F) -> Self where F: FnMut() + 'a
Sets what should happen if the state changes from clean to dirty.
By default the UndoStack
does nothing when the state changes.
Consumes the UndoStack
so this method should be called when creating the UndoStack
.
Example
let mut x = 0; let stack = UndoStack::new() .on_dirty(|| x += 1);
fn is_clean(&self) -> bool
Returns true
if the state of the stack is clean.
fn is_dirty(&self) -> bool
Returns true
if the state of the stack is dirty.
fn push<T>(&mut self, cmd: T) where T: UndoCmd + 'a
Pushes a UndoCmd
to the top of the UndoStack
and executes its redo
method.
This pops off all UndoCmd
s that is above the active command from the UndoStack
.
If cmd
s id is equal to the current top command, the two commands are merged.
fn redo(&mut self)
Calls the redo
method for the active UndoCmd
and sets the next UndoCmd
as the new
active one.
Calling this method when the state is clean does nothing.
fn undo(&mut self)
Calls the undo
method for the active UndoCmd
and sets the previous UndoCmd
as the
new active one.
Calling this method when there are no more commands to undo does nothing.