Author Topic: Visio event codes - capturing a user undo/redo event  (Read 493 times)

0 Members and 1 Guest are viewing this topic.

Visisthebest

  • Sr. Member
  • ****
  • Posts: 389
Visio event codes - capturing a user undo/redo event
« on: December 28, 2020, 11:15:58 PM »
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?
Visio 2021 Professional

Nikolay

  • Hero Member
  • *****
  • Posts: 1062
    • UnmanagedVisio
Re: Visio event codes - capturing a user undo/redo event
« Reply #1 on: December 29, 2020, 07:32:09 AM »
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/

Visisthebest

  • Sr. Member
  • ****
  • Posts: 389
Re: Visio event codes - capturing a user undo/redo event
« Reply #2 on: December 29, 2020, 11:32:08 AM »
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)
« Last Edit: December 29, 2020, 11:33:40 AM by Visisthebest »
Visio 2021 Professional