I’m seeing some strange behaviour with GoPalette. I add a node to it as follows
goPalette2.Document.Add(new StateNode());
But when I drag a node onto a GoView the selection rectangle is bigger than the node. Then when I set some properties on the shape the one on the palette changes and the one on the GoView is screwed up. Do I need to do anything special with the GoPalette. My node works okay if I add it to the GoView programatically.
As I thought I was missing something. I had no override for CopyChildren. My node contains an array of child nodes so I had to copy these. I implemented it as follows:
Yes, that sounds like a typical case of not implementing copy semantics correctly. If I were you I would make sure that copying correctly handles all references that you had added as fields in any of your classes.
Regarding your override of CopyChildren – that looks fine. It’s slightly faster and shorter code to write:
newnode.decorators[0] = (FlowControlDecorator)env[decorators[0]];
Thanks for the tip. I’ve been refactoring my class and changed it so that some of the children are being created as needed. Originally the were all created in the constructor. Now when I drag the node from the GoPalette I get the old behaviour where the GoPalette view is updated and not the node I dragged on. My CopyChildren method is still as per above. Any suggestions on what may be causing this behavior.
You’re not copying the decorators array – so that array is being shared by instances of your node.
In your CopyChildren method you can instead do:
newnode.decorators = new FlowControlDecorator[4];
Maybe there’s another problem somewhere else, but I was just pointing out that you definitely need to make sure that array of FlowControlDecorators is not shared.
I suggest you look at each object in the node that got dropped in your main view. Each GoObject ought to be a child of that node, not the node in the GoPalette.
Also, have you tried control-drag-and-drop within the view?
What about copy-and-paste within the view?
Are there any other reference fields in any of your classes?
I had another reference field which wasn’t being copied All seems to work well now. I’ve been looking at it so long it wa a case of not seeing the wood for the trees.
Thanks for your patience in this matter. Support really is one of the best I’ve seen.