Visio Guy

Visio Discussions => Programming & Code => Topic started by: Visisthebest on December 29, 2020, 04:15:58 AM

Title: Visio event codes - capturing a user undo/redo event
Post by: Visisthebest on December 29, 2020, 04:15:58 AM
Looking in the Visio event codes list:
https://docs.microsoft.com/en-us/office/vba/visio/concepts/event-codesvisio

I cannot find an event that helps to provide notification that the user has pressed the undo or redo button. Is it possible to capture the event of the user pressing undo or redo?
Title: Re: Visio event codes - capturing a user undo/redo event
Post by: Nikolay on December 29, 2020, 12:32:09 PM
Probably what you are actually want to achieve is undoing/redoing your (custom) actions when user clicks undo/redo?
To implement that, you don't need to capture undo/redo events, you need to create IVBUndoUnit and put your actions there.

The official docs page on IVBUndoUnit is unfortunately quite short:
https://docs.microsoft.com/en-us/office/vba/api/visio.ivbundounit

You could check out this old page regarding the undo/redo units (from the "Developing Visio Solution" book, it was a part of MSDN years ago, but now I could not find it on Microsoft Docs, so the first link from google):
https://flylib.com/books/en/2.268.1.140/1/
Title: Re: Visio event codes - capturing a user undo/redo event
Post by: Visisthebest on December 29, 2020, 04:32:08 PM
Thank you Nikolay I couldn't find it.

The key reason is that for VSTO performance reasons I am more or less caching information about the model in the VSTO add-in.

To keep it simple for now, if the user performs an undo I just invalidate the cache because the in-memory model in the add-in and the Visio diagram might have become out of sync. I don't want to block undo functionality of course, because it is so user-friendly, but do want to avoid an out of sync add-in 'cache'.

(my model is code-built only, I protect the 2D shapes and connectors from deletion, and I can see if a shape has been added by hand)