Hello!
Yes, you have tried to fix things up after various events, but you’re right – that’s not going to work in general.
The GoDiagram architecture was specifically designed to support this uncommon scenario. You need to have your GoDocument perform all copying operations using a custom GoCopyDictionary that is initialized to include that special singleton node.
[code] [Serializable]
public class SpecialDocument : GoDocument {
public SpecialDocument() {}
public override GoCopyDictionary CreateCopyDictionary() {
GoCopyDictionary env = new SpecialCopyDictionary();
env.DestinationDocument = this;
if (this.SpecialNode != null) {
env[this.SpecialNode] = this.SpecialNode;
GoGroup g = this.SpecialNode as GoGroup;
if (g != null) {
// this might need to be recursive, if your nodes might have more than one level of grouping
foreach (GoObject obj in g) {
env[obj] = obj;
}
}
}
return env;
}
}
goView1.Document = new SpecialDocument();[/code]
However, if you want dynamic recognition of which nodes are the “same” as your SpecialNode, you can’t initialize the GoCopyDictionary to map the SpecialNode to itself, since you don’t know statically what the source node might be. This is typically the case when dragging nodes in from another control, including other GoViews, including GoPalette.
In such a case you need to define a custom GoCopyDictionary and override GoCopyDictionary.Copy to return your SpecialNode when the argument GoObject is a “matching” node. The same goes for parts of your SpecialNode, such as GoPorts if you want copied links to magically connect to your singleton SpecialNode.
[code] [Serializable]
public class SpecialCopyDictionary : GoCopyDictionary {
public SpecialCopyDictionary() {}
public override GoObject Copy(GoObject obj) {
if (obj == null) return null;
SpecialDocument doc = this.DestinationDocument as SpecialDocument;
if (doc != null && doc.SpecialNode != null && ...obj-matches-SpecialNode...) return doc.SpecialNode;
return base.Copy(obj);
}
}
[Serializable]
public class SpecialDocument : GoDocument {
public SpecialDocument() {}
public override GoCopyDictionary CreateCopyDictionary() {
GoCopyDictionary env = new SpecialCopyDictionary();
env.DestinationDocument = this;
return env;
}
public GoNode SpecialNode { ... }
}
goView1.Document = new SpecialDocument();[/code]