diff --git a/python/src/META-INF/python-plugin-common.xml b/python/src/META-INF/python-plugin-common.xml index 32f8a2001f1e..e18df4974244 100644 --- a/python/src/META-INF/python-plugin-common.xml +++ b/python/src/META-INF/python-plugin-common.xml @@ -57,6 +57,7 @@ + diff --git a/python/src/com/jetbrains/python/codeInsight/PyElementListCellRenderer.java b/python/src/com/jetbrains/python/codeInsight/PyElementListCellRenderer.java new file mode 100644 index 000000000000..a94b0d360c00 --- /dev/null +++ b/python/src/com/jetbrains/python/codeInsight/PyElementListCellRenderer.java @@ -0,0 +1,67 @@ +package com.jetbrains.python.codeInsight; + +import com.intellij.ide.util.PsiElementListCellRenderer; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiNamedElement; +import com.intellij.util.ui.UIUtil; + +import javax.swing.*; +import java.awt.*; + +/** + * @author yole + */ +public class PyElementListCellRenderer extends PsiElementListCellRenderer { + private static final PyLocationRenderer myLocationRenderer = new PyLocationRenderer(); + + public String getElementText(final PsiElement element) { + final String name = ((PsiNamedElement)element).getName(); + return name == null ? "" : name; + } + + protected String getContainerText(final PsiElement element, final String name) { + return null; + } + + protected int getIconFlags() { + return 0; + } + + protected DefaultListCellRenderer getRightCellRenderer() { + return myLocationRenderer; + } + + private static class PyLocationRenderer extends DefaultListCellRenderer { + private String myText; + + public String getText() { + return myText; + } + + public Component getListCellRendererComponent(final JList list, + final Object value, + final int index, + final boolean isSelected, + final boolean cellHasFocus) { + final Component listCellRendererComponent = super.getListCellRendererComponent(list, value, index, isSelected, + cellHasFocus); + customizeCellRenderer(value, isSelected); + return listCellRendererComponent; + } + + private void customizeCellRenderer(final Object value, final boolean selected) { + PsiElement element = (PsiElement) value; + if (element.isValid()) { + myText = element.getContainingFile().getName(); + } + else { + myText = ""; + } + setText(myText); + setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); + setHorizontalTextPosition(SwingConstants.LEFT); + setBackground(selected ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground()); + setForeground(selected ? UIUtil.getListSelectionForeground() : UIUtil.getInactiveTextColor()); + } + } +} diff --git a/python/src/com/jetbrains/python/codeInsight/PyGotoImplementationRendererProvider.java b/python/src/com/jetbrains/python/codeInsight/PyGotoImplementationRendererProvider.java new file mode 100644 index 000000000000..77a35b30ae95 --- /dev/null +++ b/python/src/com/jetbrains/python/codeInsight/PyGotoImplementationRendererProvider.java @@ -0,0 +1,24 @@ +package com.jetbrains.python.codeInsight; + +import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.codeInsight.navigation.GotoImplementationRendererProvider; +import com.intellij.ide.util.PsiElementListCellRenderer; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiNamedElement; +import com.jetbrains.python.psi.PyElement; + +/** + * @author yole + */ +public class PyGotoImplementationRendererProvider implements GotoImplementationRendererProvider { + public PsiElementListCellRenderer getRenderer(final PsiElement[] elements) { + for(PsiElement element: elements) { + if (!(element instanceof PyElement) || !(element instanceof PsiNamedElement)) return null; + } + return new PyElementListCellRenderer(); + } + + public String getChooserTitle(final String name, final PsiElement[] elements) { + return CodeInsightBundle.message("goto.implementation.chooser.title", name, elements.length); + } +}