| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 557677b commit 8469373
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,19 +19,17 @@ def undo(self): | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | 21 | if __name__ == "__main__": | |
| 22 | - undo_stack = [] | ||
| 23 | - ren1 = MoveFileCommand('foo.txt', 'bar.txt') | ||
| 24 | - ren2 = MoveFileCommand('bar.txt', 'baz.txt') | ||
| 22 | + command_stack = [] | ||
| 25 | 23 | ||
| 26 | 24 | # commands are just pushed into the command stack | |
| 27 | - for cmd in ren1, ren2: | ||
| 28 | - undo_stack.append(cmd) | ||
| 25 | + command_stack.append(MoveFileCommand('foo.txt', 'bar.txt')) | ||
| 26 | + command_stack.append(MoveFileCommand('bar.txt', 'baz.txt')) | ||
| 29 | 27 | ||
| 30 | - # they can be executed later on will | ||
| 31 | - for cmd in undo_stack: | ||
| 32 | - cmd.execute() # foo.txt is now renamed to baz.txt | ||
| 33 | 28 | ||
| 34 | - # and can also be undone on will | ||
| 35 | - for cmd in undo_stack: | ||
| 36 | - undo_stack.pop().undo() # Now it's bar.txt | ||
| 37 | - undo_stack.pop().undo() # and back to foo.txt | ||
| 29 | + # they can be executed later on | ||
| 30 | + for cmd in command_stack: | ||
| 31 | + cmd.execute() | ||
| 32 | + | ||
| 33 | + # and can also be undone at will | ||
| 34 | + for cmd in reversed(command_stack): | ||
| 35 | + cmd.undo() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments