Hi Sylvain,
Absolutely, you’re on the right track! Implementing a custom undo/redo stack is a robust, general approach, especially when you want to avoid relying on undocumented or deprecated features like "uiundo". Following is a general undo/redo pattern you need to adapt for your MATLAB GUI app.
You maintained two stacks:
- Undo Stack (DataBackwardStep): stores previous states.
- Redo Stack (DataForwardStep): stores states you can return to after an undo.
I have implemented a similar functionality and attached the .mlapp file for your reference. Please review the code section of the app; it will give you a better understanding of the implementation.
Kindly ensure the following points for the usecase of this application.
- State Storage: If your data is large, consider storing only the differences (deltas) or using lightweight representations.
- Limit Stack Size: To save memory, you might cap the stack size (e.g., keep only the last 20 actions).
- GUI Update: After undo/redo, update any relevant UI components to reflect the restored state.
For more information regarding the "uiButton" in App Designer. Kindly refer to the following MATALB documentation: