/**
   * Appends a string with styles to the {@link StyledString}.
   *
   * @param string the string to append
   * @return returns a reference to this object
   */
  public StyledString append(StyledString string) {
    if (string.length() == 0) {
      return this;
    }

    int offset = fBuffer.length();
    fBuffer.append(string.toString());

    List otherRuns = string.fStyleRuns;
    if (otherRuns != null && !otherRuns.isEmpty()) {
      for (int i = 0; i < otherRuns.size(); i++) {
        StyleRun curr = (StyleRun) otherRuns.get(i);
        if (i == 0 && curr.offset != 0) {
          appendStyleRun(null, offset); // appended string will
          // start with the default
          // color
        }
        appendStyleRun(curr.style, offset + curr.offset);
      }
    } else {
      appendStyleRun(null, offset); // appended string will start with
      // the default color
    }
    return this;
  }
  @Override
  public StyledString getStyledDisplayString(
      IDocument document, int offset, BoldStylerProvider boldStylerProvider) {
    // Extension enabled with enableColoredLabels(true); on PyContentAssistant.
    String[] strs = PySelection.getActivationTokenAndQual(document, offset, false);
    if (strs[1].length() == 0 && (strs[0].length() == 0 || strs[0].endsWith("."))) {
      StyledString styledString = new StyledString(getDisplayString());
      return styledString;
    }
    String qualifier = strs[1];

    final boolean useSubstringMatchInCodeCompletion =
        PyCodeCompletionPreferencesPage.getUseSubstringMatchInCodeCompletion();
    String original = getDisplayString();
    // Qualifier is everything after " - ".
    int index = original.indexOf(" - ");
    String strBeforeQualifier;
    if (index != -1) {
      strBeforeQualifier = original.substring(0, index);
    } else {
      strBeforeQualifier = original;
    }

    StyledString styledString = new StyledString();
    if (useSubstringMatchInCodeCompletion) {
      int i = strBeforeQualifier.toLowerCase().indexOf(qualifier.toLowerCase());
      if (i < 0) {
        styledString.append(strBeforeQualifier);
      } else {
        styledString.append(strBeforeQualifier.substring(0, i));
        styledString.append(
            strBeforeQualifier.substring(i, i + qualifier.length()),
            boldStylerProvider.getBoldStyler());
        styledString.append(
            strBeforeQualifier.substring(i + qualifier.length(), strBeforeQualifier.length()));
      }
    } else {
      styledString.append(strBeforeQualifier);
    }
    if (styledString.length() < original.length()) {
      styledString.append(original.substring(styledString.length()), StyledString.QUALIFIER_STYLER);
    }
    return styledString;
  }
Пример #3
0
 @Override
 public StyledString getStyledText(Object element) {
   StyledString string =
       CElementLabels.getStyledTextLabel(
           element, (evaluateTextFlags(element) | CElementLabels.COLORIZE));
   if (string.length() == 0 && (element instanceof IStorage)) {
     string = new StyledString(fStorageLabelProvider.getText(element));
   }
   String decorated = decorateText(string.getString(), element);
   if (decorated != null) {
     return StyledCellLabelProvider.styleDecoratedString(
         decorated, StyledString.DECORATIONS_STYLER, string);
   }
   return string;
 }
Пример #4
0
  private StyledString literalNames(List<? extends EObject> exprs) {
    StyledString result = new StyledString();
    boolean first = true;
    for (EObject expr : exprs) {
      Object label = doGetText(expr);
      if (first) first = false;
      else result.append(", ");

      if (label instanceof String) result.append((String) label);
      else if (label instanceof StyledString) result.append((StyledString) label);
      else result.append("?");
    }
    // truncate long list (bad way, destroys individual styles)
    if (result.length() > LABEL_LIMIT)
      return new StyledString(result.getString().substring(0, LABEL_LIMIT) + "...");
    return result;
  }