GoPalette

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.

Regards,

Martin

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:

    protected override void CopyChildren(GoGroup newgroup, GoCopyDictionary env)
    {
          base.CopyChildren(newgroup, env);
          StateNode newnode = (StateNode)newgroup;
          newnode.decorators[0] = (FlowControlDecorator)env.Copy(decorators[0]);
          newnode.decorators[1] = (FlowControlDecorator)env.Copy(decorators[1]);
          newnode.decorators[2] = (FlowControlDecorator)env.Copy(decorators[2]);
          newnode.decorators[3] = (FlowControlDecorator)env.Copy(decorators[3]);
    }

Things are better but still not right. What else would I have to check?

Regards,

Martin

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.

Are you not copying the decorators array?

I had tried that but I kept on getting a null ref exception. Here’s the code:

decorators is declared as follows:

    private FlowControlDecorator[] decorators = new FlowControlDecorator[4] { null, null, null, null };

Each element gets set by the user, code to do this is:

    private void AddDecorator(FlowControlDecoratorPlacement side, FlowControlType type)
    {
          if (decorators[(int)side] != null && type == FlowControlType.Sequence)
          {
              FlowControlDecorator d = decorators[(int)side];
              decorators[(int)side] = null;
              Remove(d);
              return;
          }
          if (decorators[(int)side] == null)
          {
              decorators[(int)side] = new FlowControlDecorator();
              decorators[(int)side].Type = type;
              decorators[(int)side].Side = side;
              InsertBefore(this.Background, decorators[(int)side]);
          }
          else
          {
              decorators[(int)side].Type = type;
          }
    }

Here’s my CopyChildren as it stands.

    protected override void CopyChildren(GoGroup newgroup, GoCopyDictionary env)
    {
          base.CopyChildren(newgroup, env);
          StateNode newnode = (StateNode)newgroup;
          newnode.decorators = env[decorators] as FlowControlDecorator[];
          newnode.decorators[0] = (FlowControlDecorator)env[decorators[0]];
          newnode.decorators[1] = (FlowControlDecorator)env[decorators[1]];
          newnode.decorators[2] = (FlowControlDecorator)env[decorators[2]];
          newnode.decorators[3] = (FlowControlDecorator)env[decorators[3]];
    }

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];

I had already tried that and still I had the problem. I’m tearing my hair out with this one as it just doesn’t make sense. Any more suggestions?

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 Embarrassed 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.Wink
Thanks for your patience in this matter. Support really is one of the best I’ve seen.Clap

Regards,

Martin