DataProvider not called if parent of the performed action does not have the focus

Answered

Hi,

my problem concerns the search for the DataProvider of an AnAction.

I have a tool window that has a panel as its content, which implements the DataProvider interface. The panel also has an AnAction, which requires data from the DataProvider implementation when it is executed.

If the panel has the focus and the user clicks on the action, everything is fine. But if the tool window is open, another component outside the tool window has the focus (e.g. the editor) and the action is clicked, my DataProvider is never called, since the DataContext of the AnActionEvent searches the DataProvider starting from the focused element.

I'm a bit lost at the moment, as I seem to be missing something in the DataProvider concept, as in my constellation it is never guaranteed that my implantation is called.

So far I have come up with the following solution/workaround, but this has the disadvantage that I would have to bind the action tightly to its parent and thus the loose coupling between action and parent, which is created by the DataProvider concept, would be undermined:

class MyAnAction(private val parent: JPanel) : AnAction(...) {
override fun actionPerformed(e: AnActionEvent) {
MY_DATA_KEY.getData(DataManager.getInstance().getDataContext(parent))
}
}

Many thanks in advance and kind regards,
Marcel

0
1 comment

It is possible to provide "global" DataProvider via com.intellij.ide.impl.dataRules.GetDataRule

PS: Your AnAction must never store/have any fields for whatever reason

0

Please sign in to leave a comment.