com.intellij.CommonBundle Java Examples

The following examples show how to use com.intellij.CommonBundle. 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: ElementCreator.java    From consulo with Apache License 2.0 6 votes vote down vote up
public PsiElement[] tryCreate(@Nonnull final String inputString) {
  if (inputString.length() == 0) {
    Messages.showMessageDialog(myProject, IdeBundle.message("error.name.should.be.specified"), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    return PsiElement.EMPTY_ARRAY;
  }

  Ref<List<SmartPsiElementPointer>> createdElements = Ref.create();
  Exception exception = executeCommand(getActionName(inputString), () -> {
    PsiElement[] psiElements = create(inputString);
    SmartPointerManager manager = SmartPointerManager.getInstance(myProject);
    createdElements.set(ContainerUtil.map(psiElements, manager::createSmartPsiElementPointer));
  });
  if (exception != null) {
    handleException(exception);
    return PsiElement.EMPTY_ARRAY;
  }

  return ContainerUtil.mapNotNull(createdElements.get(), SmartPsiElementPointer::getElement).toArray(PsiElement.EMPTY_ARRAY);
}
 
Example #2
Source File: SafeFileOutputStream.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void restoreFromBackup(@Nullable Path backup, IOException e) throws IOException {
  if (backup == null) {
    throw new IOException(CommonBundle.message("safe.write.junk", myTarget), e);
  }

  boolean restored = true;
  try (InputStream in = Files.newInputStream(backup, BACKUP_READ); OutputStream out = Files.newOutputStream(myTarget, MAIN_WRITE)) {
    FileUtil.copy(in, out);
  }
  catch (IOException ex) {
    restored = false;
    e.addSuppressed(ex);
  }
  if (restored) {
    throw new IOException(CommonBundle.message("safe.write.restored", myTarget), e);
  }
  else {
    throw new IOException(CommonBundle.message("safe.write.junk.backup", myTarget, backup.getFileName()), e);
  }
}
 
Example #3
Source File: MasterDetailsComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void checkApply(Set<MyNode> rootNodes, String prefix, String title) throws ConfigurationException {
  for (MyNode rootNode : rootNodes) {
    final Set<String> names = new HashSet<String>();
    for (int i = 0; i < rootNode.getChildCount(); i++) {
      final MyNode node = (MyNode)rootNode.getChildAt(i);
      final NamedConfigurable scopeConfigurable = node.getConfigurable();
      final String name = scopeConfigurable.getDisplayName();
      if (name.trim().length() == 0) {
        selectNodeInTree(node);
        throw new ConfigurationException("Name should contain non-space characters");
      }
      if (names.contains(name)) {
        final NamedConfigurable selectedConfigurable = getSelectedConfigurable();
        if (selectedConfigurable == null || !Comparing.strEqual(selectedConfigurable.getDisplayName(), name)) {
          selectNodeInTree(node);
        }
        throw new ConfigurationException(CommonBundle.message("smth.already.exist.error.message", prefix, name), title);
      }
      names.add(name);
    }
  }
}
 
Example #4
Source File: PsiFileNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateImpl(PresentationData data) {
  PsiFile value = getValue();
  data.setPresentableText(value.getName());
  data.setIcon(IconDescriptorUpdaters.getIcon(value, Iconable.ICON_FLAG_READ_STATUS));

  VirtualFile file = getVirtualFile();
  if (file != null && file.is(VFileProperty.SYMLINK)) {
    String target = file.getCanonicalPath();
    if (target == null) {
      data.setAttributesKey(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
      data.setTooltip(CommonBundle.message("vfs.broken.link"));
    }
    else {
      data.setTooltip(FileUtil.toSystemDependentName(target));
    }
  }
}
 
Example #5
Source File: DescribeLibraryAction.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) {
  BlazeProjectData blazeProjectData =
      BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (blazeProjectData == null) {
    return;
  }
  Library library = LibraryActionHelper.findLibraryForAction(e);
  if (library == null) {
    return;
  }
  BlazeJarLibrary blazeLibrary =
      LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library);
  if (blazeLibrary == null) {
    Messages.showErrorDialog(
        project, "Could not find this library in the project.", CommonBundle.getErrorTitle());
    return;
  }
  showLibraryDescription(project, blazeLibrary);
}
 
Example #6
Source File: WholeWestSingleConfigurableEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
protected void doAction(ActionEvent e) {
  try {
    if (myConfigurable.isModified()) {
      myConfigurable.apply();
      myChangesWereApplied = true;
      setCancelButtonText(CommonBundle.getCloseButtonText());
    }
  }
  catch (ConfigurationException ex) {
    if (myProject != null) {
      Messages.showMessageDialog(myProject, ex.getMessage(), ex.getTitle(), Messages.getErrorIcon());
    }
    else {
      Messages.showMessageDialog(myParentComponent, ex.getMessage(), ex.getTitle(), Messages.getErrorIcon());
    }
  }
}
 
Example #7
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 #8
Source File: DateFormatUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("Duplicates")
private static String composeInSomeTimeMessage(final Period period, final int n) {
  switch (period) {
    case DAY:
      return CommonBundle.message("date.format.in.n.days", n);
    case MINUTE:
      return CommonBundle.message("date.format.in.n.minutes", n);
    case HOUR:
      return CommonBundle.message("date.format.in.n.hours", n);
    case MONTH:
      return CommonBundle.message("date.format.in.n.months", n);
    case WEEK:
      return CommonBundle.message("date.format.in.n.weeks", n);
    default:
      return CommonBundle.message("date.format.in.n.years", n);
  }
}
 
Example #9
Source File: SingleConfigurableEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ApplyAction() {
  super(CommonBundle.getApplyButtonText());
  final Runnable updateRequest = new Runnable() {
    @Override
    public void run() {
      if (!SingleConfigurableEditor.this.isShowing()) return;
      try {
        ApplyAction.this.setEnabled(myConfigurable != null && myConfigurable.isModified());
      }
      catch (IndexNotReadyException ignored) {
      }
      addUpdateRequest(this);
    }
  };

  // invokeLater necessary to make sure dialog is already shown so we calculate modality state correctly.
  SwingUtilities.invokeLater(() -> addUpdateRequest(updateRequest));
}
 
Example #10
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 #11
Source File: FilterDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void doOKAction() {
  String errorMessage = null;
  if (noText(myNameField.getText())) {
    errorMessage = ToolsBundle.message("tools.filters.add.name.required.error");
  } else if (noText(myRegexpField.getText())) {
    errorMessage = ToolsBundle.message("tools.filters.add.regex.required.error");
  }

  if (errorMessage != null) {
    Messages.showMessageDialog(getContentPane(), errorMessage, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    return;
  }

  try {
    checkRegexp(myRegexpField.getText());
  } catch (InvalidExpressionException e) {
    Messages.showMessageDialog(getContentPane(), e.getMessage(), ToolsBundle.message("tools.filters.add.regex.invalid.title"), Messages.getErrorIcon());
    return;
  }
  super.doOKAction();
}
 
Example #12
Source File: ToggleReadOnlyAttributeAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(final AnActionEvent e){
  ApplicationManager.getApplication().runWriteAction(
    new Runnable(){
      public void run(){
        // Save all documents. We won't be able to save changes to the files that became read-only afterwards.
        FileDocumentManager.getInstance().saveAllDocuments();

        try {
          VirtualFile[] files=getFiles(e.getDataContext());
          for (VirtualFile file : files) {
            ReadOnlyAttributeUtil.setReadOnlyAttribute(file, file.isWritable());
          }
        }
        catch(IOException exc){
          Project project = e.getData(CommonDataKeys.PROJECT);
          Messages.showMessageDialog(
            project,
            exc.getMessage(),
            CommonBundle.getErrorTitle(),Messages.getErrorIcon()
          );
        }
      }
    }
  );
}
 
Example #13
Source File: ConfirmationDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean requestForConfirmation(@Nonnull VcsShowConfirmationOption option,
                                             @Nonnull Project project,
                                             @Nonnull String message,
                                             @Nonnull String title,
                                             @Nullable Icon icon,
                                             @Nullable String okActionName,
                                             @Nullable String cancelActionName) {
  if (option.getValue() == VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY) return false;
  final ConfirmationDialog dialog = new ConfirmationDialog(project, message, title, icon, option, okActionName, cancelActionName);
  if (!option.isPersistent()) {
    dialog.setDoNotAskOption(null);
  }
  else {
    dialog.setDoNotShowAgainMessage(CommonBundle.message("dialog.options.do.not.ask"));
  }
  return dialog.showAndGet();
}
 
Example #14
Source File: HaxeRestoreReferencesDialog.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  final JPanel panel = new JPanel(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP));
  myList = new JBList((Object[])myNamedElements);
  myList.setCellRenderer(new FQNameCellRenderer());
  panel.add(ScrollPaneFactory.createScrollPane(myList), BorderLayout.CENTER);

  panel.add(new JBLabel(CodeInsightBundle.message("dialog.paste.on.import.text"), SMALL, BRIGHTER), BorderLayout.NORTH);

  final JPanel buttonPanel = new JPanel(new VerticalFlowLayout());
  final JButton okButton = new JButton(CommonBundle.getOkButtonText());
  getRootPane().setDefaultButton(okButton);
  buttonPanel.add(okButton);
  final JButton cancelButton = new JButton(CommonBundle.getCancelButtonText());
  buttonPanel.add(cancelButton);

  panel.setPreferredSize(new Dimension(500, 400));

  return panel;
}
 
Example #15
Source File: NewProjectAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
protected JPanel createSouthPanel() {
  JPanel buttonsPanel = new JPanel(new GridLayout(1, 2, SystemInfo.isMacOSLeopard ? 0 : 5, 0));

  myCancelButton = new JButton(CommonBundle.getCancelButtonText());
  myCancelButton.addActionListener(e -> doCancelAction());

  buttonsPanel.add(myCancelButton);

  myOkButton = new JButton(CommonBundle.getOkButtonText()) {
    @Override
    public boolean isDefaultButton() {
      return true;
    }
  };
  myOkButton.setEnabled(false);

  myOkButton.addActionListener(e -> doOkAction());
  buttonsPanel.add(myOkButton);

  return JBUI.Panels.simplePanel().addToRight(buttonsPanel);
}
 
Example #16
Source File: FindUsagesAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
static void chooseAmbiguousTargetAndPerform(@Nonnull final Project project, final Editor editor, @Nonnull PsiElementProcessor<PsiElement> processor) {
  if (editor == null) {
    Messages.showMessageDialog(project, FindBundle.message("find.no.usages.at.cursor.error"), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
  }
  else {
    int offset = editor.getCaretModel().getOffset();
    boolean chosen = GotoDeclarationAction.chooseAmbiguousTarget(editor, offset, processor, FindBundle.message("find.usages.ambiguous.title"), null);
    if (!chosen) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
          HintManager.getInstance().showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
        }
      }, project.getDisposed());
    }
  }
}
 
Example #17
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 #18
Source File: ShowSettingsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  if (SystemInfo.isMac && e.getPlace().equals(ActionPlaces.MAIN_MENU)) {
    // It's called from Preferences in App menu.
    e.getPresentation().setVisible(false);
  }
  if (e.getPlace().equals(ActionPlaces.WELCOME_SCREEN)) {
    e.getPresentation().setText(CommonBundle.settingsTitle());
  }
}
 
Example #19
Source File: Messages.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void makeCurrentMessageDialogGoAway(@Nonnull Window[] checkWindows) {
  for (Window w : checkWindows) {
    JDialog dialog = w instanceof JDialog ? (JDialog)w : null;
    if (dialog == null || !dialog.isModal()) continue;
    JButton cancelButton =
            UIUtil.uiTraverser(dialog.getRootPane()).filter(JButton.class).filter(b -> CommonBundle.getCancelButtonText().equals(b.getText())).first();
    if (cancelButton != null) cancelButton.doClick();
  }
}
 
Example #20
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 #21
Source File: ChangeListViewerDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void initDialog(final Project project, final CommittedChangeList changeList) {
  myProject = project;
  myChangeList = changeList;
  final Collection<Change> changes = myChangeList.getChanges();
  myChanges = changes.toArray(new Change[changes.size()]);

  setTitle(VcsBundle.message("dialog.title.changes.browser"));
  setCancelButtonText(CommonBundle.message("close.action.name"));
  setModal(false);

  init();
}
 
Example #22
Source File: ProjectLoadingErrorsNotifierImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void fireNotifications() {
  final MultiMap<ConfigurationErrorType, ConfigurationErrorDescription> descriptionsMap = new MultiMap<ConfigurationErrorType, ConfigurationErrorDescription>();
  synchronized (myLock) {
    if (myErrors.isEmpty()) return;
    descriptionsMap.putAllValues(myErrors);
    myErrors.clear();
  }

  for (final ConfigurationErrorType type : descriptionsMap.keySet()) {
    final Collection<ConfigurationErrorDescription> descriptions = descriptionsMap.get(type);
    if (descriptions.isEmpty()) continue;

    final String invalidElements = getInvalidElementsString(type, descriptions);
    final String errorText = ProjectBundle.message("error.message.configuration.cannot.load") + " " + invalidElements + " <a href=\"\">Details...</a>";

    Notifications.Bus.notify(new Notification("Project Loading Error", "Error Loading Project", errorText, NotificationType.ERROR, new NotificationListener() {
      @Override
      public void hyperlinkUpdate(@Nonnull Notification notification, @Nonnull HyperlinkEvent event) {
        final List<ConfigurationErrorDescription> validDescriptions = ContainerUtil.findAll(descriptions, new Condition<ConfigurationErrorDescription>() {
          @Override
          public boolean value(ConfigurationErrorDescription errorDescription) {
            return errorDescription.isValid();
          }
        });
        RemoveInvalidElementsDialog.showDialog(myProject, CommonBundle.getErrorTitle(), type, invalidElements, validDescriptions);

        notification.expire();
      }
    }), myProject);
  }

}
 
Example #23
Source File: ExportSettingsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String getComponentPresentableName(@Nonnull State state, @Nonnull Class<?> aClass) {
  String defaultName = state.name();
  String resourceBundleName;

  PluginDescriptor pluginDescriptor = null;
  ClassLoader classLoader = aClass.getClassLoader();

  if(classLoader instanceof PluginClassLoader) {
    pluginDescriptor = PluginManager.getPlugin(((PluginClassLoader)classLoader).getPluginId());
  }

  if (pluginDescriptor != null && !PluginManagerCore.CORE_PLUGIN.equals(pluginDescriptor.getPluginId())) {
    resourceBundleName = pluginDescriptor.getResourceBundleBaseName();
  }
  else {
    resourceBundleName = OptionsBundle.PATH_TO_BUNDLE;
  }

  if (resourceBundleName == null) {
    return defaultName;
  }

  if (classLoader != null) {
    ResourceBundle bundle = AbstractBundle.getResourceBundle(resourceBundleName, classLoader);
    if (bundle != null) {
      return CommonBundle.messageOrDefault(bundle, "exportable." + defaultName + ".presentable.name", defaultName);
    }
  }
  return defaultName;
}
 
Example #24
Source File: ConfirmationDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ConfirmationDialog(Project project,
                          final String message,
                          String title,
                          final Icon icon,
                          final VcsShowConfirmationOption option,
                          @javax.annotation.Nullable String okActionName,
                          @Nullable String cancelActionName) {
  super(project, message, title, icon);
  myOption = option;
  myOkActionName = okActionName != null ? okActionName : CommonBundle.getYesButtonText();
  myCancelActionName = cancelActionName != null ? cancelActionName : CommonBundle.getNoButtonText();
  init();
}
 
Example #25
Source File: CSharpCopyClassHandlerDelegate.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private static void doCopy(@Nonnull CSharpTypeDeclaration typeDeclaration, @Nullable PsiDirectory defaultTargetDirectory, Project project)
{
	PsiDirectory targetDirectory;
	String newName;
	boolean openInEditor;
	VirtualFile virtualFile = PsiUtilCore.getVirtualFile(typeDeclaration);
	CopyFilesOrDirectoriesDialog dialog = new CopyFilesOrDirectoriesDialog(new PsiElement[]{typeDeclaration.getContainingFile()}, defaultTargetDirectory, project, false);
	if(dialog.showAndGet())
	{
		newName = dialog.getNewName();
		targetDirectory = dialog.getTargetDirectory();
		openInEditor = dialog.openInEditor();
	}
	else
	{
		return;
	}

	if(targetDirectory != null)
	{
		PsiManager manager = PsiManager.getInstance(project);
		try
		{
			if(virtualFile.isDirectory())
			{
				PsiFileSystemItem psiElement = manager.findDirectory(virtualFile);
				MoveFilesOrDirectoriesUtil.checkIfMoveIntoSelf(psiElement, targetDirectory);
			}
		}
		catch(IncorrectOperationException e)
		{
			CommonRefactoringUtil.showErrorHint(project, null, e.getMessage(), CommonBundle.getErrorTitle(), null);
			return;
		}

		CommandProcessor.getInstance().executeCommand(project, () -> doCopy(typeDeclaration, newName, targetDirectory, false, openInEditor), RefactoringBundle.message("copy.handler.copy.files" +
				".directories"), null);
	}
}
 
Example #26
Source File: MultipleFileMergeDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
protected Action getCancelAction() {
  Action action = super.getCancelAction();
  action.putValue(Action.NAME, CommonBundle.getCloseButtonText());
  return action;
}
 
Example #27
Source File: StatisticsManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean createStoreFolder(){
  File homeFile = new File(STORE_PATH);
  if (!homeFile.exists()){
    if (!homeFile.mkdirs()){
      Messages.showMessageDialog(
              IdeBundle.message("error.saving.statistic.failed.to.create.folder", STORE_PATH),
              CommonBundle.getErrorTitle(),
              Messages.getErrorIcon()
      );
      return false;
    }
  }
  return true;
}
 
Example #28
Source File: IgnoreWhiteSpacesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public JComponent createCustomComponent(final Presentation presentation) {
  JPanel panel = new JPanel(new BorderLayout());
  final JLabel label = new JLabel(CommonBundle.message("comparison.ignore.whitespace.acton.name"));
  label.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4));
  panel.add(label, BorderLayout.WEST);
  panel.add(super.createCustomComponent(presentation), BorderLayout.CENTER);
  return panel;
}
 
Example #29
Source File: DirDiffTableModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean confirmDeletion(int count) {
  return MessageDialogBuilder.yesNo("Confirm Delete", "Delete " + count + " items?").project(myProject).yesText("Delete").noText(CommonBundle.message("button.cancel")).doNotAsk(
          new DialogWrapper.DoNotAskOption() {
            @Override
            public boolean isToBeShown() {
              return WarnOnDeletion.isWarnWhenDeleteItems();
            }

            @Override
            public void setToBeShown(boolean value, int exitCode) {
              WarnOnDeletion.setWarnWhenDeleteItems(value);
            }

            @Override
            public boolean canBeHidden() {
              return true;
            }

            @Override
            public boolean shouldSaveOptionsOnCancel() {
              return true;
            }

            @Nonnull
            @Override
            public String getDoNotShowMessage() {
              return "Do not ask me again";
            }
          }).show() == Messages.YES;
}
 
Example #30
Source File: BinaryMergeRequestImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void applyResult(@Nonnull MergeResult result) {
  final byte[] applyContent;
  switch (result) {
    case CANCEL:
      applyContent = myOriginalContent;
      break;
    case LEFT:
      applyContent = ThreeSide.LEFT.select(myByteContents);
      break;
    case RIGHT:
      applyContent = ThreeSide.RIGHT.select(myByteContents);
      break;
    case RESOLVED:
      applyContent = null;
      break;
    default:
      throw new IllegalArgumentException(result.toString());
  }

  if (applyContent != null) {
    new WriteCommandAction.Simple(null) {
      @Override
      protected void run() throws Throwable {
        try {
          VirtualFile file = myFile.getFile();
          if (!DiffUtil.makeWritable(myProject, file)) throw new IOException("File is read-only: " + file.getPresentableName());
          file.setBinaryContent(applyContent);
        }
        catch (IOException e) {
          LOG.error(e);
          Messages.showErrorDialog(myProject, "Can't apply result", CommonBundle.getErrorTitle());
        }
      }
    }.execute();
  }

  if (myApplyCallback != null) myApplyCallback.consume(result);
}