From b3f2d2939828fd2be305b99552227b740cb97488 Mon Sep 17 00:00:00 2001 From: Alexander Kirillin Date: Mon, 4 Jun 2012 20:28:30 +0400 Subject: [PATCH] non-prefix matching in goto... actions --- .../actions/InspectionListCellRenderer.java | 6 ++++++ .../ide/util/gotoByName/ChooseByNameBase.java | 10 ++++++++-- .../gotoByName/ContributorsBasedGotoByModel.java | 7 +------ .../ide/util/gotoByName/GotoFileCellRenderer.java | 12 +++++++++--- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/InspectionListCellRenderer.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/InspectionListCellRenderer.java index 92edbe05a58d..8033086b6bb8 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/InspectionListCellRenderer.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/InspectionListCellRenderer.java @@ -17,6 +17,7 @@ package com.intellij.codeInspection.actions; import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; +import com.intellij.ide.util.gotoByName.ChooseByNameBase; import com.intellij.lang.Language; import com.intellij.openapi.fileTypes.LanguageFileType; import com.intellij.openapi.fileTypes.UnknownFileType; @@ -82,6 +83,11 @@ public class InspectionListCellRenderer extends DefaultListCellRenderer implemen right.add(icon, BorderLayout.EAST); panel.add(right, BorderLayout.EAST); } + else { + // E.g. "..." item + Component component = super.getListCellRendererComponent(list, value, index, sel, focus); + return value == ChooseByNameBase.NON_PREFIX_SEPARATOR ? ChooseByNameBase.renderNonPrefixSeparatorComponent(component) : component; + } return panel; } diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index 0b746ecfd268..680db9fdb11f 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -410,8 +410,9 @@ public abstract class ChooseByNameBase { curElements.add(psi); } } - else if (object == NON_PREFIX_SEPARATOR) + else if (object == NON_PREFIX_SEPARATOR) { curElements = nonPrefixMatchElements; + } } return new PsiElement[][]{PsiUtilCore.toPsiElementArray(prefixMatchElements), PsiUtilCore.toPsiElementArray(nonPrefixMatchElements)}; } @@ -1398,7 +1399,12 @@ public abstract class ChooseByNameBase { } private static final String EXTRA_ELEM = "..."; - static final String NON_PREFIX_SEPARATOR = "non-prefix matches:"; + public static final String NON_PREFIX_SEPARATOR = "non-prefix matches:"; + + public static Component renderNonPrefixSeparatorComponent(Component component) { + component.setFont(component.getFont().deriveFont(Font.PLAIN, component.getFont().getSize() - 2)); + return component; + } private class CalcElementsThread implements Runnable { private final String myPattern; diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ContributorsBasedGotoByModel.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ContributorsBasedGotoByModel.java index f7bcd30ee03c..01eda277a3cf 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ContributorsBasedGotoByModel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ContributorsBasedGotoByModel.java @@ -58,12 +58,7 @@ public abstract class ContributorsBasedGotoByModel implements ChooseByNameModel @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - - if (value == ChooseByNameBase.NON_PREFIX_SEPARATOR) { - component.setFont(component.getFont().deriveFont(Font.BOLD, component.getFont().getSize() - 2)); - } - - return component; + return value == ChooseByNameBase.NON_PREFIX_SEPARATOR ? ChooseByNameBase.renderNonPrefixSeparatorComponent(component) : component; } }; } diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoFileCellRenderer.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoFileCellRenderer.java index fba16cac1ee9..ec6512bd4126 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoFileCellRenderer.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoFileCellRenderer.java @@ -42,15 +42,21 @@ public class GotoFileCellRenderer extends PsiElementListCellRenderer { public GotoFileCellRenderer(int maxSize) { myMaxWidth = maxSize; - EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); - Font editorFont = new Font(scheme.getEditorFontName(), Font.PLAIN, scheme.getEditorFontSize()); - setFont(editorFont); } public String getElementText(PsiFile element) { return element.getName(); } + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); + Font editorFont = new Font(scheme.getEditorFontName(), Font.PLAIN, scheme.getEditorFontSize()); + setFont(editorFont); + return value == ChooseByNameBase.NON_PREFIX_SEPARATOR ? ChooseByNameBase.renderNonPrefixSeparatorComponent(component) : component; + } + protected String getContainerText(PsiFile element, String name) { final PsiDirectory psiDirectory = element.getContainingDirectory(); if (psiDirectory == null) return null;