Interaction Techniques and Technologies (ITT), SS 2017
Session 20 (18.07.2017), Raphael Wimmer
These are slides/notes for the lecture, automatically generated from the slide set. Please extend this outline with your own notes.
Questions:
First documented use: Bravo text editor (Xerox Alto), 1974 (user manual)
^Z
was selected „by programmers at the research center Xerox PARC“<small>(source: Brad Myers' slide set)</small>
<small>(source: Brad Myers)</small>
u
and Ctrl-R
, move chronologically through all branches via g-
and g+
)undofile
<small>(source: Brad Myers)</small>
<small>(source: Brad Myers)</small>
originator
object has some internal statememento
object that represents its internal statecaretaker
object applies an undo-able action to the originator
by asking for a memento
object of the current state and only then applying the actionmemento
object is given to the originator
* see also: (Wikipedia article)
do()
and undo()
methodsdo()
is called, to revert it, undo()
is calleddiff
and patch
utilities for code developmentundo()
- undoes the actionredo()
- executes / redoes the actionpush(command)
- adds to stack and calls command.redo()
undo()
- pops last command from stack and calls command.undo()
~~~~ undo.py #!/usr/bin/env python3 from PyQt5.QtWidgets import QUndoCommand, QUndoStack, QUndoGroup class SimpleDocument(object): def __init__(self, text=None): if text is None: self.text = "" else: self.text = text class InsertCharacter(QUndoCommand): def __init__(self, document, position, character): super().__init__() self.document = document self.character = character self.position = position self.setText("insert a character") def undo(self): self.document.text = self.document.text[:self.position] \ + self.document.text[self.position+1:] def redo(self): self.document.text = self.document.text[:self.position] \ + self.character \ + self.document.text[self.position:] ~~~~
~~~~ undo.py if __name__ == "__main__": stack = QUndoStack() d = SimpleDocument("123456") stack.push(InsertCharacter(d, 1, "a")) # "1a23456" stack.push(InsertCharacter(d, 3, "b")) # "1a2b3456" stack.undo() stack.undo() # "123456" ~~~~