kitjmv
(jmv)
September 27, 2020, 12:57am
1
Is it possible to add custom behavior when a file is drag?
I whould like drag a “.csx” or “.cs” file and place a script component under the mouse.
The ideal would be to be able to override GH_Canvas.Canvas_DragDrop_Files
but this function is private.
Is this the usefulness of IGH_CanvasValidator
? Could someone explain how this works?
jmv.
kitjmv
(jmv)
October 14, 2020, 12:56am
2
public class CustomDragDrop
{
DragEventHandler m_original_handler;
public DragEventHandler OnDragDrop;
public void CustomDragDrop (GH_Canvas canvas)
{
var canvasT = typeof (GH_Canvas);
var eventT = canvasT.GetEvent ("DragDrop");
var original_methodT = canvasT.GetMethod ("Canvas_DragDrop", BindingFlags.Instance|BindingFlags.NonPublic);
m_original_handler = (DragEventHandler)original_methodT.CreateDelegate (typeof (DragEventHandler), canvas);
eventT.RemoveEventHandler (canvas, m_original_handler);
canvas.DragDrop += ActiveCanvas_DragDrop;
}
private void ActiveCanvas_DragDrop (object sender, DragEventArgs e)
{
OnDragDrop?.Invoke (sender, e);
m_original_handler?.Invoke (sender, e);
}
}
Only for Windows I guess
There’s only an official api in grasshopper for handling drag+drop onto document objects, not the canvas. So yeah, handling the winforms event will get you there unofficially, and I don’t know either whether that will translate to mac…
kitjmv
(jmv)
October 14, 2020, 11:33am
4
Hello David
It can be useful to have a “GH_ComponentAttributes.RespondToDragDrop” method in the Grasshopper API (and on the document that would be nice too).
This can be useful when our custom components use external resources.
jmv.