fix: Refactor undo/redo functionality and clean up related code#77
Merged
Conversation
Resolve the modify/delete conflict on undo_redo/Undo.pkl by removing the tracked pickle. Undo.pkl is a generated runtime artifact, now excluded via .gitignore (undo_redo/ and src/main/Simulator/undo_redo/). Brings the PR up to date with upstream; undo/redo verified working after the merge.
a4f9f3a to
cdae9ba
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request significantly refactors and improves the undo/redo system in the application, making snapshot management more robust, modular, and consistent. The changes centralize snapshot logic, ensure undo/redo stacks are updated at the correct moments, and enhance the reliability of restoring and saving the application's state, including connections and compound selections.
Undo/Redo System Refactoring and Improvements:
push_snapshotmethod inGraphics.pythat encapsulates the logic for saving the current scene state, clearing the redo stack, and updating the undo/redo action states, replacing scattered snapshot code throughout the application.mainApp.pyto use a more robust stack-based approach: undo now restores the previous snapshot and only pushes to redo if not at the initial state, while redo pushes the redone snapshot back to undo. Also, a new_update_undo_redo_actionsmethod ensures UI buttons are enabled/disabled correctly.push_snapshotat the appropriate time, ensuring that undo/redo stacks are always in sync with user actions. [1] [2] [3] [4] [5]Snapshot Data Structure and Restore Enhancements:
save_canvasnow includes items, connections, and compound selections, and uses deep copies of objects to ensure accurate restoration. Theload_canvas_from_snapshotmethod has been rewritten to fully rebuild the scene, connections, and restore class counters for unique naming.Code Cleanup and Responsibility Clarification:
Container.pyand into the main application logic, clarifying the separation of concerns and reducing redundancy. [1] [2]Other Notable Adjustments:
These changes collectively make the undo/redo functionality more predictable, reliable, and easier to maintain.