Skip to content

Commit

Permalink
Update A0143637A.md
Browse files Browse the repository at this point in the history
add dev guide code
  • Loading branch information
Sherry committed Nov 7, 2016
1 parent 4e9a2cc commit 750f021
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions collated/docs/A0143637A.md
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,7 @@
Auto Complete | TAB
setdatadir |`setdatadir FILE_PATH`
Exit | `exit`

###### docs/DeveloperGuide.md
#### Undo/Redo implementation
The `Commit` class nested in `ModelManager` holds the name (a String) of a `Command` and also a copy of a `WorkingTaskBook`. `ModelManager` has a list of commits. There is a head label which always point to the `Commit` containing the curent `WorkingTaskBook`. Right after `LogicManager` executes a `Command` and updates the `TaskBook` with the relevant changes, model.hasUncommittedChanges() is called to check if the `Command` recently called caused a change in `TaskBook`. If yes, a new `Commit` is created to store the current state of the `WorkingTaskBook` and the name of the recently executed `Command`. This `Commit` is then added to the list of commits. Head label is updated accordingly. When undo is executed, the head label shifts down the list to point to the previous `Commit`. The `WorkingTaskBook` of that `Commit` is then loaded as the current `WorkingTaskbook`. For redo, the head label shifts up the list to point to the forerunner `Commit`, after which the `WorkingTaskBook` in that `Commit` is loaded and set as the current `WorkingTaskBook`. Current `WorkingTaskBook` replacement caused by undo and redo will not be saved as `Commits`, since the check for uncommited changes is done by comparing the current `WorkingTaskBook` with the one at which head points to for changes. When a new `Commit` is about to be added to the list of commits and head is not at the top of the list, all the commits after head is removed and then the new `Commit` enters the list. Head is shifted to the top of the list. This is to delete all redoable actions after an action other than undo/redo which causes data changes is executed. `HeadAtBoundaryException` is thrown when there are no commits available for undoing/redoing.

0 comments on commit 750f021

Please sign in to comment.