Detailed documentation about Visio's Undo system

Started by Visisthebest, December 30, 2020, 11:17:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visisthebest

I've looked around the Microsoft website but unfortunately I cannot find any detailed information about the inner workings of the Visio undo/redo system. Any tips about where to find it appreciated!

Why is this important?

To keep data on the VSTO add-in side and in a Visio diagram in sync I use the UniqueIDs (GUIDs) just in case users move stuff around from page to page in Visio and changes the regular ID's.

When I use the Shape.Unique property with this setting:
visGetOrMakeGUID   1   Returns the unique ID string of the shape. If the shape does not yet have a unique ID, it assigns one to the shape and returns the new ID.

I set the GUID on any shape that doesn't already have one, and keep track of those GUID's in the VSTO add-in.

Now this is why understanding Undo/Redo is important.

If undo/redo stores the command but not the exact data of the change that occurred, the GUID might change when undoing/redoing!

I tested it and as far as I can see, Visio stores the exact data of the change that has occurred (thus no chance of GUID's changing between undo/redos). If anyone can confirm they also observe this behavior I appreciate it! Always worried I'm overlooking something.

It would be nice to be sure of this as well as knowing for sure this works the same going back until Visio 2010, but of course that requires Microsoft to document this well somewhere for us to find, which hopefully they did and I just overlooked.

Thank you for your insights on the undo/redo system!
Visio 2021 Professional

Nikolay

#1
I think maybe it's safer to assign your own guids? Creating new guid in C# is trivial: Guid.NewGuid(). So that you don't depend on Visio behavior, and you can use guids from some external storage.
Think export-import for example. It won't work if you let Visio generate ids, as far as I understand.

Anyway. I think I was learning about undo/redo from Graham Wideman's book, but that was like 20 years ago. Maybe now there is something better.
Take a look at http://diagramantics.com/ (there is a chapter on undo and some sample for custom undo unit, for vba, as c# did not exist when this book was written).
And that article from the "developing Visio solutions book" I mentioned before is also not bad at all.

I tried searching github for sample code with ivbundounit but found only my own code :D

Visisthebest

Thank you Nikolay yes probably better to use a custom GUID field and generate GUIDs outside of Visio.

Will check out the chapter on undo from Diagramantics good to find some documentation on the undo system. Thank you!
Visio 2021 Professional