Mouse and Keyboard support for Actions in Tree
Answered
I'm learning about how best to organize actions for
I would like to trigger an existing Action that I have when the user double-clicks a node in the
Tree
that I have in a ToolWindow
.I would like to trigger an existing Action that I have when the user double-clicks a node in the
Tree
that I have, AND when the user hits the key VK_ENTER
I have already added a bunch of actions in an ActionGroup
to a popup menu on my custom Tree usingPopupHandler.installPopupMenu()
that contains all the possible actions for any selected node (when the menu pops up).
Most of these actions are already configured with keyboard shortcuts (using
registerCustomShortcutSet
).This all works just great when the right-click on a node in the
So, now I want to fire one of those actions when the user double-clicks the node in the
(preferable selecting the action that has the
How should I be arranging all this to support both keys and mouse clicks? (edited)
Tree
, then the popup menu shows what Actions are available, and the user can invoke the appropriate action from the menu.So, now I want to fire one of those actions when the user double-clicks the node in the
Tree
(preferable selecting the action that has the
VK_ENETER
registered, but I'll settle for something else)How should I be arranging all this to support both keys and mouse clicks? (edited)
Please sign in to leave a comment.
double-click:
com.intellij.util.EditSourceOnDoubleClickHandler#install(javax.swing.JTree, java.lang.Runnable)
Thanks Yann Cebron,
I looked at that API, and decided it is not what I need.
My custom `Tree` is not file based.
Instead, I want to learn about the best practices for defining and managing a set of `AnAction` that are used by the `Tree` in different ways based upon its selected `DataContext`.
I understand how to assign them to a context menu, but I am missing the link to other mouse actions, like double-click.
I recognize that `PopupHandler.installPopupMenu` simply registers a `MouseListener` and that displays a menu with an `ActionGroup`.
I want to learn how to reuse that `ActionGroup` to display one of those actions when double-clicking, in another `MouseListener`.
Are there any examples of a `Tree` that is not file based?
I'd like to better understand how the `PopupHandler` processes each Action in the group to decide what is enabled or not at any time, the popup menu is shown.
and do the same thing on double-click.
Then be able to select one of the `AnAction` that is enabled, and if possible, also assigned to the `VK_ENTER` key.
My other option is to simply hardcode which `AnAction` I want in the double-click `MouseListener`, new that up and call `update` and `actionPerformed` on it manually. But not sure how to do that myself?
Can you help me with that?
Yann Cebron
A little further investigation (into PopupMenuHandler) yielded this approach.
Does it look like a reasonable approach?