Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Undo/Redo to ReClass.NET #263

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

FransBouma
Copy link

@FransBouma FransBouma commented Jul 4, 2023

I've implemented this in a separate branch (with the changes from my previous PR #262 already merged).

What's changed?

  • Undo/Redo support for class creation/deletion/modification
  • Undo/Redo support for changing nodes / node types / address etc.
  • Added an undo/redo button pair to the toolbar using the existing icons already in the resources
  • Defined some toolbar buttons for some node types to be able to overflow the toolbar if the window is narrow

I didn't implement undo/redo for enums as the enum functionality is a bit broken I think (there's an add event but not a remove event for instance. I had it working more or less but didn't want to add it just yet) so I left it as-is.

I added this using Algorithmia's command system. This is a library I wrote a long time ago and maintain since, and it's very stable. It comes with 2 nuget packages (algorithmia and bcl extensions).

The system basically tracks commands executed through the command queue manager and records every command in the 'active' queue on top of the stack. So when a command A changes something that executes a command B, B will end up in A's command queue and B's command queue is then put on top of the stack. This way you can track multiple commands within the scope of a single command and undo/redo them in 1 go. A command is an object with a lambda that makes a change and it has optional lambda's to obtain the pre-change state and the post-change state. Algorithmia has several datastructures that mimic BCL classes (like list) and wrappers (to wrap members to make them undo/redo aware) and they take care of change checking and event raising as well.

I have tested it with several class hierarchies and I think it works ok, but I know from experience that Undo/Redo code can get hairy at times especially in edge cases, e.g. multiple undo/redo sequences work ok but perhaps I missed an edge case and an event handler creates duplicate elements when redoing the whole tree of commands.

Let me know if you need additional info, or if I have to make additional changes :)

NOTE the commits in this PR are apparently also the ones in #262 :( Which sucks, and might be complicate file reviewing. If you want to wait reviewing this because of that, that's fine. I'm sorry this happened, I honestly don't know how to avoid that.

…olbar button to toolbar menu item so it can have a shortcut too.
…sable from different nodes. Changed VTable node so it always displays the RTTI information if available.
…e class. This required some hairy work in a lot of places as the context menu wasn't usable on nested classes. It now is
…ks without opening the menu. Made the window a bit wider (was too small already) so all toolbar buttons are visible
… it gets removed when the window is too narrow
… the window is too narrow to make room for undo/redo buttons
…romBuffer to MemoryBuffer, have refactored Hex32Node to use this method instead, have removed unnecessary braces and brackets.
…dlers to the ShowException method in Program so it always catches all exceptions thrown
@Sightem
Copy link

Sightem commented Oct 16, 2023

Status on this?

@FransBouma
Copy link
Author

I think @KN4CK3R has to find some time to handle this, and perhaps is currently busy with other things. If you want to use it, you can pull this PR's code and build it yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants