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

The following examples show how to use com.intellij.openapi.ui.Messages#OK . These examples are extracted from open source projects. 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 Project: consulo   File: ProjectViewImpl.java    License: 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 Project: consulo   File: DragHelper.java    License: 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 3
Source Project: consulo   File: CompilerUtil.java    License: 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 4
Source Project: consulo   File: WebProjectViewImpl.java    License: 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 Project: haystack   File: FlutterReduxGen.java    License: 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 6
Source Project: consulo   File: TodoCheckinHandler.java    License: 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 7
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 8
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 9
Source Project: consulo   File: ExecutionManagerImpl.java    License: 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 10
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 11
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 12
@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 13
Source Project: consulo   File: ExecutableValidator.java    License: 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 14
Source Project: code-generator   File: TemplateUtils.java    License: 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 15
Source Project: consulo   File: ExecutionManagerImpl.java    License: 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
public boolean confirmReviewPublish() {
    return Messages.showOkCancelDialog("Do you want to discard your review?", "Confirmation",
            AllIcons.General.BalloonWarning) != Messages.OK;
}
 
Example 17
@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 18
Source Project: consulo   File: FileTypeConfigurable.java    License: 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 19
@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 Project: consulo   File: ShowFilePathAction.java    License: 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);
  }
}