I am using GoDiagram .NET 2.1.2 for WinForms. I have a base class “DiagramNode” that inherits from GoIconicNode and implements ISerializable.
I am trying to implement Cut/Copy/Paste, as well as Ctrl drag-copying, and am having trouble understanding the behavior of CopyObject() and it’s interaction with the ISerializable interface methods with these different types of copying.
With Ctrl drag-copying, CopyObject() only gets called once. While debugging in CopyObject(), it appears that “this” is the original object that is being copied “from”, and that base.CopyObject() returns the new object that is being copied “to”.
All fields in the new object have the identical value as the corresponding field in the original object. Fields that are references to objects must be new’d for the new object, otherwise both the old and new object would have references to the same instance.
The ISerializable interface methods are never called for drag-copying.
With clipboard Cut/Copy/Paste, here is the sequence I observe: On Cut/Copy, I only get a call to CopyObject(). On Paste, I get calls to 1) the ISerializable method GetObjectData(); 2) the ISerializable constructor; 3) CopyObject().
The CopyObject() during Cut/Copy appears to be the same as a drag-copy. “this” is the original source object, and base.CopyObject() returns a new object that appears to be an exact copy of the original, with fields that are object references being references to the same instances. I assume (but may be wrong), that this CopyObject is copying from my GoView’s Document to the Clipboard Document.
The CopyObject() during Paste, however, seems different. I assumed that it was copying from the Clipboard’s Document to my GoView’s Document, and that therefore “this” would be the object on the Clipboard Document and that base.CopyObject() returns the new object being pasted to my GoView’s Document. I am not sure if this is correct.
During the Paste CopyObject(), the call to base.CopyObject() returns a GoObject with null values for all of my member fields (fields that aren’t part of the GoIconicNode base class). If I initialized any of my fields in the ISerializable contructor, these values are shown in this object (rather than null).
Here are my questions:
- Is there any full documentation on how to use CopyObject(), CopyChildren(), and ISerializable with respect to Cut/Copy/Paste as well as Ctrl drag-copying? The GoUserGuide, GoFAQ, and Go Reference Manual do not answer these questions adequately.
- In the CopyObject() call which executes during Paste, does base.CopyObject() return the new object that is being pasted into the View’s Document?
- From within CopyObject(), is there an easy way for me to distinguish if I am in the middle of a “Ctrl drag-copy” rather than a “Paste” operation?
- Why are the ISerializable interface method GetObjectData and the ISerializable constructor not called during Cut/Copy – only during Paste?
Thanks in advance for any assistance,