void (@NotNull Project project, @NotNull Editor editor, List<? extends TargetDirectory> directories) { List<TargetDirectoryListItem> items = getTargetDirectoryListItems(directories); String filePath = myNewFileName; if (mySubPath.length > 0) { filePath = toSystemDependentName( StringUtil.join(mySubPath, VFS_SEPARATOR) + VFS_SEPARATOR_CHAR + myNewFileName ); } SimpleListCellRenderer<TargetDirectoryListItem> renderer = SimpleListCellRenderer.create((label, value, index) -> { label.setIcon(value.getIcon()); label.setText(value.getPresentablePath()); }); JBPopupFactory.getInstance() .createPopupChooserBuilder(items) .setSelectionMode(ListSelectionModel.SINGLE_SELECTION) .setTitle(CodeInsightBundle.message(myKey, filePath)) .setMovable(false) .setResizable(false) .setRequestFocus(true) .setRenderer(renderer) .setNamerForFiltering(item -> item.getPresentablePath()) .setItemChosenCallback(chosenValue -> { WriteCommandAction.writeCommandAction(project) .withName(CodeInsightBundle.message(myKey, myNewFileName)) .run(() -> apply(project, chosenValue.getTarget(), editor)); }) .addListener(new JBPopupListener() { @Override public void onClosed(@NotNull LightweightWindowEvent event) { // rerun code-insight after popup close PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file != null) { DaemonCodeAnalyzer.getInstance(project).restart(file); } } }) .createPopup() .showInBestPositionFor(editor); }