don't show file path twice in platform goto file dialog

This commit is contained in:
Dmitry Jemerov
2010-07-19 14:08:40 +04:00
parent edef28b37b
commit 4eebed92f8
2 changed files with 42 additions and 28 deletions
@@ -28,38 +28,40 @@ import java.awt.*;
*/
public class PlatformModuleRendererFactory extends ModuleRendererFactory {
public DefaultListCellRenderer getModuleRenderer() {
return new DefaultListCellRenderer() {
public Component getListCellRendererComponent(final JList list,
final Object value,
final int index,
final boolean isSelected,
final boolean cellHasFocus) {
final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
String text = "";
if (value instanceof NavigationItem) {
final ItemPresentation presentation = ((NavigationItem)value).getPresentation();
if (presentation != null) {
String containerText = presentation.getLocationString();
if (containerText != null && containerText.length() > 0) {
text = " " + containerText;
}
}
}
setText(text);
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
setHorizontalTextPosition(SwingConstants.LEFT);
setBackground(isSelected ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground());
setForeground(isSelected ? UIUtil.getListSelectionForeground() : UIUtil.getInactiveTextColor());
return component;
}
};
return new PlatformModuleRenderer();
}
@Override
public boolean rendersLocationString() {
return true;
}
public static class PlatformModuleRenderer extends DefaultListCellRenderer {
public Component getListCellRendererComponent(final JList list,
final Object value,
final int index,
final boolean isSelected,
final boolean cellHasFocus) {
final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
String text = "";
if (value instanceof NavigationItem) {
final ItemPresentation presentation = ((NavigationItem)value).getPresentation();
if (presentation != null) {
String containerText = presentation.getLocationString();
if (containerText != null && containerText.length() > 0) {
text = " " + containerText;
}
}
}
setText(text);
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
setHorizontalTextPosition(SwingConstants.LEFT);
setBackground(isSelected ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground());
setForeground(isSelected ? UIUtil.getListSelectionForeground() : UIUtil.getInactiveTextColor());
return component;
}
}
}
@@ -16,6 +16,7 @@
package com.intellij.ide.util.gotoByName;
import com.intellij.ide.util.PlatformModuleRendererFactory;
import com.intellij.ide.util.PsiElementListCellRenderer;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
@@ -26,6 +27,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.util.ui.FilePathSplittingPolicy;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.io.File;
@@ -72,6 +74,16 @@ public class GotoFileCellRenderer extends PsiElementListCellRenderer<PsiFile>{
return url;
}
@Override
protected DefaultListCellRenderer getRightCellRenderer() {
final DefaultListCellRenderer rightRenderer = super.getRightCellRenderer();
if (rightRenderer instanceof PlatformModuleRendererFactory.PlatformModuleRenderer) {
// that renderer will display file path, but we're showing it ourselves - no need to show twice
return null;
}
return rightRenderer;
}
protected int getIconFlags() {
return 0;
}