How to implement ToggleAction to the toolbar?
Answered
I am writing a plugin with the tool window and I want to add a ToggleAction for "GroupBy" action. Write now I wrote a class that extending the AnAction class and overriding the actionPerformed method which does the GroupBy functionality.

But, I want to implement ToggleAction since I want to add "Selected sign (V)" once perform the action as below,

Please find the attached code herewith,
public class GroupByActionCommits extends com.intellij.openapi.actionSystem.AnAction {
@Override
public void actionPerformed(@org.jetbrains.annotations.NotNull com.intellij.openapi.actionSystem.AnActionEvent event) {
....
}
}
Plugin.xml
<group id="GroupByActionCommits" text="Group By" popup="true" icon="/actions/groupBy.png">
<separator text="Group By"/>
<action class="action.GroupByActionCommits" id="GroupByAction.Commits"
text="Commits" description="Group By Commits">
</action>
<action class="action.GroupByActionFiles" id="GroupByAction.Files"
text="Files" description="Group By Files" >
</action>
<add-to-group group-id="PluginActions" anchor="after" relative-to-action="PluginCollapseAllAction"/>
</group>
Please sign in to leave a comment.
Hello Shashi,
Have you tried extending your actions with the ToggleAction?
Jakub Chrzanowski Yeah I want to use ToggleAction but having some problem while overriding the methods. litter bit confuse about this.
Check the existing implementation, like MyShowPackagesAction
Thank you! I have fixed the issues.