Undo state and DocumentChanged


In our product, the GoDiagram part plugs into an IDE and is loosely coupled to the IDE via asynchronous events. The main menu must therefore be notified of state changes such as selection and undo/redo at some view event, not having access to GoDiagram state at such time as the Edit menu is popped.
I had planned to check CanUndo() and CanRedo() at the DocumentChanged event; however the results of these calls appear to be always false at this point. Is this observation as expected? What would be the preferable spot to make these tests and notifications?


From the documentation of GoUndoManager.CanUndo:

In order to be able to perform an undo, a transaction must not be in progress, nor an undo or a redo. Furthermore there must be an EditToUndo that itself is ready to be undone.
I would suggest overriding the FinishTransaction method, calling the base method first, and then notifying the IDE whether CanUndo() and CanRedo() are true. This is what GraphDoc does in the ProtoApp sample.


That’s got it, thank you, I appreciate it.