Copy/Paste NonSerializable GoObjects

Hi,

I’ve been dealing with Copy and Paste issues in my application and running into issues that I’ve not dealt with before. I’m trying to identify solutions but I’m not sure that what I’m doing is the best approach, so I’m asking for any suggestions you might have to better deal with these
issues.

My GoObjects need to persist data that is not serializable. Since copy/paste is an important part of my app, I’ve designed my own copy/paste implementation based around a GoSelection that is not tied to my GoView. This GoSelection is a copy of the real GoView.Selection, but created in such a way that I can be assured that my nonserializable data will be persisted in my GoObjects correctly.

During the paste operation, I’d like to insert my GoSelection into the GoView.Document in place of the real GoView.Selection. Since my GoSelection is not tied to the GoView, how do I compute the correct locations (top left corner) for the objects in my selection? Also, is there a way to insert my GoSelection into the GoView.Document without making another copy of the objects - Calling GoView.Document.CopyFromCollection calls the CopyObject method on every GoObject to make another copy.

Any suggestions you can offer would be greatly appreciated.

Thank you.

R. Houston

First of all, the clipboard uses a GoDocument (and not a selection) for holding the objects in the clipboard. It’s not clear why you picked Selection.
If you can “persist” the data, maybe you can figure out how to fit that into serialization… it really is easiest to just use the support that’s in GoDiagram. (Instead of serializing a GoImage, for example, GoDiagram just serializes the info for re-creating the GoImage.)

Trust me on this, the code under CopyToClipboard is non-trivial. It handles the case where a child and parent are both in the selection. It does a 2 pass copy so it can fix up references. It handles exceptions that can happen in reduced trust environments. and so on...
to answer your questions....
re: how do I compute the correct locations
You can use GoDocument.ComputeBounds to figure out the bounding rectangle for the objects in the selection. GoView.MoveSelection might be useful too.
is there a way to insert my GoSelection into the GoView.Document without making another copy of the objects
GoLayer.AddCollection may help.