Trait undo::Command
[−]
[src]
pub trait Command<T> { fn redo(&mut self, receiver: &mut T) -> Result<(), Box<Error>>; fn undo(&mut self, receiver: &mut T) -> Result<(), Box<Error>>; fn id(&self) -> Option<u64> { ... } }
Base functionality for all commands.
Required Methods
fn redo(&mut self, receiver: &mut T) -> Result<(), Box<Error>>
Executes the desired command and returns Ok
if everything went fine, and Err
if
something went wrong.
fn undo(&mut self, receiver: &mut T) -> Result<(), Box<Error>>
Restores the state as it was before redo
was called and returns Ok
if everything
went fine, and Err
if something went wrong.
Provided Methods
fn id(&self) -> Option<u64>
Used for merging of UndoCmd
s.
Two commands are merged together when a command is pushed on the UndoStack
, and it has
the same id as the top command already on the stack. When commands are merged together,
undoing and redoing them are done in one step. An example where this is useful is a text
editor where you might want to undo a whole word instead of each character.
Default implementation returns None
, which means the command will never be merged.