struct CommandContext {
command_list: Vec<Box<dyn ICommand>>,
}
Expand description
This struct creates a context around the undo list that the command_exercise() executes within. This gets around the problem of needing a static undo list (or passing the undo list to all functions) as all the methods on this context have ready access to the undo list in the context.
Fields§
§command_list: Vec<Box<dyn ICommand>>
The list of command objects that describe the changes made to the text object.
Implementations§
source§impl CommandContext
impl CommandContext
sourcefn new() -> CommandContext
fn new() -> CommandContext
Constructor.
sourcefn execute_and_save(
&mut self,
command: Box<dyn ICommand>,
text: &mut CommandTextObject
)
fn execute_and_save( &mut self, command: Box<dyn ICommand>, text: &mut CommandTextObject )
Execute the given command on the given text object then save the command on the given undo list.
Parameters
-
command_list
The list that holds the commands for later undoing.
-
command
The command to apply to the text.
-
text
The CommandTextObject to affect.
sourcefn apply_replace_command(
&mut self,
text: &mut CommandTextObject,
search_pattern: &str,
replace_text: &str
)
fn apply_replace_command( &mut self, text: &mut CommandTextObject, search_pattern: &str, replace_text: &str )
Helper method to create a Command object that replaces text in the given CommandTextObject, applies the command to the CommandTextObject, and then adds the command to the given undo list. Finally, it shows off what was done.
Parameters
-
command_list
The list that holds the commands for later undoing.
-
text
The CommandTextObject to affect.
-
search_pattern
What to look for in the CommandTextObject.
-
replace_text
What to replace
search_pattern
with.
sourcefn apply_reverse_command(&mut self, text: &mut CommandTextObject)
fn apply_reverse_command(&mut self, text: &mut CommandTextObject)
Helper method to create a Command object that reverses the order of the characters in the given CommandTextObject, applies the command to the CommandTextObject, and then adds the command to the given undo list. Finally, it shows what was done.
Parameters
-
command_list
The list that holds the commands for later undoing.
-
text
The CommandTextObject to affect.
sourcefn undo(&mut self, text: &mut CommandTextObject)
fn undo(&mut self, text: &mut CommandTextObject)
Perform an undo on the given CommandTextObject, using the commands in the given undo list. If the undo list is empty, nothing happens.
Parameters
-
command_list
The list that holds the commands for later undoing.
-
text
The CommandTextObject to affect.