IDEA-144857 add some love to new Find in Path popup
authorSergey Ignatov <sergey.ignatov@jetbrains.com>
Fri, 25 Mar 2016 12:44:25 +0000 (15:44 +0300)
committerSergey Ignatov <sergey.ignatov@jetbrains.com>
Fri, 25 Mar 2016 12:46:05 +0000 (15:46 +0300)
platform/lang-impl/src/com/intellij/find/impl/FindDialog.java
platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java
platform/usageView/src/com/intellij/usages/impl/UsageContextPanelBase.java

index 1233357dd5634dd3979ca6d1d6e9f9a1421f9e16..3cac32f60e7ab9521c5dc6a7c0880b40c00265c0 100644 (file)
@@ -38,7 +38,6 @@ import com.intellij.openapi.editor.event.DocumentEvent;
 import com.intellij.openapi.fileChooser.FileChooser;
 import com.intellij.openapi.fileChooser.FileChooserDescriptor;
 import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
-import com.intellij.openapi.fileEditor.UniqueVFilePathBuilder;
 import com.intellij.openapi.fileTypes.FileType;
 import com.intellij.openapi.fileTypes.LanguageFileType;
 import com.intellij.openapi.fileTypes.PlainTextFileType;
@@ -74,6 +73,7 @@ import com.intellij.usages.*;
 import com.intellij.usages.impl.UsagePreviewPanel;
 import com.intellij.util.*;
 import com.intellij.util.containers.Convertor;
+import com.intellij.util.ui.JBUI;
 import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -469,7 +469,7 @@ public class FindDialog extends DialogWrapper {
         return;
       }
 
-      myResultsPreviewTable.getColumnModel().getColumn(0).setCellRenderer(new UsageTableCellRenderer());
+      myResultsPreviewTable.getColumnModel().getColumn(0).setCellRenderer(new UsageTableCellRenderer(false, true));
 
       myResultsPreviewTable.getEmptyText().setText("Searching...");
       myContent.setTitleAt(RESULTS_PREVIEW_TAB_INDEX, PREVIEW_TITLE);
@@ -634,6 +634,7 @@ public class FindDialog extends DialogWrapper {
         };
         table.setShowColumns(false);
         table.setShowGrid(false);
+        table.setIntercellSpacing(JBUI.emptySize());
         new NavigateToSourceListener().installOn(table);
 
         Splitter previewSplitter = new Splitter(true, 0.5f, 0.1f, 0.9f);
@@ -1662,32 +1663,50 @@ public class FindDialog extends DialogWrapper {
           // skip line number / file info
           for (int i = 1; i < text.length; ++i) {
             TextChunk textChunk = text[i];
-            myUsageRenderer.append(textChunk.getText(), textChunk.getSimpleAttributesIgnoreBackground());
+            SimpleTextAttributes attributes = getAttributes(textChunk);
+            myUsageRenderer.append(textChunk.getText(), attributes);
           }
         }
         setBorder(null);
       }
+
+      @NotNull
+      private SimpleTextAttributes getAttributes(@NotNull TextChunk textChunk) {
+        SimpleTextAttributes at = textChunk.getSimpleAttributesIgnoreBackground();
+        if (myUseBold) return at;
+        boolean highlighted = textChunk.getType() != null || at.getFontStyle() == Font.BOLD;
+        return highlighted
+               ? new SimpleTextAttributes(null, at.getFgColor(), at.getWaveColor(),
+                                          (at.getStyle() & ~SimpleTextAttributes.STYLE_BOLD) |
+                                          SimpleTextAttributes.STYLE_SEARCH_MATCH)
+               : at;
+      }
     };
     private final ColoredTableCellRenderer myFileAndLineNumber = new ColoredTableCellRenderer() {
       @Override
       protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
         if (value instanceof UsageInfo2UsageAdapter) {
-          final UsageInfo2UsageAdapter usageAdapter = (UsageInfo2UsageAdapter)value;
+          UsageInfo2UsageAdapter usageAdapter = (UsageInfo2UsageAdapter)value;
           TextChunk[] text = usageAdapter.getPresentation().getText();
-          final String uniqueVirtualFilePath =
-            UniqueVFilePathBuilder.getInstance().getUniqueVirtualFilePath(usageAdapter.getUsageInfo().getProject(), usageAdapter.getFile());
           // line number / file info
+          VirtualFile file = usageAdapter.getFile();
+          String uniqueVirtualFilePath = myOmitFileExtension ? file.getNameWithoutExtension() : file.getName();
           append(uniqueVirtualFilePath + " " + text[0].getText(), SimpleTextAttributes.GRAYED_ATTRIBUTES);
         }
         setBorder(null);
       }
     };
+    private static final int MARGIN = 2;
+    private final boolean myOmitFileExtension;
+    private final boolean myUseBold;
 
-    UsageTableCellRenderer() {
+    UsageTableCellRenderer(boolean omitFileExtension, boolean useBold) {
+      myOmitFileExtension = omitFileExtension;
+      myUseBold = useBold;
       setLayout(new BorderLayout());
-
       add(myUsageRenderer, BorderLayout.WEST);
       add(myFileAndLineNumber, BorderLayout.EAST);
+      setBorder(IdeBorderFactory.createEmptyBorder(MARGIN, MARGIN, MARGIN, 0));
     }
 
     @Override
@@ -1695,6 +1714,13 @@ public class FindDialog extends DialogWrapper {
       myUsageRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
       myFileAndLineNumber.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
       setBackground(myUsageRenderer.getBackground());
+      if (!isSelected && value instanceof UsageInfo2UsageAdapter) {
+        UsageInfo2UsageAdapter usageAdapter = (UsageInfo2UsageAdapter)value;
+        Color color = FileColorManager.getInstance(usageAdapter.getUsageInfo().getProject()).getFileColor(usageAdapter.getFile());
+        setBackground(color);
+        myUsageRenderer.setBackground(color);
+        myFileAndLineNumber.setBackground(color);
+      }
       return this;
     }
   }
index 4db578576d825fc99391d2b4121b3a53010fa082..c0ca30c67b9eafea85f1fd55e2fb21c25bf86846 100644 (file)
@@ -100,8 +100,11 @@ import java.util.regex.PatternSyntaxException;
 import static com.intellij.find.impl.FindDialog.createCheckbox;
 
 public class FindPopupPanel extends JBPanel {
-  private static final Logger LOG = Logger.getInstance("#com.intellij.find.impl.FindPopupPanel");
-  private static final KeyStroke OK_KEYSTROKE = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK);
+  private static final Logger LOG = Logger.getInstance(FindPopupPanel.class);
+  // unify with CommonShortcuts.CTRL_ENTER
+  private static final KeyStroke OK_KEYSTROKE = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, SystemInfo.isMac
+                                                                                          ? InputEvent.META_DOWN_MASK
+                                                                                          : InputEvent.CTRL_DOWN_MASK);
 
   private static final KeyStroke MOVE_CARET_DOWN = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0);
   private static final KeyStroke MOVE_CARET_UP = KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0);
@@ -258,6 +261,12 @@ public class FindPopupPanel extends JBPanel {
         }
       };
     myFileMaskField.setPreferredWidth(JBUI.scale(100));
+    myFileMaskField.addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {
+      @Override
+      public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
+        scheduleResultsUpdate();
+      }
+    });
     myCbFileFilter.addItemListener(new ItemListener() {
       @Override
       public void itemStateChanged(ItemEvent e) {
@@ -370,8 +379,6 @@ public class FindPopupPanel extends JBPanel {
       (ActionToolbarImpl)ActionManager.getInstance().createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, scopeActionGroup, true);
     myScopeSelectionToolbar.setForceMinimumSize(true);
     myScopeSelectionToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY);
-    myScopeSelectionToolbar.setBorder(new RoundedLineBorder(JBColor.border(), JBUI.scale(5)));
-
 
     Module[] modules = ModuleManager.getInstance(myProject).getModules();
     String[] names = new String[modules.length];
@@ -495,6 +502,7 @@ public class FindPopupPanel extends JBPanel {
     myResultsPreviewTable.setShowColumns(false);
     myResultsPreviewTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     myResultsPreviewTable.setShowGrid(false);
+    myResultsPreviewTable.setIntercellSpacing(JBUI.emptySize());
     new NavigateToSourceListener().installOn(myResultsPreviewTable);
     applyFont(JBUI.Fonts.label(), myCbCaseSensitive, myCbPreserveCase, myCbWholeWordsOnly, myCbRegularExpressions,
               myResultsPreviewTable);
@@ -804,10 +812,11 @@ public class FindPopupPanel extends JBPanel {
     applyTo(myModel, false);
     FindManager.getInstance(myProject).getFindInProjectModel().copyFrom(myModel);
     ((FindManagerImpl)FindManager.getInstance(myProject)).changeGlobalSettings(myModel);
-    FindSettings.getInstance().setDefaultScopeName(myScopeCombo.getSelectedScopeName());
-
+    FindSettings findSettings = FindSettings.getInstance();
+    findSettings.setDefaultScopeName(myScopeCombo.getSelectedScopeName());
+    findSettings.setFileMask(myModel.getFileFilter());
 
-    ValidationInfo result = getValidationInfo(/*findModel*/myModel);
+    ValidationInfo result = getValidationInfo(myModel);
 
     final ProgressIndicatorBase progressIndicatorWhenSearchStarted = new ProgressIndicatorBase();
     myResultsPreviewSearchProgress = progressIndicatorWhenSearchStarted;
@@ -830,7 +839,7 @@ public class FindPopupPanel extends JBPanel {
       return;
     }
 
-    myResultsPreviewTable.getColumnModel().getColumn(0).setCellRenderer(new FindDialog.UsageTableCellRenderer());
+    myResultsPreviewTable.getColumnModel().getColumn(0).setCellRenderer(new FindDialog.UsageTableCellRenderer(myCbFileFilter.isSelected(), false));
     myResultsPreviewTable.getEmptyText().setText("Searching...");
 
     final AtomicInteger resultsCount = new AtomicInteger();
@@ -839,8 +848,8 @@ public class FindPopupPanel extends JBPanel {
       @Override
       public void computeInReadAction(@NotNull ProgressIndicator indicator) {
         final UsageViewPresentation presentation =
-          FindInProjectUtil.setupViewPresentation(FindSettings.getInstance().isShowResultsInSeparateView(), /*findModel*/myModel.clone());
-        final boolean showPanelIfOnlyOneUsage = !FindSettings.getInstance().isSkipResultsWithOneUsage();
+          FindInProjectUtil.setupViewPresentation(findSettings.isShowResultsInSeparateView(), /*findModel*/myModel.clone());
+        final boolean showPanelIfOnlyOneUsage = !findSettings.isSkipResultsWithOneUsage();
 
         final FindUsagesProcessPresentation processPresentation =
           FindInProjectUtil.setupProcessPresentation(myProject, showPanelIfOnlyOneUsage, presentation);
@@ -904,21 +913,24 @@ public class FindPopupPanel extends JBPanel {
         public void run() {
           JPanel popupContent = new JPanel(new BorderLayout());
           popupContent.setName("PopupContent!!!");
-          Splitter splitter = new JBSplitter(true, .33F, .1F, .5F);
+          Splitter splitter = new JBSplitter(true, .33F);
           splitter.setDividerWidth(1);
-          splitter.setFirstComponent(new JBScrollPane(myResultsPreviewTable) {
+          splitter.getDivider().setBackground(OnePixelDivider.BACKGROUND);
+          JBScrollPane scrollPane = new JBScrollPane(myResultsPreviewTable) {
             @Override
             public Dimension getMinimumSize() {
               Dimension size = super.getMinimumSize();
               size.height = Math.max(size.height, myResultsPreviewTable.getPreferredScrollableViewportSize().height);
               return size;
             }
-          });
+          };
+          scrollPane.setBorder(IdeBorderFactory.createEmptyBorder());
+          splitter.setFirstComponent(scrollPane);
           popupContent.add(splitter, BorderLayout.CENTER);
           JPanel bottomPanel = new JPanel(new MigLayout("flowx, ins 4, fillx, hidemode 3, gap 0"));
           bottomPanel.add(myTabResultsButton);
           bottomPanel.add(Box.createHorizontalGlue(), "growx, pushx");
-          JBLabel label = new JBLabel("Ctrl+Enter");
+          JBLabel label = new JBLabel(KeymapUtil.getShortcutsText(new Shortcut[]{new KeyboardShortcut(OK_KEYSTROKE, null)}));
           label.setEnabled(false);
           bottomPanel.add(label, "gapright 10");
           bottomPanel.add(myOKButton);
@@ -926,8 +938,8 @@ public class FindPopupPanel extends JBPanel {
 
           popupContent.registerKeyboardAction(myOkActionListener, OK_KEYSTROKE, WHEN_IN_FOCUSED_WINDOW);
 
-
           myCodePreviewComponent = myUsagePreviewPanel.createComponent();
+          myCodePreviewComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
           splitter.setSecondComponent(myCodePreviewComponent);
 
           AtomicBoolean canClose = new AtomicBoolean();
index d807c5b80e455efd7264700047f0ab39f5d8b6f9..cd9efc9ed795594f3de2736cba8c1c3134c44f4d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ public abstract class UsageContextPanelBase extends JPanel implements UsageConte
     myProject = project;
     myPresentation = presentation;
     setLayout(new BorderLayout());
-    setBorder(IdeBorderFactory.createBorder());
+    setBorder(IdeBorderFactory.createEmptyBorder());
   }
 
   @NotNull