void executeExport(@NotNull DataContext dataContext) throws NoSuchFileException {
    PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataContext);
    PsiDirectory psiDirectory = null;
    if (psiFile != null) {
      psiDirectory = psiFile.getContainingDirectory();
    }
    else {
      PsiElement psiElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
      if (psiElement instanceof PsiDirectory) {
        psiDirectory = (PsiDirectory)psiElement;
      }
    }

    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    Project project = psiDirectory != null ? psiDirectory.getProject() : editor != null ? editor.getProject()
                                                                                        : CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) return;

    String shortFileName = null;
    String directoryName = null;
    if (psiFile != null || psiDirectory != null) {
      if (psiFile != null) {
        shortFileName = psiFile.getVirtualFile().getName();
        if (psiDirectory == null) {
          psiDirectory = psiFile.getContainingDirectory();
        }
      }
      if (psiDirectory != null) {
        directoryName = psiDirectory.getVirtualFile().getPresentableUrl();
      }
    }

    final boolean isSelectedTextEnabled = editor != null && editor.getSelectionModel().hasSelection();

    ExportToHTMLDialog exportToHTMLDialog = new ExportToHTMLDialog(shortFileName, directoryName, isSelectedTextEnabled, project);

    ExportToHTMLSettings exportToHTMLSettings = ExportToHTMLSettings.getInstance(project);
    if (exportToHTMLSettings.OUTPUT_DIRECTORY == null) {
      String baseDir = Objects.requireNonNull(project).getBasePath();
      if (baseDir != null) {
        exportToHTMLSettings.OUTPUT_DIRECTORY = baseDir + File.separator + "exportToHTML";
      }
      else {
        exportToHTMLSettings.OUTPUT_DIRECTORY = "";
      }
    }
    exportToHTMLDialog.reset();
    if (!exportToHTMLDialog.showAndGet()) {
      return;
    }

    try {
      exportToHTMLDialog.apply();
    }
    catch (ConfigurationException e) {
      Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle());
    }

    PsiDocumentManager.getInstance(project).commitAllDocuments();
    Path outDir = Paths.get(exportToHTMLSettings.OUTPUT_DIRECTORY);
    try {
      if (exportToHTMLSettings.getPrintScope() == PrintSettings.PRINT_DIRECTORY) {
        myLastException = null;
        Runnable exportRunnable = new ExportRunnable(exportToHTMLSettings, psiDirectory, outDir, project);
        ProgressManager.getInstance().runProcessWithProgressSynchronously(exportRunnable, EditorBundle.message("export.to.html.title"), true, project);
        IOException exception = myLastException;
        if (exception != null) {
          if (exception instanceof NoSuchFileException) {
            throw (NoSuchFileException)exception;
          }
          else {
            LOG.error(exception);
          }
        }
      }
      else {
        if (psiFile == null || psiFile.getText() == null) {
          return;
        }

        boolean hasSelection = editor != null && editor.getSelectionModel().hasSelection();
        int selectionStart;
        int firstLine;
        int selectionEnd;
        if (hasSelection) {
          selectionStart = editor.getSelectionModel().getSelectionStart();
          firstLine = editor.getDocument().getLineNumber(selectionStart);
          selectionEnd = editor.getSelectionModel().getSelectionEnd();
        }
        else {
          selectionStart = firstLine = selectionEnd = 0;
        }
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
          ApplicationManager.getApplication().runReadAction(() -> {
            if (!psiFile.isValid()) {
              return;
            }
            try {
              HTMLTextPainter textPainter = new HTMLTextPainter(psiFile, project, new HtmlStyleManager(false),
                                                                exportToHTMLSettings.PRINT_LINE_NUMBERS, true);
              if (exportToHTMLSettings.getPrintScope() == PrintSettings.PRINT_SELECTED_TEXT && hasSelection) {
                textPainter.setSegment(selectionStart, selectionEnd, firstLine);
              }

              Path htmlFile = doPaint(constructOutputDirectory(psiFile.getContainingDirectory(), outDir), textPainter, null);
              if (exportToHTMLSettings.OPEN_IN_BROWSER) {
                BrowserUtil.browse(htmlFile);
              }
            }
            catch (IOException e) {
              LOG.error(e);
            }
          });
        }, EditorBundle.message("export.to.html.title"), true, project);
      }
    }
    finally {
      VfsUtil.markDirtyAndRefresh(true, true, false, new File(exportToHTMLSettings.OUTPUT_DIRECTORY));
    }
  }
void executeExport(@NotNull DataContext dataContext)