I drag one or more instances of a custom GoBoxNode into a custom SubGraph using the key modifier to enable the drop on the SubGraph. I overrode OnSelectionDropped inside my SubGraph class. When the drop occurs and the OnSelectionDropped method is fired in my SubGraph class, view.selection is empty, even though I know that I am dragging/dropping one or more GoBoxNodes into the SubGraph. The GoObjectEventArgs var, evt, does list the first object dragged into the SubGraph (evt.GoObject.Parent) but the selection is empty.
Is the problem that the drop has already occurred and view.selection is no longer valid?
Yes, you’re basically right – the drop has already happened, so the object(s) have been reparented (in SubGraphDraggingTool.DoDragging), causing those objects to have been removed from the GoView.Selection. That appears to be a bug in that example tool.
That custom tool ought to re-establish the selection after it calls AddCollection in order to perform the reparenting.
Change the definition of SubGraphDraggingTool.DoDragging to add two statements after each call to AddCollection:
OnSelectionDropped is also called when moving/repositioning SubGraph children. Is there anyway inside OnSelectionDropped to distinguish between performing an actual drop into the SubGraph and moving/repositioning SubGraph children?
I know one possibility is to check if evt.shift is true or false (true meaning a drop has occured). This approach will work as long as the key modifier is used to enable drop on the SubGraph. My concern is that if my customers don’t want to have to press the key in order to perform a drop, but want to drag onto the SubGraph instead (without having to press the key. Not sure how I would program this change of behavior anyway, since I do want MustBeMoving() to be true.
Actually, that whole SubGraphDraggingTool isn’t strictly necessary, since its effects could be implemented using …SelectionDropped event handlers, with …EnterLeave event handlers to handle the highlighting. [Caveat: well, only if GoSubGraph.PickableBackground is true.]
For your particular question, the drop has already occurred at the time of that event. You’d have to look at the GoView.Selection before the calls to AddCollection, as I’ve shown above.
Remember that the user might simultaneously select some objects that belong to different subgraphs and/or that are top-level objects.