void (CompletionResult result, boolean isExplicit, boolean showAdText) { if (myList == null) { myList = new JBList<>(); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myList.setCellRenderer(new GroupedItemsListRenderer<>(new ListItemDescriptorAdapter<>() { @Override public String getTextFor(LookupFile file) { return FileTextFieldUtil.getLookupString(file, myFinder, myCurrentCompletion); } @Override public Icon getIconFor(LookupFile value) { return value.getIcon(); } private @NlsContexts.Separator @Nullable String getSeparatorAboveOf(LookupFile file) { if (myCurrentCompletion == null) return null; int fileIndex = myCurrentCompletion.variants.indexOf(file); if (fileIndex > 0 && !myCurrentCompletion.macros.contains(file)) { LookupFile prev = myCurrentCompletion.variants.get(fileIndex - 1); if (myCurrentCompletion.macros.contains(prev)) { return ""; } } if (myCurrentCompletion.kidsAfterSeparator.indexOf(file) == 0 && !myCurrentCompletion.siblings.isEmpty()) { LookupFile parent = file.getParent(); return parent != null ? parent.getName() : ""; } if (!myCurrentCompletion.macros.isEmpty() && fileIndex == 0) { return getPathVariablesSeparatorText(); } return null; } @Override public boolean hasSeparatorAboveOf(LookupFile value) { return getSeparatorAboveOf(value) != null; } @Override public String getCaptionAboveOf(LookupFile value) { return getSeparatorAboveOf(value); } })); } if (myCurrentPopup != null) { closePopup(); } myCurrentCompletion = result; if (result.variants.isEmpty()) { showNoSuggestions(isExplicit); return; } myList.setModel(new AbstractListModel<>() { @Override public int getSize() { return myCurrentCompletion.variants.size(); } @Override public LookupFile getElementAt(int index) { return myCurrentCompletion.variants.get(index); } }); myList.getSelectionModel().clearSelection(); String adText = null; if (showAdText) { String strokeText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction("EditorChooseLookupItemReplace")); adText = IdeBundle.message("file.chooser.completion.ad.text", strokeText); } //noinspection DuplicatedCode myCurrentPopup = new PopupChooserBuilder<>(myList) .addListener(new JBPopupListener() { @Override public void beforeShown(@NotNull LightweightWindowEvent event) { myPathTextField.registerKeyboardAction(myCancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); for (Action each : myDisabledTextActions) { each.setEnabled(false); } } @Override public void onClosed(@NotNull LightweightWindowEvent event) { myPathTextField.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); for (Action each : myDisabledTextActions) { each.setEnabled(true); } } }) .setRequestFocus(false) .setAdText(adText) .setAutoSelectIfEmpty(false) .setResizable(false) .setCancelCallback(() -> { int caret = myPathTextField.getCaretPosition(); myPathTextField.setSelectionStart(caret); myPathTextField.setSelectionEnd(caret); myPathTextField.setFocusTraversalKeysEnabled(true); IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(getField(), true)); return Boolean.TRUE; }) .setItemChosenCallback(() -> processChosenFromCompletion(false)) .setCancelKeyEnabled(false) .setAlpha(0.1f) .setFocusOwners(new Component[]{myPathTextField}) .createPopup(); if (result.preselected != null) { myList.setSelectedValue(result.preselected, false); } myPathTextField.setFocusTraversalKeysEnabled(false); myCurrentPopup.showInScreenCoordinates(getField(), getLocationForCaret(myPathTextField)); }