Hi team, I would like to listen for the dragAndDrop
event of an editor tab when it is being dragged or dropped.
How can I achieve this?
Thank you.
Hi team, I would like to listen for the dragAndDrop
event of an editor tab when it is being dragged or dropped.
How can I achieve this?
Thank you.
Check out com.intellij.fileDropHandler
:
Thank you for your reply.
I just tried using this interface. It looks like it can detect files being dropped (e.g., from the desktop into the IDE). However, when I try to drag and drop an active editor that is open in IntelliJ (e.g., when splitting the editor window), no events are captured.
Hi @phanthaiduong22 - ah my apologies, I misunderstood! I’ve actually been trying to do something similar, but I’ve been looking/trying via a very low-level interface; an awt listener. It gets a ton of events, and I haven’t been able to pin down the exact filter yet to catch the event for this though. If you think it’d be helpful, I can dig it up and share
Yeah, Chris, I think it would be helpful as well. Could you share it? I will also take a look at how to filter drag-and-drop events from an active editor based on what you shared.
Additional information: I can use: java.awt.dnd.DropTargetAdapter
to listen drag and drop events from projectTree, or files from commit tab. However, when I tried drag and drop an active editor file, it can’t listen.
When I use debug mode.
being triggered. But not sure if we can use similar to this.
I would like to listen for the
dragAndDrop
event of an editor tab when it is being dragged or dropped
What is the use case?
Hi @yann.cebron use case is developing a chat with an LLM feature, and I want to drag and drop an editor tab into the chat for reference.
@phanthaiduong22 - I’m starting to think this might not be possible, without some guidance or code changes from JetBrains.
Specifically, I tried adding a java.awt.event.AWTEventListener
with a mask of AWTEvent.MOUSE_EVENT_MASK
(I’m 99% confident this is the correct mask), and I get all the mouse events I’d expect, but when dragging tabs and releasing in a new position (I’m also seeing EditorTabbedContainerDragOutDelegate
fwiw, so I think we’re both on the right track), it seems like something is consuming the event and the listener I created is not getting called.
(A few days later…)
After typing the above, and hacking around the code a bit more, I was able to get a bit further, but not by much. I was able to get a mouse listener added, with a lower ‘weight’ (so it would get called before whichever listener was consuming the event mentioned above), but now I’m struggling to figure out if the java.awt.event.MouseEvent
is coming from a ‘drag and drop’ type ‘mouse event’, or if its something else.
I just saw GitHub - MikSuki/TabSplitter plugin in marketplace, and thought it might have some code that may help here.
I haven’t had a chance to look into any of this further, but @phanthaiduong22 if you happen to be looking still, perhaps this repo/plugin might have something of interest?
Yeah, I just had a quick look at the source code. It looks like it has fileClosed
or fileSelectionChange
listeners, but it doesn’t have a drag-and-drop file listener.