Java Code Examples for com.intellij.openapi.ui.DialogWrapper#DoNotAskOption

The following examples show how to use com.intellij.openapi.ui.DialogWrapper#DoNotAskOption . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JBMacMessages.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public int showYesNoCancelDialog(@Nonnull String title,
                                 String message,
                                 @Nonnull String defaultButton,
                                 String alternateButton,
                                 String otherButton,
                                 @Nullable consulo.ui.Window window,
                                 @Nullable DialogWrapper.DoNotAskOption doNotAskOption) {
  if (window == null) {
    window = getForemostWindow(null);
  }
  SheetMessage sheetMessage = new SheetMessage(window, title, message, UIUtil.getQuestionIcon(),
                                               new String [] {defaultButton, alternateButton, otherButton}, null, defaultButton, alternateButton);
  String resultString = sheetMessage.getResult();
  int result = resultString.equals(defaultButton) ? Messages.YES : resultString.equals(alternateButton) ? Messages.NO : Messages.CANCEL;
  if (doNotAskOption != null) {
    doNotAskOption.setToBeShown(sheetMessage.toBeShown(), result);
  }
  return result;
}
 
Example 2
Source File: JBMacMessages.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public int showYesNoDialog(@Nonnull String title,
                           String message,
                           @Nonnull String yesButton,
                           @Nonnull String noButton,
                           @Nullable consulo.ui.Window window,
                           @Nullable DialogWrapper.DoNotAskOption doNotAskDialogOption) {
  if (window == null) {
    window = getForemostWindow(null);
  }
  SheetMessage sheetMessage = new SheetMessage(window, title, message, UIUtil.getQuestionIcon(),
                                               new String [] {yesButton, noButton}, doNotAskDialogOption, yesButton, noButton);
  int result = sheetMessage.getResult().equals(yesButton) ? Messages.YES : Messages.NO;
  if (doNotAskDialogOption != null) {
    doNotAskDialogOption.setToBeShown(sheetMessage.toBeShown(), result);
  }
  return result;
}
 
Example 3
Source File: MacMessages.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Messages.YesNoCancelResult
public abstract int showYesNoCancelDialog(@Nonnull String title,
                                          String message,
                                          @Nonnull String defaultButton,
                                          String alternateButton,
                                          String otherButton,
                                          @Nullable Window window,
                                          @Nullable DialogWrapper.DoNotAskOption doNotAskOption);
 
Example 4
Source File: SyncDirectoriesWarning.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Warns the user that sources may not resolve. Returns false if sync should be aborted. */
public static boolean warn(Project project) {
  if (warningSuppressed()) {
    return true;
  }
  String buildSystem = Blaze.buildSystemName(project);
  String message =
      String.format(
          "Syncing without a %s build will result in unresolved symbols "
              + "in your source files.<p>This can be useful for quickly adding directories to "
              + "your project, but if you're seeing sources marked as '(unsynced)', run a normal "
              + "%<s sync to fix it.",
          buildSystem);
  String title = String.format("Syncing without a %s build", buildSystem);
  DialogWrapper.DoNotAskOption dontAskAgain =
      new DialogWrapper.DoNotAskOption.Adapter() {
        @Override
        public void rememberChoice(boolean isSelected, int exitCode) {
          if (isSelected) {
            suppressWarning();
          }
        }

        @Override
        public String getDoNotShowMessage() {
          return "Don't warn again";
        }
      };
  int result =
      Messages.showOkCancelDialog(
          project,
          XmlStringUtil.wrapInHtml(message),
          title,
          "Run Sync",
          "Cancel",
          Messages.getWarningIcon(),
          dontAskAgain);
  return result == Messages.OK;
}
 
Example 5
Source File: MacMessages.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return {@link Messages#YES} if user pressed "Yes" or {@link Messages#NO} if user pressed "No" button.
 */
@Messages.YesNoResult
public abstract int showYesNoDialog(@Nonnull String title,
                                    String message,
                                    @Nonnull String yesButton,
                                    @Nonnull String noButton,
                                    @Nullable Window window,
                                    @Nullable DialogWrapper.DoNotAskOption doNotAskDialogOption);
 
Example 6
Source File: ShowFilePathAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Boolean showDialog(Project project, String message, String title, File file) {
  final Boolean[] ref = new Boolean[1];
  final DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() {
    @Override
    public boolean isToBeShown() {
      return true;
    }

    @Override
    public void setToBeShown(boolean value, int exitCode) {
      if (!value) {
        ref[0] = exitCode == 0;
      }
    }

    @Override
    public boolean canBeHidden() {
      return true;
    }

    @Override
    public boolean shouldSaveOptionsOnCancel() {
      return true;
    }

    @Nonnull
    @Override
    public String getDoNotShowMessage() {
      return CommonBundle.message("dialog.options.do.not.ask");
    }
  };
  showDialog(project, message, title, file, option);
  return ref[0];
}
 
Example 7
Source File: ExecutionManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean userApprovesStopForSameTypeConfigurations(Project project, String configName, int instancesCount) {
  RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
  final RunManagerConfig config = runManager.getConfig();
  if (!config.isRestartRequiresConfirmation()) return true;

  DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() {
    @Override
    public boolean isToBeShown() {
      return config.isRestartRequiresConfirmation();
    }

    @Override
    public void setToBeShown(boolean value, int exitCode) {
      config.setRestartRequiresConfirmation(value);
    }

    @Override
    public boolean canBeHidden() {
      return true;
    }

    @Override
    public boolean shouldSaveOptionsOnCancel() {
      return false;
    }

    @Nonnull
    @Override
    public String getDoNotShowMessage() {
      return CommonBundle.message("dialog.options.do.not.show");
    }
  };
  return Messages.showOkCancelDialog(project, ExecutionBundle.message("rerun.singleton.confirmation.message", configName, instancesCount),
                                     ExecutionBundle.message("process.is.running.dialog.title", configName), ExecutionBundle.message("rerun.confirmation.button.text"),
                                     CommonBundle.message("button.cancel"), Messages.getQuestionIcon(), option) == Messages.OK;
}
 
Example 8
Source File: MacMessagesImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Messages.YesNoCancelResult
public int showYesNoCancelDialog(@Nonnull String title,
                                 String message,
                                 @Nonnull String defaultButton,
                                 String alternateButton,
                                 String otherButton, consulo.ui.Window window,
                                 @Nullable DialogWrapper.DoNotAskOption doNotAskOption) {
  return showAlertDialog(title, defaultButton, alternateButton, otherButton, message, window, false, doNotAskOption);
}
 
Example 9
Source File: JBMacMessages.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public int showMessageDialog(@Nonnull String title,
                             String message,
                             @Nonnull String[] buttons,
                             boolean errorStyle,
                             @Nullable consulo.ui.Window window,
                             int defaultOptionIndex,
                             int focusedOptionIndex,
                             @Nullable DialogWrapper.DoNotAskOption doNotAskDialogOption) {
  if (window == null) {
    window = getForemostWindow(null);
  }

  Icon icon = errorStyle ? UIUtil.getErrorIcon() : UIUtil.getInformationIcon();

  focusedOptionIndex = (defaultOptionIndex == focusedOptionIndex) ? buttons.length - 1 : focusedOptionIndex;

  SheetMessage sheetMessage = new SheetMessage(window, title, message, icon, buttons, doNotAskDialogOption, buttons[defaultOptionIndex],
                                               buttons[focusedOptionIndex]);
  String result = sheetMessage.getResult();
  for (int i = 0; i < buttons.length; i++) {
    if (result.equals(buttons[i])) {
      if (doNotAskDialogOption != null) {
        doNotAskDialogOption.setToBeShown(sheetMessage.toBeShown(), i);
      }
      return i;
    }
  }
  return -1;
}
 
Example 10
Source File: MacMessagesImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public int showMessageDialog(@Nonnull final String title,
                             final String message,
                             @Nonnull final String[] buttons,
                             final boolean errorStyle,
                             @Nullable consulo.ui.Window window,
                             final int defaultOptionIndex,
                             final int focusedOptionIndex,
                             @Nullable final DialogWrapper.DoNotAskOption doNotAskDialogOption) {
  ID pool = invoke(invoke("NSAutoreleasePool", "alloc"), "init");
  try {
    final ID buttonsArray = invoke("NSMutableArray", "array");
    for (String s : buttons) {
      ID s1 = nsString(UIUtil.removeMnemonic(s));
      invoke(buttonsArray, "addObject:", s1);
    }

    Map<Enum, Object> params  = new HashMap<Enum, Object>();

    params.put(COMMON_DIALOG_PARAM_TYPE.title, nsString(title));
    // replace % -> %% to avoid formatted parameters (causes SIGTERM)
    params.put(COMMON_DIALOG_PARAM_TYPE.message, nsString(StringUtil.stripHtml(message == null ? "" : message, true).replace("%", "%%")));

    params.put(COMMON_DIALOG_PARAM_TYPE.errorStyle, nsString(errorStyle ? "error" : "-1"));
    params.put(COMMON_DIALOG_PARAM_TYPE.doNotAskDialogOption1, nsString(doNotAskDialogOption == null || !doNotAskDialogOption.canBeHidden()
                                                                        // TODO: state=!doNotAsk.shouldBeShown()
                                                                        ? "-1"
                                                                        : doNotAskDialogOption.getDoNotShowMessage()));
    params.put(COMMON_DIALOG_PARAM_TYPE.doNotAskDialogOption2, nsString(doNotAskDialogOption != null && !doNotAskDialogOption.isToBeShown() ? "checked" : "-1"));
    params.put(MESSAGE_DIALOG_PARAM_TYPE.defaultOptionIndex, nsString(Integer.toString(defaultOptionIndex)));
    params.put(MESSAGE_DIALOG_PARAM_TYPE.focusedOptionIndex, nsString(Integer.toString(focusedOptionIndex)));
    params.put(MESSAGE_DIALOG_PARAM_TYPE.buttonsArray, buttonsArray);

    MessageResult result = resultsFromDocumentRoot.remove(showDialog(window, "showVariableButtonsSheet:",
                                                                     new DialogParamsWrapper(DialogParamsWrapper.DialogType.message, params)));

    final int code = convertReturnCodeFromNativeMessageDialog(result.myReturnCode);

    final int cancelCode = buttons.length - 1;

    if (doNotAskDialogOption != null && doNotAskDialogOption.canBeHidden()) {
      if (cancelCode != code || doNotAskDialogOption.shouldSaveOptionsOnCancel()) {
        doNotAskDialogOption.setToBeShown(!result.mySuppress, code);
      }
    }

    return code;
  }
  finally {
    invoke(pool, "release");
  }
}
 
Example 11
Source File: MacMessagesImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Messages.YesNoCancelResult
public static int showAlertDialog(@Nonnull String title,
                                  @Nonnull String defaultText,
                                  @Nullable final String alternateText,
                                  @Nullable final String otherText,
                                  final String message,
                                  @Nullable consulo.ui.Window window,
                                  final boolean errorStyle,
                                  @Nullable final DialogWrapper.DoNotAskOption doNotAskDialogOption) {

  Map<Enum, Object> params  = new HashMap<Enum, Object> ();

  ID pool = invoke(invoke("NSAutoreleasePool", "alloc"), "init");
  try {
    params.put(COMMON_DIALOG_PARAM_TYPE.title, nsString(title));
    params.put(ALERT_DIALOG_PARAM_TYPE.defaultText, nsString(UIUtil.removeMnemonic(defaultText)));
    params.put(ALERT_DIALOG_PARAM_TYPE.alternateText, nsString(otherText == null ? "-1" : UIUtil.removeMnemonic(otherText)));
    params.put(ALERT_DIALOG_PARAM_TYPE.otherText, nsString(alternateText == null ? "-1" : UIUtil.removeMnemonic(alternateText)));
    // replace % -> %% to avoid formatted parameters (causes SIGTERM)
    params.put(COMMON_DIALOG_PARAM_TYPE.message, nsString(StringUtil.stripHtml(message == null ? "" : message, true).replace("%", "%%")));
    params.put(COMMON_DIALOG_PARAM_TYPE.errorStyle, nsString(errorStyle ? "error" : "-1"));
    params.put(COMMON_DIALOG_PARAM_TYPE.doNotAskDialogOption1, nsString(doNotAskDialogOption == null || !doNotAskDialogOption.canBeHidden()
                                                                        // TODO: state=!doNotAsk.shouldBeShown()
                                                                        ? "-1"
                                                                        : doNotAskDialogOption.getDoNotShowMessage()));
    params.put(COMMON_DIALOG_PARAM_TYPE.doNotAskDialogOption2, nsString(doNotAskDialogOption != null
                                                                        && !doNotAskDialogOption.isToBeShown() ? "checked" : "-1"));
    MessageResult result = resultsFromDocumentRoot.remove(
            showDialog(window, "showSheet:", new DialogParamsWrapper(DialogParamsWrapper.DialogType.alert, params)));

    int convertedResult = convertReturnCodeFromNativeAlertDialog(result.myReturnCode, alternateText);

    if (doNotAskDialogOption != null && doNotAskDialogOption.canBeHidden()) {
      boolean operationCanceled = convertedResult == Messages.CANCEL;
      if (!operationCanceled || doNotAskDialogOption.shouldSaveOptionsOnCancel()) {
        doNotAskDialogOption.setToBeShown(!result.mySuppress, convertedResult);
      }
    }

    return convertedResult;
  }
  finally {
    invoke(pool, "release");
  }
}
 
Example 12
Source File: MacMessagesImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Messages.YesNoResult
public int showYesNoDialog(@Nonnull String title, String message, @Nonnull String yesButton, @Nonnull String noButton, @Nullable consulo.ui.Window window,
                           @Nullable DialogWrapper.DoNotAskOption doNotAskDialogOption) {
  return showAlertDialog(title, yesButton, null, noButton, message, window, false, doNotAskDialogOption) == Messages.YES ? Messages.YES : Messages.NO;
}
 
Example 13
Source File: SheetController.java    From consulo with Apache License 2.0 4 votes vote down vote up
SheetController(final SheetMessage sheetMessage,
                final String title,
                final String message,
                final Icon icon,
                final String[] buttonTitles,
                final String defaultButtonTitle,
                final DialogWrapper.DoNotAskOption doNotAskOption,
                final String focusedButtonTitle) {
  if (icon != null) {
    myIcon = icon;
  }

  myDoNotAskOption = doNotAskOption;
  myDoNotAskResult = (doNotAskOption != null) && !doNotAskOption.isToBeShown();
  mySheetMessage = sheetMessage;
  buttons = new JButton[buttonTitles.length];

  myResult = null;

  int defaultButtonIndex = -1;
  int focusedButtonIndex = -1;

  for (int i = 0; i < buttons.length; i++) {
    String buttonTitle = buttonTitles[i];

    buttons[i] = new JButton();
    buttons[i].setOpaque(false);
    handleMnemonics(i, buttonTitle);

    if (buttonTitle.equals(defaultButtonTitle)) {
      defaultButtonIndex = i;
    }

    if (buttonTitle.equals(focusedButtonTitle) && !focusedButtonTitle.equals("Cancel")) {
      focusedButtonIndex = i;
    }
  }

  defaultButtonIndex = (focusedButtonIndex == defaultButtonIndex) || defaultButtonTitle == null ? 0 : defaultButtonIndex;

  if (focusedButtonIndex != -1 && defaultButtonIndex != focusedButtonIndex) {
    myFocusedComponent = buttons[focusedButtonIndex];
  } else if (doNotAskOption != null) {
    myFocusedComponent = doNotAskCheckBox;
  } else if (buttons.length > 1) {
    myFocusedComponent = buttons[buttons.length - 1];
  }

  myDefaultButton = (defaultButtonIndex == -1) ? buttons[0] : buttons[defaultButtonIndex];

  if (myResult == null) {
    myResult = Messages.CANCEL_BUTTON;
  }

  mySheetPanel = createSheetPanel(title, message, buttons);

  initShadowImage();
}
 
Example 14
Source File: DesktopApplicationImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean confirmExitIfNeeded(boolean exitConfirmed) {
  final boolean hasUnsafeBgTasks = ProgressManager.getInstance().hasUnsafeProgressIndicator();
  if (exitConfirmed && !hasUnsafeBgTasks) {
    return true;
  }

  DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() {
    @Override
    public boolean isToBeShown() {
      return GeneralSettings.getInstance().isConfirmExit() && ProjectManager.getInstance().getOpenProjects().length > 0;
    }

    @Override
    public void setToBeShown(boolean value, int exitCode) {
      GeneralSettings.getInstance().setConfirmExit(value);
    }

    @Override
    public boolean canBeHidden() {
      return !hasUnsafeBgTasks;
    }

    @Override
    public boolean shouldSaveOptionsOnCancel() {
      return false;
    }

    @Nonnull
    @Override
    public String getDoNotShowMessage() {
      return "Do not ask me again";
    }
  };

  if (hasUnsafeBgTasks || option.isToBeShown()) {
    String message = ApplicationBundle.message(hasUnsafeBgTasks ? "exit.confirm.prompt.tasks" : "exit.confirm.prompt", ApplicationNamesInfo.getInstance().getFullProductName());

    if (MessageDialogBuilder.yesNo(ApplicationBundle.message("exit.confirm.title"), message).yesText(ApplicationBundle.message("command.exit")).noText(CommonBundle.message("button.cancel"))
                .doNotAsk(option).show() != Messages.YES) {
      return false;
    }
  }
  return true;
}
 
Example 15
Source File: ExecutionManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean userApprovesStopForIncompatibleConfigurations(Project project, String configName, List<RunContentDescriptor> runningIncompatibleDescriptors) {
  RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
  final RunManagerConfig config = runManager.getConfig();
  if (!config.isRestartRequiresConfirmation()) return true;

  DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() {
    @Override
    public boolean isToBeShown() {
      return config.isRestartRequiresConfirmation();
    }

    @Override
    public void setToBeShown(boolean value, int exitCode) {
      config.setRestartRequiresConfirmation(value);
    }

    @Override
    public boolean canBeHidden() {
      return true;
    }

    @Override
    public boolean shouldSaveOptionsOnCancel() {
      return false;
    }

    @Nonnull
    @Override
    public String getDoNotShowMessage() {
      return CommonBundle.message("dialog.options.do.not.show");
    }
  };

  final StringBuilder names = new StringBuilder();
  for (final RunContentDescriptor descriptor : runningIncompatibleDescriptors) {
    String name = descriptor.getDisplayName();
    if (names.length() > 0) {
      names.append(", ");
    }
    names.append(StringUtil.isEmpty(name) ? ExecutionBundle.message("run.configuration.no.name") : String.format("'%s'", name));
  }

  //noinspection DialogTitleCapitalization
  return Messages.showOkCancelDialog(project, ExecutionBundle.message("stop.incompatible.confirmation.message", configName, names.toString(), runningIncompatibleDescriptors.size()),
                                     ExecutionBundle.message("incompatible.configuration.is.running.dialog.title", runningIncompatibleDescriptors.size()),
                                     ExecutionBundle.message("stop.incompatible.confirmation.button.text"), CommonBundle.message("button.cancel"), Messages.getQuestionIcon(), option) == Messages.OK;
}
 
Example 16
Source File: ShowFilePathAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void showDialog(Project project, String message, String title, File file, DialogWrapper.DoNotAskOption option) {
  if (Messages.showOkCancelDialog(project, message, title, RevealFileAction.getActionName(), IdeBundle.message("action.close"), Messages.getInformationIcon(), option) == Messages.OK) {
    openFile(file);
  }
}
 
Example 17
Source File: MacMessages.java    From consulo with Apache License 2.0 3 votes vote down vote up
/**
 * Buttons are placed starting near the right side of the alert and going toward the left side
 * (for languages that read left to right). The first three buttons are identified positionally as
 * NSAlertFirstButtonReturn, NSAlertSecondButtonReturn, NSAlertThirdButtonReturn in the return-code parameter evaluated by the modal
 * delegate. Subsequent buttons are identified as NSAlertThirdButtonReturn +n, where n is an integer
 * <p>
 * By default, the first button has a key equivalent of Return,
 * any button with a title of "Cancel" has a key equivalent of Escape,
 * and any button with the title "Don't Save" has a key equivalent of Command-D (but only if it is not the first button).
 * <p>
 * http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSAlert_Class/Reference/Reference.html
 * <p>
 * Please, note that Cancel is supposed to be the last button!
 *
 * @return number of button pressed: from 0 up to buttons.length-1 inclusive, or -1 for Cancel
 */
public abstract int showMessageDialog(@Nonnull String title,
                                      String message,
                                      @Nonnull String[] buttons,
                                      boolean errorStyle,
                                      @Nullable Window window,
                                      int defaultOptionIndex,
                                      int focusedOptionIndex,
                                      @Nullable DialogWrapper.DoNotAskOption doNotAskDialogOption);