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

The following examples show how to use com.intellij.openapi.ui.Messages#showOkCancelDialog() . 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: ProjectWizardUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean createDirectoryIfNotExists(final String promptPrefix, String directoryPath, boolean promptUser) {
  File dir = new File(directoryPath);
  if (!dir.exists()) {
    if (promptUser) {
      final int answer = Messages.showOkCancelDialog(IdeBundle.message("promot.projectwizard.directory.does.not.exist", promptPrefix,
                                                                       dir.getPath(), ApplicationNamesInfo.getInstance().getFullProductName()),
                                                     IdeBundle.message("title.directory.does.not.exist"), Messages.getQuestionIcon());
      if (answer != 0) {
        return false;
      }
    }
    try {
      VfsUtil.createDirectories(dir.getPath());
    }
    catch (IOException e) {
      Messages.showErrorDialog(IdeBundle.message("error.failed.to.create.directory", dir.getPath()), CommonBundle.getErrorTitle());
      return false;
    }
  }
  return true;
}
 
Example 2
Source File: LandingPageAction.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 6 votes vote down vote up
public static void open() {
    Analytics.event("landingPage", "clicked");
    int ok = Messages.showOkCancelDialog("This feature is planned for a \nfuture release of the premium version.\n" +
                    "If you are interested, please visit: \n\n" + URL, "Premium Version", "Find more", "Cancel",
            AllIcons.General.QuestionDialog);
    if (ok == 0) {
        Analytics.event("landingPage", "land");
        try {
            Desktop.getDesktop().browse(URI.create(URL));
        } catch (Exception e) {
            BrowserLauncher.getInstance().browse(URI.create(URL));
        }
    } else {
        Analytics.event("landingPage", "cancel");
    }
}
 
Example 3
Source File: CustomizableActionsPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void editToolbarIcon(String actionId, DefaultMutableTreeNode node) {
  final AnAction anAction = ActionManager.getInstance().getAction(actionId);
  if (isToolbarAction(node) &&
      anAction.getTemplatePresentation() != null &&
      anAction.getTemplatePresentation().getIcon() == null) {
    final int exitCode = Messages.showOkCancelDialog(IdeBundle.message("error.adding.action.without.icon.to.toolbar"),
                                                     IdeBundle.message("title.unable.to.add.action.without.icon.to.toolbar"),
                                                     Messages.getInformationIcon());
    if (exitCode == Messages.OK) {
      mySelectedSchema.addIconCustomization(actionId, null);
      anAction.getTemplatePresentation().setIcon(AllIcons.Toolbar.Unknown);
      anAction.setDefaultIcon(false);
      node.setUserObject(Pair.create(actionId, AllIcons.Toolbar.Unknown));
      myActionsTree.repaint();
      setCustomizationSchemaForCurrentProjects();
    }
  }
}
 
Example 4
Source File: CompilerUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean askUserToContinueWithNoClearing(Project project, Collection<VirtualFile> affectedOutputPaths) {
  final StringBuilder paths = new StringBuilder();
  for (final VirtualFile affectedOutputPath : affectedOutputPaths) {
    if (paths.length() > 0) {
      paths.append(",\n");
    }
    paths.append(affectedOutputPath.getPath().replace('/', File.separatorChar));
  }
  final int answer = Messages.showOkCancelDialog(project,
                                                 CompilerBundle.message("warning.sources.under.output.paths", paths.toString()),
                                                 CommonBundle.getErrorTitle(), Messages.getWarningIcon());
  if (answer == Messages.OK) { // ok
    return true;
  }
  else {
    return false;
  }
}
 
Example 5
Source File: PushController.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean ensureForcePushIsNeeded() {
  Collection<MyRepoModel<?, ?, ?>> selectedNodes = getSelectedRepoNode();
  MyRepoModel<?, ?, ?> selectedModel = ContainerUtil.getFirstItem(selectedNodes);
  if (selectedModel == null) return false;
  final PushSupport activePushSupport = selectedModel.getSupport();
  final PushTarget commonTarget = getCommonTarget(selectedNodes);
  if (commonTarget != null && activePushSupport.isSilentForcePushAllowed(commonTarget)) return true;
  return Messages.showOkCancelDialog(myProject, XmlStringUtil.wrapInHtml(DvcsBundle.message("push.force.confirmation.text",
                                                                                            commonTarget != null
                                                                                            ? " to <b>" +
                                                                                              commonTarget.getPresentation() + "</b>"
                                                                                            : "")),
                                     "Force Push", "&Force Push",
                                     CommonBundle.getCancelButtonText(),
                                     Messages.getWarningIcon(),
                                     commonTarget != null ? new MyDoNotAskOptionForPush(activePushSupport, commonTarget) : null) == OK;
}
 
Example 6
Source File: ProjectViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void detachLibrary(@Nonnull final LibraryOrderEntry orderEntry, @Nonnull Project project) {
  final Module module = orderEntry.getOwnerModule();
  String message = IdeBundle.message("detach.library.from.module", orderEntry.getPresentableName(), module.getName());
  String title = IdeBundle.message("detach.library");
  int ret = Messages.showOkCancelDialog(project, message, title, Messages.getQuestionIcon());
  if (ret != Messages.OK) return;
  CommandProcessor.getInstance().executeCommand(module.getProject(), () -> {
    final Runnable action = () -> {
      ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
      OrderEntry[] orderEntries = rootManager.getOrderEntries();
      ModifiableRootModel model = rootManager.getModifiableModel();
      OrderEntry[] modifiableEntries = model.getOrderEntries();
      for (int i = 0; i < orderEntries.length; i++) {
        OrderEntry entry = orderEntries[i];
        if (entry instanceof LibraryOrderEntry && ((LibraryOrderEntry)entry).getLibrary() == orderEntry.getLibrary()) {
          model.removeOrderEntry(modifiableEntries[i]);
        }
      }
      model.commit();
    };
    ApplicationManager.getApplication().runWriteAction(action);
  }, title, null);
}
 
Example 7
Source File: WebProjectViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void detachLibrary(@Nonnull final LibraryOrderEntry orderEntry, @Nonnull Project project) {
  final Module module = orderEntry.getOwnerModule();
  String message = IdeBundle.message("detach.library.from.module", orderEntry.getPresentableName(), module.getName());
  String title = IdeBundle.message("detach.library");
  int ret = Messages.showOkCancelDialog(project, message, title, Messages.getQuestionIcon());
  if (ret != Messages.OK) return;
  CommandProcessor.getInstance().executeCommand(module.getProject(), () -> {
    final Runnable action = () -> {
      ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
      OrderEntry[] orderEntries = rootManager.getOrderEntries();
      ModifiableRootModel model = rootManager.getModifiableModel();
      OrderEntry[] modifiableEntries = model.getOrderEntries();
      for (int i = 0; i < orderEntries.length; i++) {
        OrderEntry entry = orderEntries[i];
        if (entry instanceof LibraryOrderEntry && ((LibraryOrderEntry)entry).getLibrary() == orderEntry.getLibrary()) {
          model.removeOrderEntry(modifiableEntries[i]);
        }
      }
      model.commit();
    };
    ApplicationManager.getApplication().runWriteAction(action);
  }, title, null);
}
 
Example 8
Source File: ExecutableValidator.java    From consulo with Apache License 2.0 5 votes vote down vote up
private int showMessage(@Nullable Component parentComponent) {
  String okText = "Fix it";
  String cancelText = CommonBundle.getCancelButtonText();
  Icon icon = Messages.getErrorIcon();
  String title = myNotificationErrorTitle;
  String description = myNotificationErrorDescription;
  return parentComponent != null
         ? Messages.showOkCancelDialog(parentComponent, description, title, okText, cancelText, icon)
         : Messages.showOkCancelDialog(myProject, description, title, okText, cancelText, icon);
}
 
Example 9
Source File: FlutterReduxGen.java    From haystack with MIT License 5 votes vote down vote up
private void checkProjectStructure(PageModel pageModel) {
    if (!new File(sourcePath + "/redux/").exists() ||
            !new File(sourcePath + "/features/").exists() ||
            !new File(sourcePath + "/trans/").exists() ||
            !new File(sourcePath + "/data/").exists()) {
        int result = Messages.showOkCancelDialog(project, "You must init the project first!"
                , "Init Project", "OK", "NO", Messages.getQuestionIcon());
        if (result == Messages.OK) {
            initTemplate();
            genStructure(pageModel);
        }
    } else {
        genStructure(pageModel);
    }
}
 
Example 10
Source File: GetCommittedChangelistAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void actionPerformed(@Nonnull final VcsContext context) {
  Collection<FilePath> filePaths = getFilePaths(context);
  final List<ChangeList> selectedChangeLists = new ArrayList<>();
  final ChangeList[] selectionFromContext = context.getSelectedChangeLists();
  if (selectionFromContext != null) {
    Collections.addAll(selectedChangeLists, selectionFromContext);
  }
  final List<CommittedChangeList> incomingChanges = CommittedChangesCache.getInstance(context.getProject()).getCachedIncomingChanges();
  final List<CommittedChangeList> intersectingChanges = new ArrayList<>();
  if (incomingChanges != null) {
    for(CommittedChangeList changeList: incomingChanges) {
      if (!selectedChangeLists.contains(changeList)) {
        for(Change change: changeList.getChanges()) {
          if (filePaths.contains(ChangesUtil.getFilePath(change))) {
            intersectingChanges.add(changeList);
            break;
          }
        }
      }
    }
  }
  if (intersectingChanges.size() > 0) {
    int rc = Messages.showOkCancelDialog(
            context.getProject(), VcsBundle.message("get.committed.changes.intersecting.prompt", intersectingChanges.size(), selectedChangeLists.size()),
            VcsBundle.message("get.committed.changes.title"), Messages.getQuestionIcon());
    if (rc != Messages.OK) return;
  }
  super.actionPerformed(context);
}
 
Example 11
Source File: MergeRequestImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
  if (myWasInvoked) return;
  if (!getWholePanel().isDisplayable()) return;
  myWasInvoked = true;
  ChangeCounter.getOrCreate(myMergePanel.getMergeList()).removeListener(this);
  int doApply = Messages
          .showOkCancelDialog(getWholePanel(), DiffBundle.message("merge.all.changes.have.processed.save.and.finish.confirmation.text"),
                              DiffBundle.message("all.changes.processed.dialog.title"),
                              DiffBundle.message("merge.save.and.finish.button"), DiffBundle.message("merge.continue.button"),
                              Messages.getQuestionIcon());
  if (doApply != Messages.OK) return;
  myDialogWrapper.close(DialogWrapper.OK_EXIT_CODE);
}
 
Example 12
Source File: LombokLoggerHandler.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean checkLoggerField(@NotNull PsiField psiField, @NotNull String lombokLoggerName, boolean lombokLoggerIsStatic) {
  if (!isValidLoggerField(psiField, lombokLoggerName, lombokLoggerIsStatic)) {
    final String messageText = String.format("Logger field: \"%s\" Is not private %sfinal field named \"%s\". Refactor anyway?",
      psiField.getName(), lombokLoggerIsStatic ? "static " : "", lombokLoggerName);
    int result = Messages.showOkCancelDialog(messageText, "Attention!", Messages.getOkButton(), Messages.getCancelButton(), Messages.getQuestionIcon());
    return DialogWrapper.OK_EXIT_CODE == result;
  }
  return true;
}
 
Example 13
Source File: AddControllerForm.java    From r2m-plugin-android with Apache License 2.0 5 votes vote down vote up
private boolean ifContinue(String methodName, BodyValidationResult validationResult) {
    int okCancelResult = Messages.showOkCancelDialog(contentPane, R2MMessages.getMessage("VALIDATION_WARNING_QUESTION", methodName) + "\n" + JSONValidator.getErrorMessage(validationResult.getErrors()),
            R2MMessages.getMessage("VALIDATION_WARNING_TITLE", methodName),
            R2MMessages.getMessage("VALIDATION_WARNING_CONTINUE"),
            R2MMessages.getMessage("VALIDATION_WARNING_CANCEL"),
            null);
    return okCancelResult == 0;
}
 
Example 14
Source File: TodoCheckinHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
  if (! myConfiguration.CHECK_NEW_TODO) return ReturnResult.COMMIT;
  if (DumbService.getInstance(myProject).isDumb()) {
    String todoName = VcsBundle.message("before.checkin.new.todo.check.title");
    if (Messages.showOkCancelDialog(myProject,
                                    todoName +
                                    " can't be performed while " + ApplicationNamesInfo.getInstance().getFullProductName() + " updates the indices in background.\n" +
                                    "You can commit the changes without running checks, or you can wait until indices are built.",
                                    todoName + " is not possible right now",
                                    "&Wait", "&Commit", null) == Messages.OK) {
      return ReturnResult.CANCEL;
    }
    return ReturnResult.COMMIT;
  }
  Collection<Change> changes = myCheckinProjectPanel.getSelectedChanges();
  TodoCheckinHandlerWorker worker = new TodoCheckinHandlerWorker(myProject, changes, myTodoFilter, true);

  Ref<Boolean> completed = Ref.create(Boolean.FALSE);
  ProgressManager.getInstance().run(new Task.Modal(myProject, "Looking for New and Edited TODO Items...", true) {
    @Override
    public void run(@Nonnull ProgressIndicator indicator) {
      indicator.setIndeterminate(true);
      worker.execute();
    }

    @Override
    public void onSuccess() {
      completed.set(Boolean.TRUE);
    }
  });
  if (completed.get() && (worker.getAddedOrEditedTodos().isEmpty() && worker.getInChangedTodos().isEmpty() &&
                          worker.getSkipped().isEmpty())) return ReturnResult.COMMIT;
  if (!completed.get()) return ReturnResult.CANCEL;
  return showResults(worker, executor);
}
 
Example 15
Source File: ShelvedChangesViewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteElement(@Nonnull DataContext dataContext) {
  //noinspection unchecked
  final List<ShelvedChangeList> shelvedChangeLists = getLists(dataContext);
  if (shelvedChangeLists.isEmpty()) return;
  String message = (shelvedChangeLists.size() == 1)
    ? VcsBundle.message("shelve.changes.delete.confirm", shelvedChangeLists.get(0).DESCRIPTION)
    : VcsBundle.message("shelve.changes.delete.multiple.confirm", shelvedChangeLists.size());
  int rc = Messages.showOkCancelDialog(myProject, message, VcsBundle.message("shelvedChanges.delete.title"), CommonBundle.message("button.delete"), CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
  if (rc != 0) return;
  for(ShelvedChangeList changeList: shelvedChangeLists) {
    ShelveChangesManager.getInstance(myProject).deleteChangeList(changeList);
  }
}
 
Example 16
Source File: ReplaceFileConfirmationDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean requestConfirmation(final Collection modifiedFiles) {
  if (modifiedFiles.isEmpty()) return true;

  return Messages.showOkCancelDialog(createMessage(modifiedFiles), myActionName,
                                  createOwerriteButtonName(modifiedFiles), getCancelButtonText(),
                             Messages.getWarningIcon()) ==
              DialogWrapper.OK_EXIT_CODE;

}
 
Example 17
Source File: ReloadFromDiskAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  DataContext dataContext = e.getDataContext();
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  final Editor editor = dataContext.getData(PlatformDataKeys.EDITOR);
  if (editor == null) return;
  final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (psiFile == null) return;

  int res = Messages.showOkCancelDialog(
    project,
    IdeBundle.message("prompt.reload.file.from.disk", psiFile.getVirtualFile().getPresentableUrl()),
    IdeBundle.message("title.reload.file"),
    Messages.getWarningIcon()
  );
  if (res != 0) return;

  CommandProcessor.getInstance().executeCommand(
      project, new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().runWriteAction(
          new Runnable() {
            @Override
            public void run() {
              PsiManager.getInstance(project).reloadFromDisk(psiFile);
            }
          }
        );
      }
    },
      IdeBundle.message("command.reload.from.disk"),
      null
  );
}
 
Example 18
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 19
Source File: VetoSavingCommittingDocumentsAdapter.java    From consulo with Apache License 2.0 5 votes vote down vote up
boolean showAllowSaveDialog(Map<Document, Project> documentsToWarn) {
  StringBuilder messageBuilder = new StringBuilder("The following " + (documentsToWarn.size() == 1 ? "file is" : "files are") +
                                                   " currently being committed to the VCS. " +
                                                   "Saving now could cause inconsistent data to be committed.\n");
  for (Document document : documentsToWarn.keySet()) {
    final VirtualFile file = myFileDocumentManager.getFile(document);
    messageBuilder.append(FileUtil.toSystemDependentName(file.getPath())).append("\n");
  }
  messageBuilder.append("Save the ").append(documentsToWarn.size() == 1 ? "file" : "files").append(" now?");

  Project project = documentsToWarn.values().iterator().next();
  int rc = Messages.showOkCancelDialog(project, messageBuilder.toString(), "Save Files During Commit", "Save Now", "Postpone Save",
                                       Messages.getQuestionIcon());
  return rc == 0;
}
 
Example 20
Source File: MindMapDialogProvider.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean msgConfirmOkCancel(@Nullable final Component parentComponent, @Nonnull final String title, @Nonnull final String text) {
  return Messages.showOkCancelDialog(this.project, text, title, Messages.getQuestionIcon()) == Messages.OK;
}