Java Code Examples for com.intellij.openapi.util.text.StringUtil#shortenTextWithEllipsis()

The following examples show how to use com.intellij.openapi.util.text.StringUtil#shortenTextWithEllipsis() . 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: HaxeClassReference.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
private String getClassNameInternal(HaxeClassModel clazz) {
  if (clazz.haxeClass instanceof HaxeAnonymousType) {
    HaxeNamedComponent namedComponent = PsiTreeUtil.getParentOfType(clazz.haxeClass.getContext(), HaxeNamedComponent.class);
    if (namedComponent instanceof HaxeTypedefDeclaration) {
      final HaxeComponentName name = namedComponent.getComponentName();
      if (name != null) {
        return name.getText();
      }
    }
    final String formattedClassText = clazz.haxeClass.getText()
      .replaceAll("\\s{2,}+", " ")
      .replaceAll("\\{\\s", "{");

    return StringUtil.shortenTextWithEllipsis(formattedClassText,128,1);
  }
  return clazz.getName();
}
 
Example 2
Source File: LabelPainter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static String shortenRefName(@Nonnull String refName, @Nonnull FontMetrics fontMetrics, int availableWidth) {
  if (fontMetrics.stringWidth(refName) > availableWidth && refName.length() > MAX_LENGTH) {
    int separatorIndex = refName.indexOf(SEPARATOR);
    if (separatorIndex > TWO_DOTS.length()) {
      refName = TWO_DOTS + refName.substring(separatorIndex);
    }

    if (fontMetrics.stringWidth(refName) <= availableWidth) return refName;

    if (availableWidth > 0) {
      for (int i = refName.length(); i > MAX_LENGTH; i--) {
        String result = StringUtil.shortenTextWithEllipsis(refName, i, 0, THREE_DOTS);
        if (fontMetrics.stringWidth(result) <= availableWidth) {
          return result;
        }
      }
    }
    return StringUtil.shortenTextWithEllipsis(refName, MAX_LENGTH, 0, THREE_DOTS);
  }
  return refName;
}
 
Example 3
Source File: RecentLocationsDataModel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private String getBreadcrumbs(Project project, IdeDocumentHistoryImpl.PlaceInfo placeInfo) {
  RangeMarker rangeMarker = placeInfo.getCaretPosition();
  String fileName = placeInfo.getFile().getName();
  if (rangeMarker == null) {
    return fileName;
  }

  FileBreadcrumbsCollector collector = FileBreadcrumbsCollector.findBreadcrumbsCollector(project, placeInfo.getFile());
  if (collector == null) {
    return fileName;
  }

  Iterable<? extends Crumb> crumbs = collector.computeCrumbs(placeInfo.getFile(), rangeMarker.getDocument(), rangeMarker.getStartOffset(), true);

  if (!crumbs.iterator().hasNext()) {
    return fileName;
  }

  String breadcrumbsText = StringUtil.join(crumbs, o -> o.getText(), " > ");
  return StringUtil.shortenTextWithEllipsis(breadcrumbsText, 50, 0);
}
 
Example 4
Source File: DvcsStatusWidget.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
private void update() {
  myText = null;
  myTooltip = null;

  Project project = getProject();
  if (project == null || project.isDisposed()) return;
  T repository = guessCurrentRepository(project);
  if (repository == null) return;

  int maxLength = MAX_STRING.length() - 1; // -1, because there are arrows indicating that it is a popup
  myText = StringUtil.shortenTextWithEllipsis(getFullBranchName(repository), maxLength, 5);
  myTooltip = getToolTip(project);
  if (myStatusBar != null) {
    myStatusBar.updateWidget(ID());
  }
  rememberRecentRoot(repository.getRoot().getPath());
}
 
Example 5
Source File: L2Test.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Override
@NotNull
public String getTestName(boolean lowercaseFirstLetter) {
    String name = super.getTestName(lowercaseFirstLetter);
    name = StringUtil.shortenTextWithEllipsis(name.trim().replace(" ", "_"), 12, 6, "_");
    if (name.startsWith("_")) {
        name = name.substring(1);
    }
    return name;
}
 
Example 6
Source File: EditorNotificationPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nls
@Nonnull
@Override
public String getText() {
  String text = myLabel.getText();
  return StringUtil.isEmpty(text) ? EditorBundle.message("editor.notification.default.action.name") : StringUtil.shortenTextWithEllipsis(text, 50, 0);
}
 
Example 7
Source File: GraphTableController.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private String getArrowTooltipText(int commit, @Nullable Integer row) {
  VcsShortCommitDetails details;
  if (row != null && row >= 0) {
    details = myTable.getModel().getShortDetails(row); // preload rows around the commit
  }
  else {
    details = myLogData.getMiniDetailsGetter().getCommitData(commit, Collections.singleton(commit)); // preload just the commit
  }

  String balloonText = "";
  if (details instanceof LoadingDetails) {
    CommitId commitId = myLogData.getCommitId(commit);
    if (commitId != null) {
      balloonText = "Jump to commit" + " " + commitId.getHash().toShortString();
      if (myUi.isMultipleRoots()) {
        balloonText += " in " + commitId.getRoot().getName();
      }
    }
  }
  else {
    balloonText = "Jump to <b>\"" +
                  StringUtil.shortenTextWithEllipsis(details.getSubject(), 50, 0, "...") +
                  "\"</b> by " +
                  VcsUserUtil.getShortPresentation(details.getAuthor()) +
                  CommitPanel.formatDateTime(details.getAuthorTime());
  }
  return balloonText;
}
 
Example 8
Source File: MultipleValueFilterPopupComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
static String displayableText(@Nonnull Collection<String> values) {
  if (values.size() == 1) {
    return values.iterator().next();
  }
  return StringUtil.shortenTextWithEllipsis(StringUtil.join(values, "|"), MAX_FILTER_VALUE_LENGTH, 0, true);
}
 
Example 9
Source File: XAttachDebugger.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return title for `Attach to process` module window, which will be shown when choosing this debugger
 */
@Nullable
default String getDebuggerSelectedTitle() {
  String title = getDebuggerDisplayName();
  title = StringUtil.shortenTextWithEllipsis(title, 50, 0);
  return XDebuggerBundle.message("xdebugger.attach.popup.title", title);
}
 
Example 10
Source File: AttachToProcessActionBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public String getText(@Nonnull Project project) {
  String shortenedText = StringUtil.shortenTextWithEllipsis(myGroup.getItemDisplayText(project, myInfo, myDataHolder), 200, 0);
  int pid = myInfo.getPid();
  return (pid == -1 ? "" : pid + " ") + shortenedText;
}
 
Example 11
Source File: XLineBreakpointType.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@RequiredReadAction
@Override
public String getText() {
  return StringUtil.shortenTextWithEllipsis(myElement.getText(), 100, 0);
}