Skip to main content

CompositeCommand

Struct CompositeCommand 

Source
pub struct CompositeCommand {
    pub stack_id: u64,
    /* private fields */
}
Expand description

A composite command that groups multiple commands as one.

This allows treating a sequence of commands as a single unit for undo/redo operations. When a composite command is undone or redone, all its contained commands are undone or redone in the appropriate order.

§Example

use common::undo_redo::CompositeCommand;
let mut composite = CompositeCommand::new();
composite.add_command(Box::new(Command1::new()));
composite.add_command(Box::new(Command2::new()));
// Now composite can be treated as a single command

Fields§

§stack_id: u64

Implementations§

Source§

impl CompositeCommand

Source

pub fn new(stack_id: Option<u64>) -> Self

Creates a new empty composite command.

Source

pub fn labeled(stack_id: Option<u64>, label: Option<UndoLabel>) -> Self

A composite that names itself.

A group’s constituent labels are the wrong answer for a menu — a three-entity capture would read “Undo update” after the least interesting of its parts. The caller who opened the group is the only one who knows what the group was, so it says so here.

Source

pub fn add_command(&mut self, command: Box<dyn UndoRedoCommand>)

Adds a command to this composite.

Commands are executed, undone, and redone in the order they are added.

Source

pub fn is_empty(&self) -> bool

Returns true if this composite contains no commands.

Source

pub fn set_label(&mut self, label: Option<UndoLabel>)

Name this group after the fact — for a caller that only learns what the group was once its parts have run.

Trait Implementations§

Source§

impl Debug for CompositeCommand

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl UndoRedoCommand for CompositeCommand

Source§

fn label(&self) -> Option<UndoLabel>

The group’s own name, never a constituent’s — see CompositeCommand::labeled.

Source§

fn undo(&mut self) -> Result<()>

Undoes the command, reverting its effects
Source§

fn redo(&mut self) -> Result<()>

Redoes the command, reapplying its effects
Source§

fn as_any(&self) -> &dyn Any

Returns the type ID of this command for type checking. Read more
Source§

fn can_merge(&self, _other: &dyn UndoRedoCommand) -> bool

Returns true if this command can be merged with the other command. Read more
Source§

fn merge(&mut self, _other: &dyn UndoRedoCommand) -> bool

Merges this command with the other command. Returns true if the merge was successful. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.