May I modify the color of the locationString in ProjectViewNodeDecorator?

Answered
1
5 comments

Thanks for your response. 

Upon reviewing the snippet you provided, it appears that I can utilize coloredText.

I will try later to see if it is feasible.

0

Thank you very much. I finally used the addText method to achieve colored text.

1

Hi,

I think the future readers would appreciate the code snippet solving this. Please share it if you can.

0

Of course, Just need to implement the decorating method of ProjectViewNodeDecorator and use the presentation.addText method within that method.

override fun decorate(node: ProjectViewNode<*>?, presentation: PresentationData?) {
    val text = presentation?.presentableText
    
    var forcedForeground = presentation?.forcedTextForeground
    val textAttributesKey = presentation?.textAttributesKey
    val textAttributes = EditorColorsManager.getInstance().schemeForCurrentUITheme.getAttributes(textAttributesKey)
    if (forcedForeground == null) forcedForeground = textAttributes?.foregroundColor
    if (forcedForeground == null) forcedForeground = EditorColorsManager.getInstance().schemeForCurrentUITheme.defaultForeground;
    val plainTextAttributes = SimpleTextAttributes(null, forcedForeground, null, 0);
    presentation?.addText(text, plainTextAttributes);

    val percent = (changes.toDouble() / totalChanges.toDouble() * 100).let {
        if (it >= 1f) it.toInt().toString() else String.format("%.2f", it)
    }

    val location = "YOUR COLORED TEXT"
    val simpleAttributes = SimpleTextAttributes(
        STYLE_PLAIN,
        Color.RED
    );
    presentation?.addText(
        presentation?.getLocationPrefix() + location + presentation?.getLocationSuffix(),
        simpleAttributes
    );
}
2

Please sign in to leave a comment.