Skip to content

Commit

Permalink
OC-9697 Include ObjC symbols into search everywhere
Browse files Browse the repository at this point in the history
fix duplication, add custom renderer
  • Loading branch information
fsmorygo committed Nov 9, 2015
1 parent 749aeb1 commit f0eb6d9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 26 deletions.
Expand Up @@ -22,6 +22,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

public class DefaultSearchEverywhereClassifier implements SearchEverywhereClassifier {
@Override
public boolean isClass(@Nullable Object o) {
Expand All @@ -47,4 +50,10 @@ public VirtualFile getVirtualFile(@NotNull Object o) {
}
return null;
}

@Nullable
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
return null;
}
}
Expand Up @@ -1107,23 +1107,29 @@ public Component getListCellRendererComponent(JList list, Object value, int inde
Matcher matcher = NameUtil.buildMatcher(pattern, 0, true, true);
if (isMoreItem(index)) {
cmp = More.get(isSelected);
} else if (value instanceof VirtualFile
&& myProject != null
&& ((((VirtualFile)value).isDirectory() && (file = PsiManager.getInstance(myProject).findDirectory((VirtualFile)value)) != null )
|| (file = PsiManager.getInstance(myProject).findFile((VirtualFile)value)) != null)) {
myFileRenderer.setPatternMatcher(matcher);
cmp = myFileRenderer.getListCellRendererComponent(list, file, index, isSelected, cellHasFocus);
} else if (value instanceof PsiElement) {
myFileRenderer.setPatternMatcher(matcher);
cmp = myFileRenderer.getListCellRendererComponent(list, value, index, isSelected, isSelected);
} else if (value instanceof GotoActionModel.ActionWrapper) {
cmp = myActionsRenderer.getListCellRendererComponent(list, new GotoActionModel.MatchedValue(((GotoActionModel.ActionWrapper)value), pattern), index, isSelected, isSelected);
} else {
cmp = super.getListCellRendererComponent(list, value, index, isSelected, isSelected);
final JPanel p = new JPanel(new BorderLayout());
p.setBackground(UIUtil.getListBackground(isSelected));
p.add(cmp, BorderLayout.CENTER);
cmp = p;
cmp = SearchEverywhereClassifier.EP_Manager.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}

if (cmp == null) {
if (value instanceof VirtualFile
&& myProject != null
&& ((((VirtualFile)value).isDirectory() && (file = PsiManager.getInstance(myProject).findDirectory((VirtualFile)value)) != null)
|| (file = PsiManager.getInstance(myProject).findFile((VirtualFile)value)) != null)) {
myFileRenderer.setPatternMatcher(matcher);
cmp = myFileRenderer.getListCellRendererComponent(list, file, index, isSelected, cellHasFocus);
} else if (value instanceof PsiElement) {
myFileRenderer.setPatternMatcher(matcher);
cmp = myFileRenderer.getListCellRendererComponent(list, value, index, isSelected, isSelected);
} else if (value instanceof GotoActionModel.ActionWrapper) {
cmp = myActionsRenderer.getListCellRendererComponent(list, new GotoActionModel.MatchedValue(((GotoActionModel.ActionWrapper)value), pattern), index, isSelected, isSelected);
} else {
cmp = super.getListCellRendererComponent(list, value, index, isSelected, isSelected);
final JPanel p = new JPanel(new BorderLayout());
p.setBackground(UIUtil.getListBackground(isSelected));
p.add(cmp, BorderLayout.CENTER);
cmp = p;
}
}
if (myLocationString != null || value instanceof BooleanOptionDescription) {
final JPanel panel = new JPanel(new BorderLayout());
Expand Down Expand Up @@ -1739,13 +1745,18 @@ private SearchResult getSymbols(String pattern, final int max, final boolean inc
@Override
public boolean process(Object o) {
if (SearchEverywhereClassifier.EP_Manager.isSymbol(o) && !myListModel.contains(o) && !symbols.contains(o)) {
PsiElement element = null;
if (o instanceof PsiElement) {
element = (PsiElement)o;
}
else if (o instanceof PsiElementNavigationItem) {
element = ((PsiElementNavigationItem)o).getTargetElement();
}
VirtualFile virtualFile = SearchEverywhereClassifier.EP_Manager.getVirtualFile(o);
//some elements are non-physical like DB columns
if (o instanceof PsiElementNavigationItem) {
o = ((PsiElementNavigationItem)o).getTargetElement();
}
if ((o instanceof PsiElement && ((PsiElement)o).getContainingFile() == null) ||
(virtualFile != null && (includeLibs || scope.accept(virtualFile)))) {
boolean isElementWithoutFile = element != null && element.getContainingFile() == null;
boolean isFileInScope = virtualFile != null && (includeLibs || scope.accept(virtualFile));
if (isElementWithoutFile || isFileInScope) {
symbols.add(o);
}
}
Expand Down Expand Up @@ -1775,13 +1786,18 @@ public boolean process(Object o) {
classes.needMore = true;
return false;
}
classes.add(o);

if (o instanceof PsiElementNavigationItem) {
o = ((PsiElementNavigationItem)o).getTargetElement();
PsiElement element = null;
if (o instanceof PsiElement) {
element = (PsiElement)o;
}
else if (o instanceof PsiElementNavigationItem) {
element = ((PsiElementNavigationItem)o).getTargetElement();
}
if (o instanceof PsiNamedElement) {
final String name = ((PsiNamedElement)o).getName();
classes.add(o);

if (element instanceof PsiNamedElement) {
final String name = ((PsiNamedElement)element).getName();
VirtualFile virtualFile = SearchEverywhereClassifier.EP_Manager.getVirtualFile(o);
if (virtualFile != null) {
if (StringUtil.equals(name, virtualFile.getNameWithoutExtension())) {
Expand Down
Expand Up @@ -21,6 +21,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

/**
* @author Philipp Smorygo
*/
Expand Down Expand Up @@ -50,6 +53,15 @@ public static VirtualFile getVirtualFile(@NotNull Object o) {
}
return null;
}

@Nullable
public static Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
for (SearchEverywhereClassifier classifier : Extensions.getExtensions(SearchEverywhereClassifier.EP_NAME)) {
Component component = classifier.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (component != null) return component;
}
return null;
}
}

ExtensionPointName<SearchEverywhereClassifier> EP_NAME = ExtensionPointName.create("com.intellij.searchEverywhereClassifier");
Expand All @@ -60,4 +72,7 @@ public static VirtualFile getVirtualFile(@NotNull Object o) {

@Nullable
VirtualFile getVirtualFile(@NotNull Object o);

@Nullable
Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus);
}

0 comments on commit f0eb6d9

Please sign in to comment.