About actiongroup add/delete!

Can i add or delete an new actiongroup without defined in the pluin.xml?
Or after i have defined an actiongroup in menu bar, can i remove it by code?

Comment actions Permalink

Yes. You can get a handle to the menu bar:

You can also create your own DefaultActionGroup and it to the menu by invoking its add method:

You can add individual actions to your action group.

These are subclasses of AnAction (Which DefaultActionGroup is also a subclass of). These require you to implement the method actionPerformed to handle what the action is supposed to do. There are some other options you can pass to Constraints. Just examine the class.

You can modify how the action is displayed (its text, description, etc.) by using the result of the method getTemplatePresentation.

Finally, you can register your own keystrokes to your actions but to do so requires use of some obfuscated code. (Thanks to Dmitry Skavish)

Comment actions Permalink

I was copying from some of my code. "this.keystroke" is supposed to be a value like "control shift S". In other words: one or more of "control", "shift", "alt" separated by spaces followed by a CAPITAL letter or a character.

Comment actions Permalink

I have do some code, but not work,why?

DefaultActionGroup mainMenu = (DefaultActionGroup) ActionManager.getInstance().getAction("MainMenu");
DefaultActionGroup myActionGroup = new DefaultActionGroup("MyMenu", true);
ActionManager.getInstance().registerAction("MyMenuID", myActionGroup);

AnAction action= new GarbageCollectionAction();

myActionGroup.add(action, new Constraints(Anchor.LAST, "after"));
ActionManager.getInstance().registerAction("actionID", action);

Comment actions Permalink

Well, what part doesn't work? Does the menu appear, but not the action? Does the menu not even appear? And, of course, are you 100% sure your code is being run? And also, having not tried that constructor of DefaultActionGroup, I cannot vouch for its expected result.


Please sign in to leave a comment.