Add action to toolbar for all IntelliJ IDEs Follow
I have an action item that I want to include in the main toolbar at the top. (I'm not super familiar with Jetbrains so forgive me for my lack of correct terminology).
I have been able to include the action in the toolbar for IDEA by specifying the `group-id` as `ToolBarRunGroup` (see snippet below). This was fine up until one of our users (who uses Ride) said that the action was not there for them.
<action id="<action ID>"
<add-to-group group-id="ToolBarRunGroup" anchor="first"/>
I installed Ride to try this out and the action is indeed missing, though it can be added via the "Customize Toolbar..." dialogue.
The following image shows the toolbar in Ride where I want the action to show up. Ideally it would be placed to the left of the "Build Solution" icon.
![https://i.stack.imgur.com/WiG7V.png](image of toolbar in Ride)
Ideally, I would like the action to be included in the toolbar for all Jetbrains IDEs. I have tried looking in the "Internal Actions -> UI inspector" to find a common `group-id` but it seems that each IDE uses slightly different ones.
Is there another way I can ensure the action is included in the toolbar for all IDEs?
Please sign in to leave a comment.
If a group differs between IDEs, then I suggest implementing
com.intellij.openapi.actionSystem.impl.ActionConfigurationCustomizerand registering it in the
com.intellij.actionConfigurationCustomizerextension point. In the customizer use
ActionManagerto find the actual group available in a given IDE until it is not null (note that getAction() works for groups as well), e.g.:
Thank you Karol.
This seems like the right approach, however on the `toolbarGroup?.add()` line, I am running into a "Cyclic service initialization" error on startup. I'll reiterate though - I'm not very familiar with Jetbrains (I'm a Junior web dev by trade, typescript is my comfort zone), and in particular I'm very bad at parsing its error messages - so this may be obvious to you. I have narrowed it down to the `toolbar?.add()` line by commenting it out and observing that I no longer get the error. This is how I have written it:
I have tried instantiating my action's class (with and without it being defined in `plugin.xml`) instead of using `actionManager.getAction()`. I have tried switching out my action's ID with another action that I know has no issues with its internals (the "Run" action). I've tried removing the `Constraints.FIRST` parameter. And after all this, the error persists.
I'm stumped here, and unfortunately there is nobody in my company with more experience for me to turn to anymore (thanks tech layoffs). Could you please help me out?
Please use the following method to add the action:
So it is important to pass the current actionManager.
The error reason is that without passing actionManager to add() method, the platform tries to retrieve the ActionManager from the component registry. The problem is that customize() is invoked during ActionManager creation (in its constructor), so it caused cyclic service initialization.
I didn't notice it before. We will add Javadoc to clarify it.
This solved the issue, thank you again.