void (@Nullable VirtualFile toSelect, @NotNull Consumer<? super List<VirtualFile>> callback) { if (toSelect != null && toSelect.getParent() != null) { String directoryName; String fileName = null; if (toSelect.isDirectory()) { directoryName = toSelect.getCanonicalPath(); } else { directoryName = toSelect.getParent().getCanonicalPath(); fileName = toSelect.getPath(); } myFileDialog.setDirectory(directoryName); myFileDialog.setFile(fileName); } myFileDialog.setFilenameFilter(FileChooser.safeInvokeFilter((dir, name) -> { return myFileChooserDescriptor.isFileSelectable(PathChooserDialogHelper.Companion.fileToCoreLocalVirtualFile(dir, name)); }, false)); myFileDialog.setMultipleMode(myFileChooserDescriptor.isChooseMultiple()); final CommandProcessorEx commandProcessor = ApplicationManager.getApplication() != null ? (CommandProcessorEx)CommandProcessor.getInstance() : null; final boolean appStarted = commandProcessor != null; if (appStarted) { commandProcessor.enterModal(); LaterInvocator.enterModal(myFileDialog); } Component parent = myParent.get(); Component previousFocusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); try { try (AccessToken ignored = ThreadContext.resetThreadContext()) { myFileDialog.setVisible(true); } } finally { if (appStarted) { commandProcessor.leaveModal(); LaterInvocator.leaveModal(myFileDialog); if (previousFocusOwner != null) { IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> previousFocusOwner.requestFocus()); } } } File[] files = myFileDialog.getFiles(); List<VirtualFile> virtualFileList = myHelper.getChosenFiles(files); virtualFiles = virtualFileList.toArray(VirtualFile.EMPTY_ARRAY); if (!virtualFileList.isEmpty()) { try { if (virtualFileList.size() == 1) { myFileChooserDescriptor.isFileSelectable(virtualFileList.get(0)); } myFileChooserDescriptor.validateSelectedFiles(virtualFiles); } catch (Exception e) { if (parent == null) { Messages.showErrorDialog(myProject, e.getMessage(), myTitle); } else { Messages.showErrorDialog(parent, e.getMessage(), myTitle); } return; } if (!ArrayUtil.isEmpty(files)) { callback.consume(virtualFileList); return; } } if (callback instanceof FileChooser.FileChooserConsumer) { ((FileChooser.FileChooserConsumer)callback).cancelled(); } }