cunla
(Daniel Moran)
November 17, 2025, 2:05pm
1
How can I set a keyboard shortcut for Activating toolwindow action?
I can’t write the action on plugin.xml and I do not want it hard-coded like this:
val shortcutUsed = keymap.getShortcuts(ACTIVATE_TOOL_WINDOW_ACTION_ID).any { it == DEFAULT_TOOLWINDOW_SHORTCUT }
if (!shortcutUsed) {
keymap.addShortcut(ACTIVATE_TOOL_WINDOW_ACTION_ID, DEFAULT_TOOLWINDOW_SHORTCUT)
}
Hi,
it is customary that only built-in tool windows have keyboard shortcuts: generally Cmd/Alt+.
Can you elaborate on the “I can’t write the action on plugin.xml bit”?
gerryhjs
(Gerry)
November 20, 2025, 12:23pm
3
Maybe you could use a “keymaps” entry in your plugin or even create a related independent keymap plugin.
cunla
(Daniel Moran)
November 20, 2025, 1:44pm
4
I can’t write
<action id="ActivateXXXToolWindow">
<keyboard-shortcut ...
</action>
because it is missing the class attribute. I can’t use <reference ref=... because it does not take <keyboard-shortcut.
Also, semi-related, <group id=.. class=...> does not take <keyboard-shortcut subelement and it should.
cunla
(Daniel Moran)
November 20, 2025, 1:45pm
5
Can you provide an example? where should the keymaps entry be?
gerryhjs
(Gerry)
November 20, 2025, 1:58pm
6
cunla
(Daniel Moran)
November 20, 2025, 2:10pm
7
But why should it be a separate plugin for having 2-3 shortcuts for my plugin..
I just would like a default shortcut for a few actions.
gerryhjs
(Gerry)
November 20, 2025, 2:12pm
8
It could also implement entry in your plugin.xml like this.
<extensions defaultExtensionNs="com.intellij">
<bundledKeymap file="(your keymap).xml"/>
</extensions>
cunla
(Daniel Moran)
November 20, 2025, 2:24pm
9
I tried that, but it does not “pick it up”.
Do you have an example how to use bundledKeymap?
gerryhjs
(Gerry)
November 20, 2025, 11:40pm
10
What do you means of “pick it up”? Can you see your keymap in IDE setting.
As a somewhat unorthodox approach, you can inherit from AnAction and activate the tool window programatically in actionPerformed(). Then, a keyboard shortcut can be assigned in the plugin.xml to this action.
In your plugin.xml, add the following to the <actions>…</actions> section:
<action
id="OpenYourToolWindowActionId"
class="OpenYourToolWindowAction"
text="Open Your Tool Window"
description="Opens your tool window"
icon="yourToolWindow.svg">
<keyboard-shortcut
first-keystroke="desired keystroke"
keymap="$default"/>
</action>
Then implement OpenYourToolWindowAction as:
public class OpenYourToolWindowAction extends AnAction {
@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getProject();
if (project != null) {
ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(YourToolWindow.ID);
if (toolWindow != null) {
ContentManager contentManager = toolWindow.getContentManager();
Content content = contentManager.getSelectedContent();
if (content != null) {
toolWindow.show();
}
}
}
}
}
That may not be 100% perfect, but it should get you very close.
1 Like