Java Code Examples for com.intellij.openapi.ui.Messages#showYesNoCancelDialog()

The following examples show how to use com.intellij.openapi.ui.Messages#showYesNoCancelDialog() . 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: PantsOpenProjectProvider.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
private int shouldOpenExistingProject(VirtualFile file, Project projectToClose) {
  VirtualFile rootFile = PantsUtil.findBuildRoot(file).orElse(null);
  if(rootFile == null) return Messages.NO;

  ProjectOpenProcessor openProcessor = PlatformProjectOpenProcessor.getInstance();
  if (!openProcessor.canOpenProject(rootFile)) return Messages.NO;

  VirtualFile dotIdeaFile = rootFile.findChild(Project.DIRECTORY_STORE_FOLDER);
  if (dotIdeaFile == null || !dotIdeaFile.exists()) return Messages.NO;

  Application application = ApplicationManager.getApplication();
  if (application.isHeadlessEnvironment()) return Messages.YES;

  return Messages.showYesNoCancelDialog(
    projectToClose,
    JavaUiBundle.message("project.import.open.existing", "an existing project", rootFile.getPath(), file.getName()),
    IdeBundle.message("title.open.project"),
    JavaUiBundle.message("project.import.open.existing.openExisting"),
    JavaUiBundle.message("project.import.open.existing.reimport"),
    CommonBundle.getCancelButtonText(),
    Messages.getQuestionIcon()
  );
}
 
Example 2
Source File: CodeAnalysisBeforeCheckinHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
private ReturnResult processFoundCodeSmells(final List<CodeSmellInfo> codeSmells, @Nullable CommitExecutor executor) {
  int errorCount = collectErrors(codeSmells);
  int warningCount = codeSmells.size() - errorCount;
  String commitButtonText = executor != null ? executor.getActionText() : myCheckinPanel.getCommitActionName();
  if (commitButtonText.endsWith("...")) {
    commitButtonText = commitButtonText.substring(0, commitButtonText.length()-3);
  }

  final int answer = Messages.showYesNoCancelDialog(myProject,
    VcsBundle.message("before.commit.files.contain.code.smells.edit.them.confirm.text", errorCount, warningCount),
    VcsBundle.message("code.smells.error.messages.tab.name"), VcsBundle.message("code.smells.review.button"),
    commitButtonText, CommonBundle.getCancelButtonText(), UIUtil.getWarningIcon());
  if (answer == 0) {
    CodeSmellDetector.getInstance(myProject).showCodeSmellErrors(codeSmells);
    return ReturnResult.CLOSE_WINDOW;
  }
  else if (answer == 2 || answer == -1) {
    return ReturnResult.CANCEL;
  }
  else {
    return ReturnResult.COMMIT;
  }
}
 
Example 3
Source File: CreateDirectoryOrPackageHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private Boolean suggestCreatingFileInstead(String subDirName) {
  Boolean createFile = false;
  if (StringUtil.countChars(subDirName, '.') == 1 && Registry.is("ide.suggest.file.when.creating.filename.like.directory")) {
    FileType fileType = findFileTypeBoundToName(subDirName);
    if (fileType != null) {
      String message = "The name you entered looks like a file name. Do you want to create a file named " + subDirName + " instead?";
      int ec = Messages.showYesNoCancelDialog(myProject, message, "File Name Detected", "&Yes, create file", "&No, create " + (myIsDirectory ? "directory" : "packages"),
                                              CommonBundle.getCancelButtonText(), TargetAWT.to(fileType.getIcon()));
      if (ec == Messages.CANCEL) {
        createFile = null;
      }
      if (ec == Messages.YES) {
        createFile = true;
      }
    }
  }
  return createFile;
}
 
Example 4
Source File: BlazeAndroidBinaryRunConfigurationHandler.java    From intellij with Apache License 2.0 4 votes vote down vote up
/**
 * Maybe shows the mobile-install optin dialog, and migrates project as appropriate.
 *
 * <p>Will only be shown once per project in a 20 hour window, with the ability to permanently
 * dismiss for this project.
 *
 * <p>If the user selects "Yes", all BlazeAndroidBinaryRunConfigurations in this project will be
 * migrated to use mobile-install.
 *
 * @return true if dialog was shown and user migrated, otherwise false
 */
private boolean maybeShowMobileInstallOptIn(
    Project project, BlazeCommandRunConfiguration configuration) {
  long lastPrompt = PropertiesComponent.getInstance(project).getOrInitLong(MI_LAST_PROMPT, 0L);
  boolean neverAsk =
      PropertiesComponent.getInstance(project).getBoolean(MI_NEVER_ASK_AGAIN, false);
  if (neverAsk || (System.currentTimeMillis() - lastPrompt) < MI_TIMEOUT_MS) {
    return false;
  }
  // Add more logging on why the MI opt-in dialog is shown.  There exists a bug there a user
  // is shown the mobile-install opt-in dialog every time they switch clients. The only way for
  // this to happen is if a new target is created or if the timeouts are not behaving as expected.
  // TODO Remove once b/130327673 is resolved.
  LOG.info(
      "Showing mobile install opt-in dialog.\n"
          + "Run target: "
          + configuration.getSingleTarget()
          + "\n"
          + "Time since last prompt: "
          + (System.currentTimeMillis() - lastPrompt));
  PropertiesComponent.getInstance(project)
      .setValue(MI_LAST_PROMPT, String.valueOf(System.currentTimeMillis()));
  int choice =
      Messages.showYesNoCancelDialog(
          project,
          "Blaze mobile-install (go/blaze-mi) introduces fast, incremental builds and deploys "
              + "for Android development.\nBlaze mobile-install is the default for new Android "
              + "Studio projects, but you're still using Blaze build.\n\nSwitch all run "
              + "configurations in this project to use Blaze mobile-install?",
          "Switch to Blaze mobile-install?",
          "Yes",
          "Not now",
          "Never ask again for this project",
          Messages.getQuestionIcon());
  if (choice == Messages.YES) {
    Messages.showInfoMessage(
        String.format(
            "Successfully migrated %d run configuration(s) to mobile-install",
            doMigrate(project)),
        "Success!");
  } else if (choice == Messages.NO) {
    // Do nothing, dialog will not be shown until the wait period has elapsed
  } else if (choice == Messages.CANCEL) {
    PropertiesComponent.getInstance(project).setValue(MI_NEVER_ASK_AGAIN, true);
  }
  EventLoggingService.getInstance()
      .logEvent(
          getClass(), "mi_migrate_prompt", ImmutableMap.of("choice", choiceToString(choice)));
  return choice == Messages.YES;
}
 
Example 5
Source File: MindMapDialogProvider.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean msgConfirmYesNoCancel(@Nullable final Component parentComponent, @Nonnull final String title, @Nonnull final String text) {
  final int result = Messages.showYesNoCancelDialog(this.project, text, title, Messages.getQuestionIcon());
  return result == Messages.CANCEL ? null : result == Messages.YES;
}
 
Example 6
Source File: KeymapPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void addMouseShortcut(Shortcut shortcut, ShortcutRestrictions restrictions) {
  String actionId = myActionsTree.getSelectedActionId();
  if (actionId == null) {
    return;
  }

  if (!createKeymapCopyIfNeeded()) return;

  MouseShortcut mouseShortcut = shortcut instanceof MouseShortcut ? (MouseShortcut)shortcut : null;

  MouseShortcutDialog dialog = new MouseShortcutDialog(this, mouseShortcut, mySelectedKeymap, actionId, myActionsTree.getMainGroup(), restrictions);
  dialog.show();
  if (!dialog.isOK()) {
    return;
  }

  mouseShortcut = dialog.getMouseShortcut();

  if (mouseShortcut == null) {
    return;
  }

  String[] actionIds = mySelectedKeymap.getActionIds(mouseShortcut);
  if (actionIds.length > 1 || (actionIds.length == 1 && !actionId.equals(actionIds[0]))) {
    int result = Messages.showYesNoCancelDialog(this, KeyMapBundle.message("conflict.shortcut.dialog.message"),
                                                KeyMapBundle.message("conflict.shortcut.dialog.title"),
                                                KeyMapBundle.message("conflict.shortcut.dialog.remove.button"),
                                                KeyMapBundle.message("conflict.shortcut.dialog.leave.button"),
                                                KeyMapBundle.message("conflict.shortcut.dialog.cancel.button"), Messages.getWarningIcon());

    if (result == Messages.YES) {
      for (String id : actionIds) {
        mySelectedKeymap.removeShortcut(id, mouseShortcut);
      }
    }
    else if (result != Messages.NO) {
      return;
    }
  }

  // if shortcut is aleady registered to this action, just select it in the list

  Shortcut[] shortcuts = mySelectedKeymap.getShortcuts(actionId);
  for (Shortcut shortcut1 : shortcuts) {
    if (shortcut1.equals(mouseShortcut)) {
      return;
    }
  }

  mySelectedKeymap.addShortcut(actionId, mouseShortcut);
  if (StringUtil.startsWithChar(actionId, '$')) {
    mySelectedKeymap.addShortcut(KeyMapBundle.message("editor.shortcut", actionId.substring(1)), mouseShortcut);
  }

  repaintLists();
  processCurrentKeymapChanged(getCurrentQuickListIds());
}
 
Example 7
Source File: InstallPluginAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean suggestToEnableInstalledPlugins(final InstalledPluginsTableModel pluginsModel,
                                                       final Set<PluginDescriptor> disabled,
                                                       final Set<PluginDescriptor> disabledDependants,
                                                       final List<PluginDescriptor> list) {
  if (!disabled.isEmpty() || !disabledDependants.isEmpty()) {
    String message = "";
    if (disabled.size() == 1) {
      message += "Updated plugin '" + disabled.iterator().next().getName() + "' is disabled.";
    }
    else if (!disabled.isEmpty()) {
      message += "Updated plugins " + StringUtil.join(disabled, PluginDescriptor::getName, ", ") + " are disabled.";
    }

    if (!disabledDependants.isEmpty()) {
      message += "<br>";
      message += "Updated plugin" + (list.size() > 1 ? "s depend " : " depends ") + "on disabled";
      if (disabledDependants.size() == 1) {
        message += " plugin '" + disabledDependants.iterator().next().getName() + "'.";
      }
      else {
        message += " plugins " + StringUtil.join(disabledDependants, PluginDescriptor::getName, ", ") + ".";
      }
    }
    message += " Disabled plugins and plugins which depends on disabled plugins won't be activated after restart.";

    int result;
    if (!disabled.isEmpty() && !disabledDependants.isEmpty()) {
      result = Messages.showYesNoCancelDialog(XmlStringUtil.wrapInHtml(message), CommonBundle.getWarningTitle(), "Enable all", "Enable updated plugin" + (disabled.size() > 1 ? "s" : ""),
                                              CommonBundle.getCancelButtonText(), Messages.getQuestionIcon());
      if (result == Messages.CANCEL) return false;
    }
    else {
      message += "<br>Would you like to enable ";
      if (!disabled.isEmpty()) {
        message += "updated plugin" + (disabled.size() > 1 ? "s" : "");
      }
      else {
        //noinspection SpellCheckingInspection
        message += "plugin dependenc" + (disabledDependants.size() > 1 ? "ies" : "y");
      }
      message += "?</body></html>";
      result = Messages.showYesNoDialog(message, CommonBundle.getWarningTitle(), Messages.getQuestionIcon());
      if (result == Messages.NO) return false;
    }

    if (result == Messages.YES) {
      disabled.addAll(disabledDependants);
      pluginsModel.enableRows(disabled.toArray(new PluginDescriptor[disabled.size()]), true);
    }
    else if (result == Messages.NO && !disabled.isEmpty()) {
      pluginsModel.enableRows(disabled.toArray(new PluginDescriptor[disabled.size()]), true);
    }
    return true;
  }
  return false;
}
 
Example 8
Source File: InplaceRefactoring.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected boolean buildTemplateAndStart(final Collection<PsiReference> refs,
                                        final Collection<Pair<PsiElement, TextRange>> stringUsages,
                                        final PsiElement scope,
                                        final PsiFile containingFile) {
  final PsiElement context = InjectedLanguageManager.getInstance(containingFile.getProject()).getInjectionHost(containingFile);
  myScope = context != null ? context.getContainingFile() : scope;
  final TemplateBuilderImpl builder = new TemplateBuilderImpl(myScope);

  PsiElement nameIdentifier = getNameIdentifier();
  int offset = myEditor.getCaretModel().getOffset();
  PsiElement selectedElement = getSelectedInEditorElement(nameIdentifier, refs, stringUsages, offset);

  boolean subrefOnPrimaryElement = false;
  boolean hasReferenceOnNameIdentifier = false;
  for (PsiReference ref : refs) {
    if (isReferenceAtCaret(selectedElement, ref)) {
      builder.replaceElement(ref, PRIMARY_VARIABLE_NAME, createLookupExpression(selectedElement), true);
      subrefOnPrimaryElement = true;
      continue;
    }
    addVariable(ref, selectedElement, builder, offset);
    hasReferenceOnNameIdentifier |= isReferenceAtCaret(nameIdentifier, ref);
  }
  if (nameIdentifier != null) {
    hasReferenceOnNameIdentifier |= selectedElement.getTextRange().contains(nameIdentifier.getTextRange());
    if (!subrefOnPrimaryElement || !hasReferenceOnNameIdentifier){
      addVariable(nameIdentifier, selectedElement, builder);
    }
  }
  for (Pair<PsiElement, TextRange> usage : stringUsages) {
    addVariable(usage.first, usage.second, selectedElement, builder);
  }
  addAdditionalVariables(builder);
  try {
    myMarkAction = startRename();
  }
  catch (final StartMarkAction.AlreadyStartedException e) {
    final Document oldDocument = e.getDocument();
    if (oldDocument != myEditor.getDocument()) {
      final int exitCode = Messages.showYesNoCancelDialog(myProject, e.getMessage(), getCommandName(),
                                                          "Navigate to Started", "Cancel Started", "Cancel", Messages.getErrorIcon());
      if (exitCode == Messages.CANCEL) return true;
      navigateToAlreadyStarted(oldDocument, exitCode);
      return true;
    }
    else {

      if (!ourRenamersStack.isEmpty() && ourRenamersStack.peek() == this) {
        ourRenamersStack.pop();
        if (!ourRenamersStack.empty()) {
          myOldName = ourRenamersStack.peek().myOldName;
        }
      }

      revertState();
      final TemplateState templateState = TemplateManagerImpl.getTemplateState(InjectedLanguageUtil.getTopLevelEditor(myEditor));
      if (templateState != null) {
        templateState.gotoEnd(true);
      }
    }
    return false;
  }

  beforeTemplateStart();

  new WriteCommandAction(myProject, getCommandName()) {
    @Override
    protected void run(com.intellij.openapi.application.Result result) throws Throwable {
      startTemplate(builder);
    }
  }.execute();

  if (myBalloon == null) {
    showBalloon();
  }
  return true;
}