Struct undo::UndoStack [] [src]

pub struct UndoStack<'a> { /* fields omitted */ }

UndoStack maintains a stack of UndoCmds 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]

Creates a new UndoStack.

Creates a new UndoStack with the specified capacity.

Returns the capacity of the UndoStack.

Shrinks the capacity of the UndoStack as much as possible.

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);

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);

Returns true if the state of the stack is clean.

Returns true if the state of the stack is dirty.

Pushes a UndoCmd to the top of the UndoStack and executes its redo method. This pops off all UndoCmds that is above the active command from the UndoStack.

If cmds id is equal to the current top command, the two commands are merged.

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.

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.