Undoing user activity

Hi,

I’ve added an Node on the diagram. Next I’ve changed the background color of the node using a Button click. Now I would like to undo the background color to previous one by (pressing ctrl + z one time).

After undoing one time whole node is disappearing from the diagram rather then changing only the background color to previous state.

How can I control the diagram to undo only the activity I performed after adding the node rather then going on the Node level ?

Solution I tried is DiagramModel.CommitTransaction() but might be it built for something else.

Thanks

You need to call StartTransaction before all changes, and then call CommitTransaction afterwards.

Thanks Walter, It’s working fine.

I’ve one more scenario which is slimier to this operation.

Let say I’ve performed two more action (replacing one link with two new individual links). now I would like to maintain this chain in Undo manager.

What I’ve tried so far is multiple Start and Commit Transaction one after another and one inside another but none of them really worked (i.e it misses the sequence, also while undoing deleted link doesn’t appear back, but if I do undo and then again do redo link appears.) Any suggestions to perform the above activity ?

You need to conduct a transaction around all of the changes that you want to consider as a single operation. Don’t do sequential StartTransaction/CommitTransactions.

However, it’s OK to nest transactions, if your code happens to be implemented that way. But you need the single top-level transaction to make when making changes.

In your case I assume you are splicing a node “into” a link. That means adding a node, deleting the old link, adding two links, and connecting the two links with the original ports and with the new node. Or some apps would prefer not to delete the original link but to reconnect it, thereby keeping its data – so you would only add one link.

one more problem I am facing with undo and redo. Please see below steps.

Step 1: Drawing an open link (whose To port is null)
Step 2: Select this link and delete it.
Step 3: undo the previous activity by pressing Ctrl+Z

Current Behavior : It’s going to Top Left corner rather then maintaining it’s Route.Points.
Expected Behavior : It should maintain it’s Route.Point and should appear as it was drawn earlier.

How I can achieve the expected behavior written above or is there something wrong I am doing ?

One can only undo/redo model state, so if the information is not in the model, an undo will not be able to faithfully restore the state of a Link. Is the link route being saved in your model?