Adding PopupMenu to ActionBarButton

I would like to add a PopupMenu to a button in the action bar of my tool window. When the user clicks the button, the list will apear and they can then select the options that they want to filter to list in the window. Something similar to the Add Button from the Database Tool Window in Intellij Ultimate.

I tried configuring this in the plugin.xml fiile but I do not know which group I should add it too.

<action id="assist.actions.FilterListAction"
class="assist.actions.FilterListAction"
text="Filter">
</action>

<group id="FilterGroup" text="Options" popup="true">
<add-to-group group-id="PopupMenu" anchor="first"/>
</group>

I also tried creating an action group and and adding to the popup menu but I was not successful.

DefaultActionGroup actionGroup = new DefaultActionGroup();
actionGroup.add(new LoadFileAction());
actionGroup.add(new Separator());

ActionPopupMenu actionPopupMenu = ActionManager.getInstance().createActionPopupMenu("Filter",actionGroup);

Any help or links to online resources would be appreaciated.

 

0
4 comments
Avatar
Permanently deleted user

FilterListAction should extends ActionGroup, so popup menu will be built&shown automatically when user clicks on a corresponding button. The question is your implementation of ActionGroup.getChildren().

1

Thanks for responding Vassily. I was able to add the actions to the FilterListAction class by extending ActionGroup.

 

public class FilterActionGroup extends ActionGroup {
@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent anActionEvent) {
return new AnAction[]{new MyAction("All"), new MyAction("Current Class")};
}

class MyAction extends AnAction {
public MyAction(String name) {
super(name);
}

@Override
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
}
}
}

What I want to do is to have a button on the ToolWindow ActionBar and when the user presses this button, the FilterListAction popup menu should appear. Do you have any ideas of how I can do this?

 

0
Avatar
Permanently deleted user

In FilterActionGroup you should override isPopup():

 @Override
    public boolean isPopup() {
      return true;
    }

Then you should add this group in toolbar and it will look like single button (with small arrow marker) and it will show children as popup list on mouse click.

1

Thanks it works!

0

Please sign in to leave a comment.