GoDocument override question

Hi,

I created my own GoDocument class which contains an instance of my business layer object model. I thought that by overriding Add and Remove I could control what was inserted into and deleted from my object model. However Add doesn’t seem to be called if I create a copy of an existing node. What’s the recommended way to handle this?

Regards,

Martin

Implement a GoDocument.Changed event handler, perhaps most conveniently in your case by overriding the GoDocument.OnChanged method, and look for the Hint GoLayer.InsertedObject and GoLayer.RemovedObject.
You might also be interested in the cases where objects are added/removed from groups too. Check for the Hint GoLayer.ChangedObject and the SubHints GoGroup.InsertedObject and GoGroup.RemovedObject.

Hi Walter,

Thanks for that. Is there anyway to tell if the Inserted/Removed object was done interactively by the user versus a programmatic call to Document.Add

Regards,

Martin

Not at the GoDocument level (i.e. in the GoDocument.Changed event handler).
To tell when the user did something you could instead implement various GoView event handlers, such as for GoView.SelectionCopied. I don’t know what all the cases are that you would care about – you’ll need to review all the GoView events carefully.
Remember that all interactive gestures result in programmatic actions, but the converse is not true.

Thanks Walter

I have another issue with my GoDocument class. When I copy and paste an item in a view which has this as it’s document I get extra start & stop nodes pasted in. My GoDocument class is like this:

[Serializable]
class StateWorkflowDocument : GoDocument
{
    private Workflow blWorkflow = null;
    private Dictionary<Guid, GoObject> elements = new Dictionary<Guid,GoObject>();
    private bool isDirty = false;
    private StartNode start;
    private StopNode stop;

    
    public StateWorkflowDocument()
          : base()
    {
          blWorkflow = new Workflow();
          start = new StartNode();
          start.Size = new SizeF(50, 50);
          start.Location = new PointF(10, 10);
          this.Add(start);

          stop = new StopNode();
          stop.Size = new SizeF(50, 50);
          stop.Location = new PointF(100, 10);
          this.Add(stop);
    }
}

The problem is to do with the fact that I’m creating the start and stop nodes in the constructor as if I don’t do this then pasting works correctly. Any ideas why this is the case?

Regards,

Martin

Anybody got any input re my last post?

GoView.CopyToClipboard constructs a new document to hold the copied objects to be put in the clipboard.
I suggest you have a separate method to initialize your StateWorkflowDocument with a StartNode and a StopNode.
I don’t know what your Workflow class is, but I assume you don’t mind it being serialized along with the rest of the document, when it is serialized into the clipboard.

Thanks Walter, I had already moved my StartNode and StopNode to an public Init() method, I was just looking for an explanation as to why the nodes were being created on the copy. Now I understand :-)
I have to fine tune the serialization, at the moment I just copy everything I will fine tune later by marking some fields as [NonSerialized] which I think will sort that out.

Regards,

Martin