How to prevent a ListPopup from dismissing automatically after it is clicked?

Answered

I have created an ActionGroup which is bound to an ActionButton, and this group maintains three ToggleActions.

When I click the ActionButton, a popup appears that lists my three ToggleActions in a List format.

However, when I tap one of the options, the popup disappears. I haven't found a method within the ListPopup to keep the popup visible. How can I prevent the popup from dismissing after tapping an option?

 

Here is my source code:

 

ActionButton:

OptionsPopupGroup group = new OptionsPopupGroup();
return new ActionButton(group, group.getTemplatePresentation().clone(), ActionPlaces.POPUP, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE);

 

OptionsPopupGroup (ActionGroup):

public class OptionsPopupGroup extends DefaultActionGroup {

    public OptionsPopupGroup() {
        super(JsonAssistantBundle.messageOnSystem("dialog.deserialize.options.text"), true);
        setEnabledInModalContext(true);
        Presentation presentation = getTemplatePresentation();
        presentation.setIcon(AllIcons.General.Settings);
    }
    
    @Override
    public AnAction @NotNull [] getChildren(@Nullable AnActionEvent e) {
        List<AnAction> actions = new ArrayList<>();
        actions.add(new FastJsonToggleAction());
        actions.add(new JacksonToggleAction());
        actions.add(new KeepCamelToggleAction());
        return actions.toArray(new AnAction[0]);
    }
}

 

0
3 comments

Hi,

Try using com.intellij.openapi.actionSystem.KeepPopupOnPerform.

0

Hi, I have noticed that in the platform version used by the plugin (IDEA 2022.1.4), there is no KeepPopupOnPerform class, but I found the com.intellij.ui.popup.KeepingPopupOpenAction interface. 

Now, there is a confusing issue: all three of my ToggleActions implement the KeepingPopupOpenAction interface, and indeed, clicking on items in the popup does not cause the popup to close. However, after clicking on an item, I have observed that the icon of the item does not change. 

Normally, when I click on an item, it should toggle between selected and unselected states. I found that the ToggleAction.setSelected() method is being triggered upon clicking, but the icon does not update accordingly.

 

0

Hi,

I suggest reporting this at https://youtrack.jetbrains.com/issues/IJPL (please include a minimal example project to reproduce it).

0

Please sign in to leave a comment.