Question
Already can open the IDE's keymap page by using the code below:
ShowSettingsUtil.getInstance().showSettingsDialog(e.getProject(), KeymapPanel.class);
If want to select an action(e.g., a plugin's action) automatically, is there any good way?
Answer
Try this code. Remember to change IdeActions.ACTION_EXPAND_LIVE_TEMPLATE_CUSTOM to your action ID:
// Some Action Class
public void actionPerformed(AnActionEvent e) {
Settings allSettings = Settings.KEY.getData(e.getDataContext());
final KeymapPanel keymapPanel = allSettings == null ? new KeymapPanel() : allSettings.find(KeymapPanel.class);
if (keymapPanel == null) return;
Runnable selectAction = () -> keymapPanel.selectAction(IdeActions.ACTION_EXPAND_LIVE_TEMPLATE_CUSTOM);
if (allSettings != null) {
allSettings.select(keymapPanel).doWhenDone(selectAction);
}
else {
ShowSettingsUtil.getInstance().editConfigurable(e.getProject(), keymapPanel, selectAction);
}
}
If you are trying to trigger this action in another Settings page component which is already displayed, change the way to get DataContext:
Settings allSettings = Settings.KEY.getData(DataManager.getInstance().getDataContext(somePreferencesJComponent));
The final effect:
Comments
0 comments
Please sign in to leave a comment.