void (DataContext dataContext) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) return; PsiDirectory psiDirectory = null; PsiElement psiElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext); if (psiElement instanceof PsiDirectory) { psiDirectory = (PsiDirectory)psiElement; } PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataContext); String shortFileName = null; String directoryName = null; if (psiFile != null || psiDirectory != null) { if (psiFile != null) { shortFileName = psiFile.getName(); if (psiDirectory == null) { psiDirectory = psiFile.getContainingDirectory(); } } if (psiDirectory != null) { directoryName = psiDirectory.getVirtualFile().getPresentableUrl(); } } Editor editor = CommonDataKeys.EDITOR.getData(dataContext); String text = null; if (editor != null) { if (editor.getSelectionModel().hasSelection()) { text = EditorBundle.message("print.selected.text.radio"); } else { text = psiFile == null ? "Console text" : null; } } List<PsiFile> psiFiles = getSelectedPsiFiles(dataContext); PrintDialog printDialog = new PrintDialog(shortFileName, directoryName, text, psiFiles.size(), project); printDialog.reset(); if (!printDialog.showAndGet()) { return; } printDialog.apply(); final PageFormat pageFormat = createPageFormat(); final BasePainter painter; PrintSettings printSettings = PrintSettings.getInstance(); if (printSettings.getPrintScope() == PrintSettings.PRINT_FILE && psiFiles.size() > 1) { painter = new MultiFilePainter(psiFiles, printSettings.EVEN_NUMBER_OF_PAGES); } else if (printSettings.getPrintScope() == PrintSettings.PRINT_DIRECTORY) { List<PsiFile> filesList = new ArrayList<>(); boolean isRecursive = printSettings.isIncludeSubdirectories(); addToPsiFileList(Objects.requireNonNull(psiDirectory), filesList, isRecursive); painter = new MultiFilePainter(filesList, printSettings.EVEN_NUMBER_OF_PAGES); } else { if (psiFile == null && editor == null) return; TextPainter textPainter; if (psiFile != null) { textPainter = initTextPainter(psiFile); } else { textPainter = initTextPainter((DocumentEx)editor.getDocument(), project, generateFileName(dataContext)); } if (textPainter == null) return; if (printSettings.getPrintScope() == PrintSettings.PRINT_SELECTED_TEXT && editor != null && editor.getSelectionModel().hasSelection()) { textPainter.setSegment(editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd()); } painter = textPainter; } executePrintInner(project, pageFormat, painter); }