/** * @param source Source string * @param chars Symbols to be trimmed * @return string without all specified chars at the end. For example, * <code>chopTrailingChars("c:\\my_directory\\//\\",new char[]{'\\'}) is <code>"c:\\my_directory\\//"</code>, * <code>chopTrailingChars("c:\\my_directory\\//\\",new char[]{'\\','/'}) is <code>"c:\my_directory"</code>. * Actually this method can be used to normalize file names to chop trailing separator chars. */ public static String chopTrailingChars(String source, char[] chars) { StringBuilder sb = new StringBuilder(source); while (true) { boolean atLeastOneCharWasChopped = false; for (int i = 0; i < chars.length && sb.length() > 0; i++) { if (sb.charAt(sb.length() - 1) == chars[i]) { sb.deleteCharAt(sb.length() - 1); atLeastOneCharWasChopped = true; } } if (!atLeastOneCharWasChopped) { break; } } return sb.toString(); }
@Override public void run(ContinuationContext context) { final StringBuilder message = new StringBuilder().append("Theirs changes merged for ").append(myOldPresentation); VcsBalloonProblemNotifier.showOverChangesView( myVcs.getProject(), message.toString(), MessageType.INFO); if (!myWarnings.isEmpty()) { AbstractVcsHelper.getInstance(myVcs.getProject()) .showErrors(myWarnings, TreeConflictRefreshablePanel.TITLE); } }
@SuppressWarnings("StringConcatenationInsideStringBufferAppend") @NotNull private static String makeDescription( @NotNull Collection<VcsRootError> unregisteredRoots, @NotNull Collection<VcsRootError> invalidRoots) { Function<VcsRootError, String> rootToDisplayableString = rootError -> { if (rootError.getMapping().equals(VcsDirectoryMapping.PROJECT_CONSTANT)) { return StringUtil.escapeXml(rootError.getMapping()); } return FileUtil.toSystemDependentName(rootError.getMapping()); }; StringBuilder description = new StringBuilder(); if (!invalidRoots.isEmpty()) { if (invalidRoots.size() == 1) { VcsRootError rootError = invalidRoots.iterator().next(); String vcsName = rootError.getVcsKey().getName(); description.append( String.format( "The directory %s is registered as a %s root, but no %s repositories were found there.", rootToDisplayableString.fun(rootError), vcsName, vcsName)); } else { description.append( "The following directories are registered as VCS roots, but they are not: <br/>" + StringUtil.join(invalidRoots, rootToDisplayableString, "<br/>")); } description.append("<br/>"); } if (!unregisteredRoots.isEmpty()) { if (unregisteredRoots.size() == 1) { VcsRootError unregisteredRoot = unregisteredRoots.iterator().next(); description.append( String.format( "The directory %s is under %s, but is not registered in the Settings.", rootToDisplayableString.fun(unregisteredRoot), unregisteredRoot.getVcsKey().getName())); } else { description.append( "The following directories are roots of VCS repositories, but they are not registered in the Settings: <br/>" + StringUtil.join(unregisteredRoots, rootToDisplayableString, "<br/>")); } description.append("<br/>"); } String add = invalidRoots.isEmpty() ? "<a href='add'>Add " + pluralize("root", unregisteredRoots.size()) + "</a> " : ""; String configure = "<a href='configure'>Configure</a>"; String ignore = invalidRoots.isEmpty() ? " <a href='ignore'>Ignore</a>" : ""; description.append(add + configure + ignore); return description.toString(); }
/** * Show errors as popup and as messages in vcs view. * * @param list a list of errors * @param action an action */ public void showErrors(@NotNull List<VcsException> list, @NotNull String action) { if (list.size() > 0) { StringBuilder buffer = new StringBuilder(); buffer.append("\n"); buffer.append(GitBundle.message("error.list.title", action)); for (final VcsException exception : list) { buffer.append("\n"); buffer.append(exception.getMessage()); } final String msg = buffer.toString(); UIUtil.invokeLaterIfNeeded( new Runnable() { @Override public void run() { Messages.showErrorDialog(myProject, msg, GitBundle.getString("error.dialog.title")); } }); } }