From e36607b4bfbf32905810824a9ba54f0225b2562d Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Mon, 26 Aug 2013 14:28:17 +0200 Subject: [PATCH] new renderer --- .../ide/actions/SearchEverywhereAction.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java index 3e43258a75f0..a6fe5ce2b197 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java @@ -24,6 +24,7 @@ import com.intellij.ide.ui.LafManagerListener; import com.intellij.ide.ui.search.BooleanOptionDescription; import com.intellij.ide.ui.search.OptionDescription; import com.intellij.ide.ui.search.SearchableOptionsRegistrarImpl; +import com.intellij.ide.util.DefaultPsiElementCellRenderer; import com.intellij.ide.util.gotoByName.*; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; @@ -56,6 +57,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; import com.intellij.psi.codeStyle.MinusculeMatcher; import com.intellij.psi.codeStyle.NameUtil; import com.intellij.psi.util.PsiUtilCore; @@ -302,6 +304,7 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA final Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(field.getTextEditor())); assert project != null; + myRenderer.myProject = project; myCalcThread = new CalcThread(project, pattern); myCalcThread.start(); } @@ -350,7 +353,9 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA } }; private String myLocationString; + private DefaultPsiElementCellRenderer myPsiRenderer = new DefaultPsiElementCellRenderer(); private Icon myLocationIcon; + private Project myProject; private JPanel myMainPanel = new JPanel(new BorderLayout()); private JLabel myTitle = new JLabel(); private JPanel myLeftPanel = new JPanel(new BorderLayout()) { @@ -383,7 +388,16 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - Component cmp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + Component cmp; + PsiFile file; + myLocationString = null; + if (value instanceof VirtualFile && myProject != null && (file = PsiManager.getInstance(myProject).findFile((VirtualFile)value)) != null) { + cmp = new GotoFileCellRenderer(list.getWidth()).getListCellRendererComponent(list, file, index, isSelected, cellHasFocus); + } else if (value instanceof PsiElement) { + cmp = myPsiRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + } else { + cmp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + } if (myLocationString != null || value instanceof BooleanOptionDescription) { final JPanel panel = new JPanel(new BorderLayout()); panel.add(cmp, BorderLayout.CENTER); @@ -490,7 +504,7 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA index++; } - myLeftWidth += 10; + //myLeftWidth += 10; myTitle.setForeground(Gray._122); myTitle.setAlignmentY(BOTTOM_ALIGNMENT); myLeftPanel.setBorder(new CompoundBorder(new CustomLineBorder(getSeparatorColor(), 0, 0, 0, 1), new EmptyBorder(0, 0, 0, 5))); @@ -863,9 +877,11 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA @SuppressWarnings("SSBasedInspection") private void updatePopup() { + myProgressIndicator.checkCanceled(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { + myProgressIndicator.checkCanceled(); myListModel.update(); myList.revalidate(); myList.repaint(); @@ -911,8 +927,8 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA sz.width++; sz.width++; } - sz.width = 600; - sz.height = 800; + sz.width = Math.max(600, sz.width); + sz.height = Math.max(800, sz.height); myPopup.setSize(sz); final Point screen = field.getLocationOnScreen(); final int x = screen.x + field.getWidth() - myPopup.getSize().width;