How to hook in the copy and paste methods?

Hi,
I have some complex Classes as Node.Data. These Classes get some of their data for other classes at runtime.
How can I implement my own Copy and Paste methods to make all the Stuff I need to do?

For DeleteParts I created my own PartManager and override DeleteParts, but the PartManager has a CopyParts method only and no PasteParts. I the documentation there is written about the CommandHandler, but I find no example how to use this to implement copy and paste.

PartManager.CopyParts just makes copies of parts by copying data into a model – it does not involve the clipboard.

CommandHandler.Copy and CommandHandler.Paste implement the commands for copy and paste to/from the clipboard. These methods call PartManager.CopyParts. But they also call overridable methods for interacting with the clipboard, CommandHandler.CopyToClipboard and PasteFromClipboard.

I’m not sure what you are trying to accomplish, but you probably want to override those methods, so that you can manipulate whatever data that you want in whatever manners that you want, before/after the rest of the Copy/Paste commands do their regular operations.

Hi Walter,
yes I can override CommandHandler Methods - but I don’t know how!
Must I write a new CustomCommandHandler and inherit CommandHandler? Which of the classes (Diagram, Manager…) has the CommandHandler?

I just don’t know how?

I’ve tried:

public class CustomCommandHandler : CommandHandler
{
    public override void Copy()
    {
        base.Copy();
    }

    public override void Paste()
    {
        base.Paste();
    }
}

and then on another place:

MyDiagram.CommandHandler = new CustomCommandHandler();

Is this the right way?

Can I get the parts to paste in the Paste-Method and do some additional operation with them?

One of my issues is that my Node.Data has a Brush-Property. This Brush-Property is not serializable. If I know the Parts to copy and the Parts to paste then I can copy the Brush-Property by my own.

Also, just for information, if the Data is not serializable there is a message in the output window:
Error in model
CopyNode1: over this method to copy nodes, or have…

where is this CopyNode1 methode?

Is the reason for trying to customize clipboard data access due to having to deal with non-serializable objects such as certain Brushes?

If so, I would recommend that you persist the information you need to re-create the desired Brushes, rather than a whole Brush object, which can clearly contain references to elements that cannot be serialized in a manner that can be deserialized. You might use a converter for that, especially if the number of Brushes that you use are limited.

But I have all kind of brushes: Solid, Linear, Radial and Image…
I found out that after the paste the new Nodes are in the SelectedParts Collection.
Can I thrust on that the order of them is the same as in the copy before?
Or is there another way to get the parts to copy and the parts to paste. It’s would be very simple if I can just clone the brushes of the source objects to the target object (and do some internal operation).

Are you asking if the Parts in the clipboard are in the same order that they were when they were selected before the call to CopyToClipboard? No, I don’t think that is guaranteed – I seem to remember sorting the parts by Z-order.

But you might have CopyToClipboard keep a separate Dictionary to keep track of the Brushes that each copied Part uses using some dependable property as the key, and then copy those Brushes over in PasteFromClipboard.