Create two plugins with actions in same (custom) group
已回答
I'm trying to build two different IntelliJ plugins, but I'm having trouble with the menu structure.
I want to create them both in the same "menu", but it is a custom menu, so it may not exist as neither plugin depends on the other.
Is there a convention for this? If I use the same `<group id ...>` tag I end up with an error when the second plugin loads, about "action ... already registered".
请先登录再写评论。
Could you explain your use-case, maybe there is a different approach.
There's no good location for them in the default IDE (I can't attach items directly to the 'Git' options), so the best, secondary option is to put them in my own (custom) menu somewhere.
What do you mean with "Git options"? Screenshot, please?
Here is where I'd like one of them, ideally. The other still doesn't really have a "place" but it could go in the "Tools" area I suppose.
You should be able to attach it to "Git" group with group ID "Git.Menu".
Ok, that seems to do it for the one plugin.
Is there a way I could add two plugins to a single custom menu option, or am I SOL on that one?
My only thought for a workaround (that I refuse to do because it's substantially ugly) is to create a third plugin that has the custom menu groups, and then have each plugin that needs an item in that group depend on the third plugin. (Not even sure if that would work, to be completely honest.)
Probably, you can create this group in runtime via `com.intellij.openapi.actionSystem.ActionManager`:
This code makes some assumptions, that in theory might be broken in the future (ex: if "Git.Menu" for some reason will be implemented by custom ActionGroup), but should work.
On second thought, it can be implemented better:
So both actions will belong to the same "group1" if both installed ("group2" in this case will be empty and not visible).
Or to their "own" group if only one plugin is installed.
Curious, I'll have to experiment with that and see if I can make it work. That would probably be IDEAl (pun intended).