Java Code Examples for com.intellij.openapi.ui.Messages#YesNoCancelResult

The following examples show how to use com.intellij.openapi.ui.Messages#YesNoCancelResult . 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: 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 2
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 3
Source File: MacMessagesImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Messages.YesNoCancelResult
private static int showAlertDialog(@Nonnull String title,
                                   @Nonnull String okText,
                                   @Nullable String alternateText,
                                   @Nullable String cancelText,
                                   String message,
                                   @Nullable consulo.ui.Window window) {
  return showAlertDialog(title, okText, alternateText, cancelText, message, window, false, null);
}
 
Example 4
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 5
Source File: MacMessagesImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Messages.YesNoCancelResult
private static int convertReturnCodeFromNativeAlertDialog(int returnCode, String alternateText) {
  // DEFAULT = 1
  // ALTERNATE = 0
  // OTHER = -1 (cancel)

  int cancelCode;
  int code;
  if (alternateText != null) {
    // DEFAULT = 0
    // ALTERNATE = 1
    // CANCEL = 2

    cancelCode = Messages.CANCEL;

    switch (returnCode) {
      case 1:
        code = Messages.YES;
        break;
      case 0:
        code = Messages.NO;
        break;
      case -1: // cancel
      default:
        code = Messages.CANCEL;
        break;
    }
  }
  else {
    // DEFAULT = 0
    // CANCEL = 1

    cancelCode = 1;

    switch (returnCode) {
      case 1:
        code = Messages.YES;
        break;
      case -1: // cancel
      default:
        code = Messages.NO;
        break;
    }
  }

  if (cancelCode == code) {
    code = Messages.CANCEL;
  }
  LOG.assertTrue(code == Messages.YES || code == Messages.NO || code == Messages.CANCEL, code);
  return code;
}