[Action, Shortcut] How to force IDE to use action shortcut?

Hi all,

I am trying to find how I can force IDE to execute my action when action shortcut is invoked. 
Usually this is not an issue, unless actions shortcut overlaps with any existing IDE shortcut.

In my case I would like to execute action on `ctrl enter`. However in IDE for this shortcut is bind "split line" action.

Let's take this action definition as an example.
```
<actions>
  <action id="MyPlugin.EditorAction" class="my.plugin.EditorAction" text="Make action in editor!">
    <keyboard-shortcut first-keystroke="ctrl enter" keymap="$default"/>
  </action>
</actions>
```

When I explore how this action is shown in IDE - it correctly says that shortcut is `ctrl enter`.
But when I actually try to execute this shortcut - it splits lines, instead of executing my action.

0
3 comments

The issue is that there are multiple actions with the same shortcut available in given context. In this case we don't know which one to execute, and pick the first one.

You can use com.intellij.openapi.actionSystem.ActionPromoter to prioritise your action over the others.

But, please, think twice before stealing a such common shortcut.

0

Thanks, @Alexey - I will try your solution.

I am creating a plugin which will allow the user to execute queries in the database (similar to what Database support plugin is doing).
In this case, users are expecting that queries can be invoked via "ctrl-enter" shortcut, while the cursor is placed in the file.

So, in theory, I want this shortcut to be active only in editor context.

0

Thanks @Aleksey!

ActionPromoter works perfectly and was exactly what I looking for.

0

Please sign in to leave a comment.