-
Notifications
You must be signed in to change notification settings - Fork 1
SketchMorph2 Undo
In general, there are two ways to implement undo functionality, each with its own advantages and drawbacks:
The idea of this approach is to save the state of the program (in our case the backend's form) after each user interaction.
The problem with that is that it uses a lot of memory to save a lossless bitmap after each step.
To generate the state of the program before the last interaction, every user interaction is saved. Then, the program is reset to its initial state and every one but the last user interaction is redone.
This has the advantage of not being too memory intensive but redoing many user interactions can take a lot of time.
To address the problems with these approaches, we have chosen a combination of the two. In the beginning and after a number of user interactions (predefined in M2Backend's defaultMaxActionQueueSize
) an M2UndoLevel is generated and saved on a stack. This object contains an initial form and an OrderedCollection of M2UserActions. Each user interaction generates an M2UserAction that gets saved in the last M2UndoLevel. When the undo button is pressed, the form gets reverted to the last M2UndoLevel's form and all but the last M2UserActions in that M2Undolevel's collection are recreated.
Thus, a form is saved only after a certain number of steps and undoing a step only requires a low maximum number of interactions to be recreated.