From 67dbff6d5fada852d0e25abd9257cc752c1f6b8a Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Wed, 23 Oct 2013 22:50:15 +0400 Subject: [PATCH] speed-search highlights in standard trees --- .../intellij/ide/util/FileStructurePopup.java | 25 +---------------- .../ide/util/treeView/NodeRenderer.java | 28 +++++++------------ .../ui/speedSearch/SpeedSearchUtil.java | 6 ++-- 3 files changed, 15 insertions(+), 44 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java index d3186cf4d17e..f43a95c34a0f 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java +++ b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java @@ -186,30 +186,7 @@ public class FileStructurePopup implements Disposable { myTree = new FileStructureTree(myTreeStructure.getRootElement(), Registry.is("fast.tree.expand.in.structure.view")); - myTree.setCellRenderer(new NodeRenderer() { - @Override - protected void doAppend(@NotNull @Nls String fragment, - @NotNull SimpleTextAttributes attributes, - boolean isMainText, - boolean selected) { - if (!isMainText) { - super.doAppend(fragment, attributes, isMainText, selected); - } - else { - SpeedSearchUtil.appendFragmentsForSpeedSearch(myTree, fragment, attributes, selected, this); - } - } - - @Override - public void doAppend(@NotNull String fragment, @NotNull SimpleTextAttributes attributes, boolean selected) { - SpeedSearchUtil.appendFragmentsForSpeedSearch(myTree, fragment, attributes, selected, this); - } - - @Override - public void doAppend(String fragment, boolean selected) { - SpeedSearchUtil.appendFragmentsForSpeedSearch(myTree, fragment, SimpleTextAttributes.REGULAR_ATTRIBUTES, selected, this); - } - }); + myTree.setCellRenderer(new NodeRenderer()); mySpeedSearch = new MyTreeSpeedSearch(); mySpeedSearch.setComparator(new SpeedSearchComparator(false, true)); diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/NodeRenderer.java b/platform/platform-api/src/com/intellij/ide/util/treeView/NodeRenderer.java index 6eef7bc3474f..60ee6b919ed1 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/NodeRenderer.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/NodeRenderer.java @@ -25,7 +25,7 @@ import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.ColoredTreeCellRenderer; import com.intellij.ui.SimpleTextAttributes; -import org.jetbrains.annotations.Nls; +import com.intellij.ui.speedSearch.SpeedSearchUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -58,7 +58,7 @@ public class NodeRenderer extends ColoredTreeCellRenderer { if (coloredText.isEmpty()) { String text = tree.convertValueToText(value.toString(), selected, expanded, leaf, row, hasFocus); SimpleTextAttributes simpleTextAttributes = getSimpleTextAttributes(node, presentation.getForcedTextForeground() != null ? presentation.getForcedTextForeground() : color); - doAppend(text, simpleTextAttributes, selected); + append(text, simpleTextAttributes, selected); } else { boolean first = true; @@ -78,14 +78,15 @@ public class NodeRenderer extends ColoredTreeCellRenderer { } first = false; } - doAppend(each.getText(), simpleTextAttributes, true); + // treat grayed text as non-main + boolean isMain = simpleTextAttributes != SimpleTextAttributes.GRAYED_ATTRIBUTES; + append(each.getText(), simpleTextAttributes, isMain); } } final String location = presentation.getLocationString(); if (!StringUtil.isEmpty(location)) { - doAppend(presentation.getLocationPrefix() + location + presentation.getLocationSuffix(), - SimpleTextAttributes.GRAY_ATTRIBUTES, false, selected); + append(presentation.getLocationPrefix() + location + presentation.getLocationSuffix(), SimpleTextAttributes.GRAY_ATTRIBUTES, false); } setToolTipText(presentation.getTooltip()); @@ -99,23 +100,14 @@ public class NodeRenderer extends ColoredTreeCellRenderer { if (text == null) { text = ""; } - doAppend(text, selected); + append(text); setToolTipText(null); } + if (!AbstractTreeUi.isLoadingNode(value)) { + SpeedSearchUtil.applySpeedSearchHighlighting(tree, this, true, selected); + } } - protected void doAppend(@NotNull @Nls String fragment, @NotNull SimpleTextAttributes attributes, boolean isMainText, boolean isSelected) { - append(fragment, attributes, isMainText); - } - - public void doAppend(@NotNull String fragment, @NotNull SimpleTextAttributes attributes, boolean isSelected) { - append(fragment, attributes); - } - - public void doAppend(String fragment, boolean isSelected) { - append(fragment); - } - @NotNull protected EditorColorsScheme getColorsScheme() { return EditorColorsManager.getInstance().getGlobalScheme(); diff --git a/platform/platform-api/src/com/intellij/ui/speedSearch/SpeedSearchUtil.java b/platform/platform-api/src/com/intellij/ui/speedSearch/SpeedSearchUtil.java index 961a916ba6d5..e88616a28938 100644 --- a/platform/platform-api/src/com/intellij/ui/speedSearch/SpeedSearchUtil.java +++ b/platform/platform-api/src/com/intellij/ui/speedSearch/SpeedSearchUtil.java @@ -43,10 +43,12 @@ public final class SpeedSearchUtil { public static void applySpeedSearchHighlighting(@NotNull JComponent speedSearchEnabledComponent, @NotNull SimpleColoredComponent coloredComponent, - boolean mainOnly, + boolean mainTextOnly, boolean selected) { SpeedSearchSupply speedSearch = SpeedSearchSupply.getSupply(speedSearchEnabledComponent); - Iterable ranges = speedSearch == null ? null : speedSearch.matchingFragments(coloredComponent.getCharSequence(mainOnly).toString()); + // The bad thing is that SpeedSearch model is decoupled from UI presentation so we don't know the real matched text. + // Our best guess is to get strgin from the ColoredComponent. We can only provide main-text-only option. + Iterable ranges = speedSearch == null ? null : speedSearch.matchingFragments(coloredComponent.getCharSequence(mainTextOnly).toString()); Iterator rangesIterator = ranges != null ? ranges.iterator() : null; if (rangesIterator == null || !rangesIterator.hasNext()) return; Color bg = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();