public static @Nullable ProcessCloseConfirmation show(Project project,
                                                        @NotNull String sessionName,
                                                        @NotNull ProcessHandler processHandler) {
    //noinspection deprecation
    if (processHandler.isSilentlyDestroyOnClose() ||
        Boolean.TRUE.equals(processHandler.getUserData(ProcessHandler.SILENTLY_DESTROY_ON_CLOSE))) {
      return ProcessCloseConfirmation.TERMINATE;
    }

    boolean canDisconnect =
      !Boolean.TRUE.equals(processHandler.getUserData(RunContentManagerImpl.ALWAYS_USE_DEFAULT_STOPPING_BEHAVIOUR_KEY));
    ProcessCloseConfirmation confirmation = GeneralSettings.getInstance().getProcessCloseConfirmation();
    if (confirmation != ProcessCloseConfirmation.ASK) {
      if (confirmation == ProcessCloseConfirmation.DISCONNECT && !canDisconnect) {
        confirmation = ProcessCloseConfirmation.TERMINATE;
      }
      return confirmation;
    }

    List<String> options = new ArrayList<>(3);
    options.add(ExecutionBundle.message("button.terminate"));
    if (canDisconnect) {
      options.add(ExecutionBundle.message("button.disconnect"));
    }
    options.add(CommonBundle.getCancelButtonText());
    DialogWrapper.DoNotAskOption.Adapter doNotAskOption = new DialogWrapper.DoNotAskOption.Adapter() {
      @Override
      public void rememberChoice(boolean isSelected, int exitCode) {
        if (isSelected) {
          ProcessCloseConfirmation confirmation = getConfirmation(exitCode, canDisconnect);
          if (confirmation != null) {
            GeneralSettings.getInstance().setProcessCloseConfirmation(confirmation);
          }
        }
      }
    };

    AtomicBoolean alreadyGone = new AtomicBoolean(false);
    Runnable dialogRemover = Messages.createMessageDialogRemover(project);
    ProcessAdapter listener = new ProcessAdapter() {
      @Override
      public void processWillTerminate(@NotNull ProcessEvent event, boolean willBeDestroyed) {
        alreadyGone.set(true);
        dialogRemover.run();
      }
    };
    processHandler.addProcessListener(listener);

    boolean defaultDisconnect = processHandler.detachIsDefault();
    int exitCode = Messages.showDialog(project,
                                       ExecutionBundle.message("terminate.process.confirmation.text", sessionName),
                                       ExecutionBundle.message("process.is.running.dialog.title", sessionName),
                                       ArrayUtil.toStringArray(options),
                                       canDisconnect && defaultDisconnect ? 1 : 0,
                                       Messages.getWarningIcon(),
                                       doNotAskOption);
    processHandler.removeProcessListener(listener);
    if (alreadyGone.get()) {
      return ProcessCloseConfirmation.DISCONNECT;
    }

    return getConfirmation(exitCode, canDisconnect);
  }
public static @Nullable ProcessCloseConfirmation show(Project project,
                                                        @NotNull String sessionName,
                                                        @NotNull ProcessHandler processHandler)