Custom behavior for Drag/Drop event

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.

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…

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.