From 48b7c94f540b17fc6d382e86a04997cc69d0d21c Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Wed, 18 Dec 2019 12:10:10 +0300 Subject: [PATCH] IDEA-228306 Items in "Go to Test" and "Go to Implementations" popup use monospaced (editor) font GitOrigin-RevId: 64c222f9eb217f9afdaba0c5a83acc6c7d5169f3 --- .../navigation/GotoTargetHandler.java | 45 +++++++++++-------- .../GotoTestOrCodeHandler.java | 5 +++ 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoTargetHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoTargetHandler.java index dbffe9747da4..c282dae5effc 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoTargetHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/GotoTargetHandler.java @@ -74,6 +74,10 @@ public abstract class GotoTargetHandler implements CodeInsightActionHandler { @NonNls protected abstract String getFeatureUsedKey(); + protected boolean useEditorFont() { + return true; + } + @Nullable protected abstract GotoData getSourceAndTargetElements(Editor editor, PsiFile file); @@ -112,25 +116,26 @@ public abstract class GotoTargetHandler implements CodeInsightActionHandler { final IPopupChooserBuilder builder = JBPopupFactory.getInstance().createPopupChooserBuilder(allElements); final Ref usageView = new Ref<>(); - final JBPopup popup = builder.setNamerForFiltering(o -> { + builder.setNamerForFiltering(o -> { if (o instanceof AdditionalAction) { return ((AdditionalAction)o).getText(); } return getRenderer(o, gotoData).getElementText((PsiElement)o); - }). - setTitle(title). - setFont(EditorUtil.getEditorFont()). - setRenderer(new DefaultListCellRenderer() { - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - if (value == null) return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof AdditionalAction) { - return myActionElementRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - } - PsiElementListCellRenderer renderer = getRenderer(value, gotoData); - return renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + }).setTitle(title); + if (useEditorFont()) { + builder.setFont(EditorUtil.getEditorFont()); + } + builder.setRenderer(new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + if (value == null) return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if (value instanceof AdditionalAction) { + return myActionElementRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } - }). + PsiElementListCellRenderer renderer = getRenderer(value, gotoData); + return renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + } + }). setItemsChosenCallback(selectedElements -> { for (Object element : selectedElements) { if (element instanceof AdditionalAction) { @@ -159,17 +164,19 @@ public abstract class GotoTargetHandler implements CodeInsightActionHandler { return true; }). setCouldPin(popup1 -> { - usageView.set(FindUtil.showInUsageView(gotoData.source, gotoData.targets, getFindUsagesTitle(gotoData.source, name, gotoData.targets.length), gotoData.source.getProject())); + usageView.set(FindUtil.showInUsageView(gotoData.source, gotoData.targets, + getFindUsagesTitle(gotoData.source, name, gotoData.targets.length), + gotoData.source.getProject())); popup1.cancel(); return false; }). - setAdText(getAdText(gotoData.source, targets.length)). - createPopup(); + setAdText(getAdText(gotoData.source, targets.length)); + final JBPopup popup = builder.createPopup(); JScrollPane pane = builder instanceof PopupChooserBuilder ? ((PopupChooserBuilder)builder).getScrollPane() : null; if (pane != null) { - pane.setBorder(null); - pane.setViewportBorder(null); + pane.setBorder(null); + pane.setViewportBorder(null); } if (gotoData.listUpdaterTask != null) { diff --git a/platform/lang-impl/src/com/intellij/testIntegration/GotoTestOrCodeHandler.java b/platform/lang-impl/src/com/intellij/testIntegration/GotoTestOrCodeHandler.java index 664df489b04c..111fb48ebef6 100644 --- a/platform/lang-impl/src/com/intellij/testIntegration/GotoTestOrCodeHandler.java +++ b/platform/lang-impl/src/com/intellij/testIntegration/GotoTestOrCodeHandler.java @@ -141,6 +141,11 @@ public class GotoTestOrCodeHandler extends GotoTargetHandler { return null; } + @Override + protected boolean useEditorFont() { + return false; + } + @Override protected void navigateToElement(@NotNull Navigatable element) { if (element instanceof PsiElement) {