speed-search highlights in standard trees

This commit is contained in:
Gregory.Shrago
2013-10-23 22:52:04 +04:00
parent 049dd64491
commit 67dbff6d5f
3 changed files with 15 additions and 44 deletions
@@ -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));
@@ -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();
@@ -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<TextRange> 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<TextRange> ranges = speedSearch == null ? null : speedSearch.matchingFragments(coloredComponent.getCharSequence(mainTextOnly).toString());
Iterator<TextRange> rangesIterator = ranges != null ? ranges.iterator() : null;
if (rangesIterator == null || !rangesIterator.hasNext()) return;
Color bg = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();