I figure this is a long shot, but I'm a bit desperate and Microsoft is no help. I'm creating an add-in that needs to support undoing. Some add-in operations modify the document, but also perform actions outside the document. The former end-up in Word's undo stack and I can even group them as a custom undo record to make them atomic, but I need to also be able to undo the latter when that undo record is, well, "undone" by Word.
Initially, I had hoped there would be some "beforeUndo" and "afterUndo" events I could handle, but I can't find any. Googling in every direction, I stumbled across the possibility of "repurposing" Word's commands in my Ribbon XML to handle them myself. The example I found was for the "Save" command, and it goes like this:
<button idMso="FileSave" onAction="MySave"/>
This requires a handler with this signature:
public void MySave (Office.IRibbonControl control, bool cancel)
This works as you'd expect. So I looked up the idMso for "Undo", and found that it's not a "button", but a "gallery", and so wrote this in my Ribbon XML:
<gallery idMso="Undo" onAction="MyUndo" />
And I gave MyUndo the same signature as MySave.
Word's "undo" control does correctly show-up in my add-in's ribbon tab, HOWEVER "MyUndo" doesn't get called. My educated guess is that "MyUndo" should have a different signature.
I couldn't find any information on this through Googling, so here I am. In practice I have two problems to solve:
- Get my undo handler to get called with the user "undoes" something
- Get the name of the undo record that was (or is being) undone
I don't even know if I'm using the correct approach to implement the feature I described, so I'm open to any option that lets me add my own code to a custom undo record. I'd be much happier if this could be done through events, though... Ribbon XML makes me feel dirty :-D