Non-DataModel undo/redo

Oftentimes, I’m implementing a plugin which would benefit from having undo and redo functionality. For example, consider a node graph editor, where you might want to undo creating nodes, connecting nodes, configuring properties on nodes, etc.

These undo and redo actions do not correspond to any change in the data model. However, ChangeHistoryService seems to be geared towards undoing and redoing changes to the data model only. It’d be helpful if there were some mechanism by which we could add our own custom actions to the undo stack, such that our own code is called when the action is undone or redone.

For some plugins, it may be desirable to mix these actions in with the normal stack, for example if they’re dealing with in-world tasks. For others, such as 2D editors, they may prefer to keep their own stack, but still share the same keyboard shortcuts.

This allows plugins to respect the user’s keyboard shortcuts for undo and redo (important for seamlessly supporting Windows and macOS) and integrates with Studio’s native buttons, so there aren’t two undo buttons on-screen with one being the ‘wrong’ undo.

15 Likes