Undo and GoDocument.UserObject


I am using the GoDocument.UserObject to hold another nonGoDiagram object for me which is working great until I try to utilize the undo functionality of GoDiagram. For some reason, after the first time I undo something in my interface like the deletion of node/link, the code no longer knows what the GoDocument’s UserObject is. I have no idea why this is happening - do you have any ideas?



It sounds like you set the GoDocument.UserObject property to some value during a transaction, which is undone (i.e. set back to nothing) when during a GoDocument.Undo().
Setting GoDocument.UserObject is treated like any other normal property, of documents or of GoObjects.


I am having a similar problem. I have some properties and fields in an object derived from GoSimpleNode that I have marked with as Nonserializable. When Undo and Redo get called, the fields as expected are set back to their default value. However I need to override that functionality without making them serializable. When I click undo after deleting a node, the nodes that have been deleted just magically appear on the document with the document’s add function getting called, and neither the Node’s constructor or CopyObject function was called. What function can I override to catch the node as it is being deserialized and fix the values of the properties that are not getting set?


Basically this is what I have to do in my GoDocument Class when I undo something in the interface:
Public Overrides Sub Undo()
myObject = view.Document.UserObject
view.Document.UserObject = myObject
End Sub
Before I call MyBase.Undo, myObject is still contained in view.Document.UserObject. After the mystical process of MyBase.Undo this is no longer the case. And myObject is nonSerializable as well so maybe that’s the problem. I am handling for it right now as you see but the Undo functionality is a mystery to me and I was wondering why this is happening.
Andrew, I am having similar difficulties in tracking nodes and links after the undo process to make sure their userobjects are getting set correctly - right now I have some pretty crazy code handling it but if you find out an easier and more efficient way of keeping track of nodes and links during and after the undo process I would love to know about it!