How can I customize the context/menu bar programmatically?


I need to remove some actions from menu bar programmatically.

I  know that it's possible to do this though Settings > Appearance & Behavior > Menus and Toolbars, but I'm trying to build an plugin that customize the actions and show by default the actions that I need.

I can remove the tools:

//  get tool window manager 
final ToolWindowManager manager = ToolWindowManager.getInstance(project);
// iterate all tools windows by id 
for (final String id : manager.getToolWindowIds()) {
// get tool window 
final ToolWindow toolWindow = manager.getToolWindow(id);
// hide tool window 
toolWindow.setAvailable(false, null);


Using  the ActionManager class I can get all the actions available:

final ActionManager actionManager = ActionManagerImpl.getInstance();
String[] actionIds = actionManager.getActionIds("");

Now I need to know how can I remove some of them.


Thank you,

Eduardo Costa

Comment actions Permalink
Official comment

You can get the corresponding menu action group from ActionManager and invoke DefaultActionGroup.remove(action) on it.

Comment actions Permalink

I tried the code bellow (to remove help menu for example) and works:

ActionManager actionManager = ActionManager.getInstance();
DefaultActionGroup actionGroup = (DefaultActionGroup) actionManager.getAction(IdeActions.GROUP_MAIN_MENU);

// iterate all main menu children's
for (AnAction childGroupAction : actionGroup.getChildActionsOrStubs()) {
if (actionManager.getId(childGroupAction) != null && actionManager.getId(childGroupAction).equals("HelpMenu")) {

Thank you Peter by your reply.

Best regards,

Eduardo Costa


Please sign in to leave a comment.