This is a plugin so Java actions are available too.
I would like to hide the "New -> Package" action in the context menu depending upon where I right clicked in the project structure.
I need to add this action because I need to use a different handler rather than CreateDirectoryOrPackageHandler.java
<action id="MyNewDir" class="com.my.ij.actions.MyCreateDirectoryOrPackageAction">
<add-to-group group-id="NewGroup" anchor="after" relative-to-action="NewFile"/>
Since this action is not overridable, I cannot add this with id="NewDir" as that id already exists.
Now both the Java and my "New -> Package" option is available in the context menu.
To hide the Java option, I am (on some condition) trying to hide the action in this way -
AnAction javaPackageAction = ActionManager.getInstance().getAction("NewDir");
Presentation javaPresentation = javaPackageAction.getTemplatePresentation();
But it is not working. The option is still there. I see 2 options for "packages"
I know it may not be the ideal way. But is there another way? Should the above code work? If yes, what am I missing here?
I have used the similar approach to hide the "Generated Constructor" option for Java in my custom language (My custome language extends Java so it is depenedent