How to use Child Transactions (Undo and Redo)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
My add-in displays a window, and I wrap everything that happens while the window is open into a single transaction. This is working fine. However, I want to build undo/redo within the window. I thought I could accomplish this using child transactions, but I can't seem to figure out how they work.
I've read this article: How Nested Transactions, Undo and Abort Work in Inventor?, but it doesn't demonstrate how to use child transactions, just explains the concept. I've played around with child transactions and checkpoints, as discussed in the article, but I can't get it to work right.
Let me demonstrate what I'm after with a workflow example:
- Window opens, Main transaction is started
- User clicks "Command A"
- Child transaction "A" is started
- Changes are made
- Child transaction is ended
- User clicks "Command "B"
- Child transaction "B" is started
- Changes are made
- Child transaction is ended
- User hits the "Undo" button. How do I undo everything that happened within child transaction "B"?
- User hits the "Redo" button. How do I re-do everything that happened within child transaction "B"?
- User clicks "Command A"
So far, I've only managed to roll back changes within a transaction using checkpoints, but then there's no possibility of a redo. The rolled-back work is gone forever.
So, how can I undo/redo child transactions just like we can with parent transactions? And if it's not possible, what even is the point of child transactions?