ListPopup disappears immediately when used after popup

Answered

Hello!

I'm just starting out with JetBrains plugin development, so please forgive me if I'm doing something wrong here. Basically what I want to do is have a menu item that first pops up an input box, and then based on what the user enters in the input box, pops up a list of potential options. As a first start, I've created the following minimal modification to the HelloAction.java file:

https://gist.github.com/neubig/45c6c382110714aef0f4b1834991fbf2

When run as-is, this works: it pops up a list of choices, and if you select one it prints out the selection to the console.

However, if you uncomment the "showMessageDialog" call, it then shows a message dialog, but then when it moves on to showing the selection menu, the menu appears for one instant, but then quickly disappears. This doesn't seem like expected behavior, but I'm not sure if I'm doing something wrong, or if this is a bug. Could someone provide guidance?

Thanks a lot!

6 comments
Avatar
Vassiliy Kudryashov
Comment actions Permalink

Hi! The problem here is in focus transfer after dialog closing: ListPopup appears and immediately lost focus that goes to main window (and it triggers popup closing). So showing popup after modal dialog is just bad pattern and misbehaving (on native level) is possible depending on OS, Java version etc.

Use single popup or popup-after-popup instead.

0
Comment actions Permalink

Thanks a lot for the quick reply!

I think the popup-after-popup pattern would probably solve my problem, but I'm not sure how to get a popup that does what I want to do. To demonstrate what I want to do a little bit more I modified the gist, still using a modal dialog:

https://gist.github.com/neubig/45c6c382110714aef0f4b1834991fbf2

Basically, what it does is it opens a dialog using "Messages.showInputDialog()", gets the input, and then uses the input in the "createListPopup()" call. I think what I need to do is create a Popup that allows the user to do text entry, but I'm not sure how to do so. Would you be able to give me any pointers towards an example of how to use a popup for text entry?

Thanks a lot in advance!

0
Comment actions Permalink

You can create a non-modal popup via com.intellij.openapi.ui.popup.JBPopupFactory#createComponentPopupBuilder

0
Comment actions Permalink

Thanks for the pointer! But I'm sorry, I'm still confused about how to get createComponentPopupBuilder to act similarly to a modal InputDialog. I've created a simple input panel "TextInputForm" with the IntelliJ GUI editor, and called it using the following code:

TextInputForm form = new TextInputForm();
JBPopupFactory jbPopupFactory = JBPopupFactory.getInstance();
ComponentPopupBuilder popupBuilder = jbPopupFactory.createComponentPopupBuilder(form.rootPanel, null);
popupBuilder.createPopup().show(jbPopupFactory.guessBestPopupLocation(editor));

This displays the form as a popup, but it's not possible to select the JTextField or JButton objects that I've added to the GUI. Are there any examples of using createComponentPopupBuilder for something like text entry? If so, it'd be great if I could see any reference code to work off of.

0
Avatar
Vassiliy Kudryashov
Comment actions Permalink

Please try

popupBuilder.setRequestFocus(true).setFocusable(true).createPopup()...
0
Comment actions Permalink

Thanks a lot! setRequestFocus() and an actionlistener on the included components to call the next createPopupList call did the trick.

0

Please sign in to leave a comment.