9from .memento
import IMemento, Memento_TextObject
24 memento = text.GetMemento(operation)
25 _mementoUndoList.append(memento)
37 source.SetText = source.Text.replace(searchPattern, replaceText)
47 textLength = len(text)
48 for index
in range(0, textLength):
49 output.write(text[textLength - 1 - index])
50 source.SetText = output.getvalue()
60 lastMemento = _mementoUndoList.pop()
61 text.RestoreMemento(lastMemento)
64 print(
" undoing operation {0:<31}: \"{1}\"".format(lastMemento.Name, text.ToString()))
78 operationName =
"Replace '{0}' with '{1}'".format(searchPattern, replaceText)
81 print(
" operation {0:<31}: \"{1}\"".format(operationName, text.ToString()))
91 operationName =
"Reverse"
94 print(
" operation {0:<31}: \"{1}\"".format(operationName, text.ToString()))
123 print(
"Memento Exercise")
126 _mementoUndoList.clear()
131 print(
" Starting text: \"{0}\"".format(text.ToString()))
139 print(
" Now perform undo until back to original")
147 print(
" Final text : \"{0}\"".format(text.ToString()))
None Memento_Operation_Reverse(Memento_TextObject source)
An operation to reverse the characters in the given Memento_TextObject.
None Memento_Operation_Replace(Memento_TextObject source, str searchPattern, str replaceText)
An operation to search and replace text in a Memento_TextObject.
None Memento_Undo(Memento_TextObject text)
Perform an undo on the given Command_TextObject, using the mementos in the "global" undo list.
def Memento_Exercise()
Example of using the Memento Pattern.
None Memento_SaveForUndo(Memento_TextObject text, str operation)
Take a snapshot of the given text object associated with the name of given operation.
None Memento_ApplyReverseOperation(Memento_TextObject text)
Helper function to reverse the order of the characters in the given Memento_TextObject after adding a...
None Memento_ApplyReplaceOperation(Memento_TextObject text, str searchPattern, str replaceText)
Helper function to replace a pattern with another string in the given Memento_TextObject after adding...