Hi,
Can we get drop target of a node with ExternalObjectsDropped event when dropped from palette to main diagram?
Basically I want to know if the drop target is a Node or a Link or Canvas.
Hi,
Can we get drop target of a node with ExternalObjectsDropped event when dropped from palette to main diagram?
Basically I want to know if the drop target is a Node or a Link or Canvas.
When you want to have different behaviors for different kinds of targets, it’s common to set the GraphObject.mouseDrop event handler (and for feedback, the mouseDragEnter and mouseDragLeave event handlers), rather than using a global “ExternalObjectsDropped” DiagramEvent listener.
I suppose it’s convenient that in the latter case you know that it’s an external-drag-and-drop, whereas for the mouseDrag… and mouseDrop event handlers it could be either internal or external. If you want the same behavior for both internal and external, then that’s good; but if you want different behavior you can just check whether .diagram.currentTool instanceof go.DraggingTool
or not. For internal drags, it’s the DraggingTool that’s running; for external drags, it’s another Diagram’s DraggingTool that’s running, but not the target Node’s or Link’s Diagram’s DraggingTool.
Yes we need different behaviours for Drop from Palette and drop within the diagram. For some reason diagram.currentTool instanceof go.DraggingTool is always false for me. I tried to check this in both mouseDragEnter and mouseDrop. It is false in both the places.
Really? I just tried this, and it produced the results that I expected as I tried dropping nodes onto a node either from a Palette or from within the same Diagram.
const myDiagram =
new go.Diagram("myDiagramDiv", {
mouseDrop: e => console.log("Background",
e.diagram.currentTool.name,
e.diagram.currentTool instanceof go.DraggingTool)
});
myDiagram.nodeTemplate =
new go.Node("Auto", {
mouseDrop: (e, node) => console.log(node.key,
e.diagram.currentTool.name,
e.diagram.currentTool instanceof go.DraggingTool)
})
. . .