Skip to content

Instantly share code, notes, and snippets.

@Sean-Bradley
Last active April 12, 2019 12:34
Show Gist options
  • Save Sean-Bradley/9f354bbaf7623ed55e966890d1cc8409 to your computer and use it in GitHub Desktop.
Save Sean-Bradley/9f354bbaf7623ed55e966890d1cc8409 to your computer and use it in GitHub Desktop.
@property
def history(self):
"""Return all records in the History list"""
return self._history
def undo(self):
"""Undo a command if there is a command that can be undone.
Update the history psoition so that further UNDOs or REDOs
point to the correct index"""
if self._history_position > 0:
self._history_position -= 1
self._commands[
self._history[self._history_position][1]
].execute(self._history[self._history_position][2])
else:
print("nothing to undo")
def redo(self):
"""Perform a REDO if the history_position is less than the end of the history list"""
if self._history_position + 1 < len(self._history):
self._history_position += 1
self._commands[
self._history[self._history_position][1]
].execute(self._history[self._history_position][2])
else:
print("nothing to REDO")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment