diff --git a/platform/editor-ui-api/src/com/intellij/ide/util/treeView/PresentableNodeDescriptor.java b/platform/editor-ui-api/src/com/intellij/ide/util/treeView/PresentableNodeDescriptor.java index 1f45eb33542c..6b264f157cfa 100644 --- a/platform/editor-ui-api/src/com/intellij/ide/util/treeView/PresentableNodeDescriptor.java +++ b/platform/editor-ui-api/src/com/intellij/ide/util/treeView/PresentableNodeDescriptor.java @@ -10,6 +10,7 @@ import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; import com.intellij.util.concurrency.annotations.RequiresReadLock; import com.intellij.util.ui.StartupUiUtil; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -222,13 +223,23 @@ public abstract class PresentableNodeDescriptor extends NodeDescriptor { } public @NlsSafe String getName() { - if (!getPresentation().getColoredText().isEmpty()) { + String result = getColoredTextAsPlainText(getPresentation()); + if (result != null) { + return result; + } + return myName; + } + + @ApiStatus.Internal + @Nullable + protected static String getColoredTextAsPlainText(PresentationData presentation) { + if (!presentation.getColoredText().isEmpty()) { StringBuilder result = new StringBuilder(); - for (ColoredFragment each : getPresentation().getColoredText()) { + for (ColoredFragment each : presentation.getColoredText()) { result.append(each.getText()); } return result.toString(); } - return myName; + return null; } } diff --git a/platform/platform-api/src/com/intellij/ui/treeStructure/SimpleNode.java b/platform/platform-api/src/com/intellij/ui/treeStructure/SimpleNode.java index ff90e21056f4..36629679edf6 100644 --- a/platform/platform-api/src/com/intellij/ui/treeStructure/SimpleNode.java +++ b/platform/platform-api/src/com/intellij/ui/treeStructure/SimpleNode.java @@ -17,9 +17,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.awt.event.InputEvent; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; public abstract class SimpleNode extends PresentableNodeDescriptor implements ComparableObject, LeafState.Supplier { @@ -79,23 +76,38 @@ public abstract class SimpleNode extends PresentableNodeDescriptor imple } if (newElement == null) return; - Color oldColor = myColor; - String oldName = myName; - Icon oldIcon = getIcon(); - List oldFragments = new ArrayList<>(presentation.getColoredText()); - - myColor = UIUtil.getTreeForeground(); - doUpdate(presentation); - myName = getName(); - presentation.setPresentableText(myName); + fillFallbackProperties(presentation); + } - presentation.setChanged(!Arrays.equals(new Object[]{getIcon(), myName, oldFragments, myColor}, - new Object[]{oldIcon, oldName, oldFragments, oldColor})); + private void fillFallbackProperties(PresentationData presentation) { + fillFallbackText(presentation); + fillFallbackIcon(presentation); + fillFallbackColor(presentation); + } - presentation.setForcedTextForeground(myColor); - presentation.setIcon(getIcon()); + private void fillFallbackText(PresentationData presentation) { + var text = getColoredTextAsPlainText(presentation); + if (text == null) { + text = presentation.getPresentableText(); + } + if (text == null) { + text = myName; + } + presentation.setPresentableText(text); + } + + private void fillFallbackIcon(PresentationData presentation) { + if (presentation.getIcon(false) == null) { + presentation.setIcon(myClosedIcon); + } + } + + private void fillFallbackColor(PresentationData presentation) { + if (presentation.getForcedTextForeground() == null) { + presentation.setForcedTextForeground(myColor == null ? UIUtil.getTreeForeground() : myColor); + } } /**