A set of ToggleAction menu items that only one can be in the selected state

Hi. I'm trying to add a set of context menu items that can be checked and unchecked, like this:

But I want them to act like a set of radio buttons, that only one can be checked at a time with the rest to be unchecked. Will ToggleAction work for this purpose?

 

0

Yes, you can store option state somewhere (ex: in PersistentStateComponent) and access it from multiple actions (only one of which would return `isSelected == true`).

As an example, you can look at AnAction in editor gutter menu, that allows to toggle "Breadcrumbs" position.
https://github.com/JetBrains/intellij-community/blob/master/xml/impl/src/com/intellij/xml/breadcrumbs/ToggleBreadcrumbsSettingsAction.java

 

 

0
Avatar
Permanently deleted user

Thank you. It worked.

0

请先登录再写评论。