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

The following examples show how to use com.intellij.openapi.ui.Messages#OK . 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: 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 2
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 3
Source File: DragHelper.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void processDragFinish(MouseEvent event, boolean willDragOutStart) {
  super.processDragFinish(event, willDragOutStart);

  endDrag(willDragOutStart);

  final JBTabsPosition position = myTabs.getTabsPosition();

  if (!willDragOutStart && myTabs.isAlphabeticalMode() && position != JBTabsPosition.top && position != JBTabsPosition.bottom) {
    Point p = new Point(event.getPoint());
    p = SwingUtilities.convertPoint(event.getComponent(), p, myTabs);
    if (myTabs.getVisibleRect().contains(p) && myPressedOnScreenPoint.distance(new RelativePoint(event).getScreenPoint()) > 15) {
      final int answer = Messages.showOkCancelDialog(myTabs,
                                                     IdeBundle.message("alphabetical.mode.is.on.warning"),
                                                     IdeBundle.message("title.warning"),
                                                     Messages.getQuestionIcon());
      if (answer == Messages.OK) {
        JBEditorTabs.setAlphabeticalMode(false);
        myTabs.relayout(true, false);
        myTabs.revalidate();
      }
    }
  }
}
 
Example 4
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 5
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 6
Source File: ExecutableValidator.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if executable is valid and shows the message if not.
 * This method is to be used instead of {@link #checkExecutableAndNotifyIfNeeded()} when Git fails to start from a modal dialog:
 * in that case user won't be able to click "Fix it".
 *
 * @return true if executable was valid, false - if not valid (and a message is shown in that case).
 * @see #checkExecutableAndNotifyIfNeeded()
 */
public boolean checkExecutableAndShowMessageIfNeeded(@Nullable Component parentComponent) {
  if (myProject.isDisposed()) {
    return false;
  }

  if (!isExecutableValid(getCurrentExecutable())) {
    if (Messages.OK == showMessage(parentComponent)) {
      ApplicationManager.getApplication().invokeLater(() -> showSettings());
    }
    return false;
  }
  return true;
}
 
Example 7
Source File: AbstractExtractMethodDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void doOKAction() {
  final String error = myValidator.check(getMethodName());
  if (error != null){
    if (ApplicationManager.getApplication().isUnitTestMode()){
      Messages.showInfoMessage(error, RefactoringBundle.message("error.title"));
      return;
    }
    if (Messages.showOkCancelDialog(error + ". " + RefactoringBundle.message("do.you.wish.to.continue"), RefactoringBundle.message("warning.title"), Messages.getWarningIcon()) != Messages.OK){
      return;
    }
  }
  super.doOKAction();
}
 
Example 8
Source File: DialogsFactory.java    From android-codegenerator-plugin-intellij with Apache License 2.0 5 votes vote down vote up
public static boolean openOverrideFileDialog(Project project, String folderPath, String fileName) {
    return Messages.showYesNoDialog(
            project,
            String.format(StringResources.OVERRIDE_DIALOG_MESSAGE, folderPath, fileName),
            StringResources.OVERRIDE_DIALOG_TITLE,
            StringResources.OVERRIDE_DIALOG_YES_TEXT,
            StringResources.OVERRIDE_DIALOG_NO_TEXT,
            UIUtil.getWarningIcon()
    ) == Messages.OK;
}
 
Example 9
Source File: AllFileTemplatesConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void onReset() {
  FileTemplate selected = myCurrentTab.getSelectedTemplate();
  if (selected instanceof BundledFileTemplate) {
    if (Messages.showOkCancelDialog(IdeBundle.message("prompt.reset.to.original.template"), IdeBundle.message("title.reset.template"),
                                    Messages.getQuestionIcon()) != Messages.OK) {
      return;
    }
    ((BundledFileTemplate)selected).revertToDefaults();
    myEditor.reset();
    myModified = true;
  }
}
 
Example 10
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 11
Source File: CodeMakerConfiguration.java    From CodeMaker with Apache License 2.0 5 votes vote down vote up
private void onDeleteClicked(String title, String templateKey) {
    int result = Messages.showYesNoDialog("Delete this template '" + title + "' ?", "Delete", null);
    if (result == Messages.OK) {
        codeTemplates.remove(templateKey);
        refresh(codeTemplates);
    }
}
 
Example 12
Source File: OCamlModuleWizardStep.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
public boolean validate() {
    Sdk odk = c_sdk.getSelectedJdk();
    if (odk == null && !ApplicationManager.getApplication().isUnitTestMode()) {
        int result = Messages.showOkCancelDialog(
                "Do you want to create a project with no SDK assigned?\\nAn SDK is required for compiling as well as for the standard SDK modules resolution and type inference.",
                IdeBundle.message("title.no.jdk.specified"), Messages.OK_BUTTON, Messages.CANCEL_BUTTON, Messages.getWarningIcon());
        return result == Messages.OK;
    }
    return true;
}
 
Example 13
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 14
Source File: ReviewPanelController.java    From review-board-idea-plugin with Apache License 2.0 4 votes vote down vote up
public boolean confirmReviewPublish() {
    return Messages.showOkCancelDialog("Do you want to discard your review?", "Confirmation",
            AllIcons.General.BalloonWarning) != Messages.OK;
}
 
Example 15
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;
}
 
Example 16
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 17
Source File: FileTypeConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void editPattern(@Nullable final String item) {
  final FileType type = myRecognizedFileType.getSelectedFileType();
  if (type == null) return;

  final String title = item == null
                       ? FileTypesBundle.message("filetype.edit.add.pattern.title")
                       : FileTypesBundle.message("filetype.edit.edit.pattern.title");

  final Language oldLanguage = item == null ? null : myTempTemplateDataLanguages.findAssociatedFileType(item);
  final FileTypePatternDialog dialog = new FileTypePatternDialog(item, type, oldLanguage);
  final DialogBuilder builder = new DialogBuilder(myPatterns);
  builder.setPreferredFocusComponent(dialog.getPatternField());
  builder.setCenterPanel(dialog.getMainPanel());
  builder.setTitle(title);
  builder.showModal(true);
  if (builder.getDialogWrapper().isOK()) {
    final String pattern = dialog.getPatternField().getText();
    if (StringUtil.isEmpty(pattern)) return;

    final FileNameMatcher matcher = FileTypeManager.parseFromString(pattern);
    FileType registeredFileType = findExistingFileType(matcher);
    if (registeredFileType != null && registeredFileType != type) {
      if (registeredFileType.isReadOnly()) {
        Messages.showMessageDialog(myPatterns.myPatternsList, FileTypesBundle
                .message("filetype.edit.add.pattern.exists.error", registeredFileType.getDescription()), title,
                                   Messages.getErrorIcon());
        return;
      }
      else {
        if (Messages.OK ==
            Messages.showOkCancelDialog(myPatterns.myPatternsList, FileTypesBundle
                    .message("filetype.edit.add.pattern.exists.message", registeredFileType.getDescription()),
                                        FileTypesBundle.message("filetype.edit.add.pattern.exists.title"),
                                        FileTypesBundle.message("filetype.edit.add.pattern.reassign.button"),
                                        CommonBundle.getCancelButtonText(), Messages.getQuestionIcon())) {
          myTempPatternsTable.removeAssociation(matcher, registeredFileType);
          if(oldLanguage != null) {
            myTempTemplateDataLanguages.removeAssociation(matcher, oldLanguage);
          }
          myReassigned.put(matcher, registeredFileType);
        }
        else {
          return;
        }
      }
    }

    if (item != null) {
      final FileNameMatcher oldMatcher = FileTypeManager.parseFromString(item);
      myTempPatternsTable.removeAssociation(oldMatcher, type);
      if(oldLanguage != null) {
        myTempTemplateDataLanguages.removeAssociation(oldMatcher, oldLanguage);
      }
    }
    myTempPatternsTable.addAssociation(matcher, type);
    myTempTemplateDataLanguages.addAssociation(matcher, dialog.getTemplateDataLanguage());

    updateExtensionList();
    final int index = myPatterns.getListModel().indexOf(matcher.getPresentableString());
    if (index >= 0) {
      ScrollingUtil.selectItem(myPatterns.myPatternsList, index);
    }
    IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(myPatterns.myPatternsList);
  }
}
 
Example 18
Source File: TemplateUtils.java    From code-generator with Apache License 2.0 4 votes vote down vote up
private static boolean userConfirmedOverride(String name) {
    return Messages.showYesNoDialog(name + " already exists,\nConfirm Overwrite?", "File Exists", null)
        == Messages.OK;
}
 
Example 19
Source File: VirtualFileDeleteProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void deleteElement(@Nonnull DataContext dataContext) {
  final VirtualFile[] files = dataContext.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
  if (files == null || files.length == 0) return;
  Project project = dataContext.getData(CommonDataKeys.PROJECT);

  String message = createConfirmationMessage(files);
  int returnValue = Messages.showOkCancelDialog(message, UIBundle.message("delete.dialog.title"), ApplicationBundle.message("button.delete"),
                                                CommonBundle.getCancelButtonText(), Messages.getQuestionIcon());
  if (returnValue != Messages.OK) return;

  Arrays.sort(files, FileComparator.getInstance());

  List<String> problems = ContainerUtil.newLinkedList();
  CommandProcessor.getInstance().executeCommand(project, () -> {
    new Task.Modal(project, "Deleting Files...", true) {
      @Override
      public void run(@Nonnull ProgressIndicator indicator) {
        indicator.setIndeterminate(false);
        int i = 0;
        for (VirtualFile file : files) {
          indicator.checkCanceled();
          indicator.setText2(file.getPresentableUrl());
          indicator.setFraction((double)i / files.length);
          i++;

          try {
            WriteAction.run(() -> file.delete(this));
          }
          catch (Exception e) {
            LOG.info("Error when deleting " + file, e);
            problems.add(file.getName());
          }
        }
      }

      @RequiredUIAccess
      @Override
      public void onSuccess() {
        reportProblems();
      }

      @RequiredUIAccess
      @Override
      public void onCancel() {
        reportProblems();
      }

      private void reportProblems() {
        if (!problems.isEmpty()) {
          reportDeletionProblem(problems);
        }
      }
    }.queue();
  }, "Deleting files", null);
}
 
Example 20
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);
  }
}