6from .command_classes
import Command_TextObject, Command
20 _commandUndoList.append(command)
35 source.Text = source.Text.replace(searchPattern, replaceText)
45 text_in_list = [c
for c
in source.Text]
46 text_in_list.reverse()
47 output =
"".join(text_in_list)
64 lastCommand = _commandUndoList.pop(len(_commandUndoList) - 1)
68 for command
in _commandUndoList:
72 print(
" undoing command {0:<31}==> \"{1}\"".format(lastCommand.ToString(), text.ToString()))
90 command =
Command(text,
"Replace", Command_Operation_Replace, searchPattern, replaceText)
92 print(
" command {0:<31}==> \"{1}\"".format(command.ToString(), text.ToString()))
106 command =
Command(text,
"Reverse", Command_Operation_Reverse)
108 print(
" command {0:<31}==> \"{1}\"".format(command.ToString(), text.ToString()))
125 print(
"Command Exercise")
130 print(
" Starting text: \"{0}\"".format(text.ToString()))
138 print(
" Now perform undo until back to original")
146 print(
" Final text : \"{0}\"".format(text.ToString()))
Represents an operation that can be applied to a TextObject.
None Command_Operation_Replace(Command_TextObject source, str searchPattern, str replaceText)
An operation to search and replace text in a Command_TextObject.
def Command_Operation_Reverse(Command_TextObject source)
An operation to reverse the characters in the given Command_TextObject.
def Command_Exercise()
Example of using the Command Pattern.
None Command_ApplyReverseCommand(Command_TextObject text)
Helper function to create a Command object that reverses the order of the characters in the given Com...
None Command_Undo(Command_TextObject text)
Perform an undo on the given Command_TextObject, using the commands in the "global" undo list.
None Command_ApplyReplaceCommand(Command_TextObject text, str searchPattern, str replaceText)
Helper function to create a Command object that replaces text in the given Command_TextObject,...
def Command_Save_And_Execute(Command_TextObject text, Command command)
Save the given command on the undo list then execute the command on the given text object.