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 db83ec4f9481..223f973cb2d6 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java @@ -107,9 +107,11 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA private GotoClassModel2 myClassModel; private GotoFileModel myFileModel; private GotoActionModel myActionModel; + private GotoSymbolModel2 mySymbolsModel; private String[] myClasses; private String[] myFiles; private String[] myActions; + private String[] mySymbols; private Component myFocusComponent; private JBPopup myPopup; private SearchListModel myListModel = new SearchListModel(); @@ -845,6 +847,12 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA buildActionsAndSettings(pattern); updatePopup(); + + readLock = ApplicationManager.getApplication().acquireReadActionLock(); + try { + buildSymbols(pattern); + } finally {readLock.finish();} + updatePopup(); } catch (Exception ignore) { } @@ -854,6 +862,9 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA } private void buildToolWindows(String pattern) { + if (myActions == null) { + myActions = myActionModel.getNames(true); + } final HashSet toolWindows = new HashSet(); final MinusculeMatcher matcher = new MinusculeMatcher("*" +pattern, NameUtil.MatchingCaseSensitivity.NONE); List matches = collectResults(pattern, myActions, myActionModel); @@ -888,6 +899,9 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA final Set actions = new HashSet(); final Set settings = new HashSet(); final MinusculeMatcher matcher = new MinusculeMatcher("*" +pattern, NameUtil.MatchingCaseSensitivity.NONE); + if (myActions == null) { + myActions = myActionModel.getNames(true); + } List matches = collectResults(pattern, myActions, myActionModel); @@ -933,6 +947,9 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA private void buildFiles(String pattern) { int filesCounter = 0; + if (myFiles == null) { + myFiles = myFileModel.getNames(false); + } List matches = collectResults(pattern, myFiles, myFileModel); final List files = new ArrayList(); FindSymbolParameters parameters = FindSymbolParameters.wrap(pattern, project, false); @@ -976,9 +993,52 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA } } + private void buildSymbols(String pattern) { + int symbolCounter = 0; + if (mySymbols == null) { + mySymbols = mySymbolsModel.getNames(false); + } + List matches = collectResults(pattern, mySymbols, mySymbolsModel); + final List symbols = new ArrayList(); + + final int maxFiles = 8; + for (MatchResult o : matches) { + if (symbolCounter > maxFiles) break; + + Object[] objects = mySymbolsModel.getElementsByName(o.elementName, false, pattern); + for (Object object : objects) { + if (!myListModel.contains(object)) { + symbols.add(object); + symbolCounter++; + if (symbolCounter > maxFiles) break; + } + } + } + + myProgressIndicator.checkCanceled(); + + if (symbols.size() > 0) { + UIUtil.invokeAndWaitIfNeeded(new Runnable() { + @Override + public void run() { + if (!myProgressIndicator.isCanceled()) { + myTitleIndexes.symbols = myListModel.size(); + for (Object file : symbols) { + myListModel.addElement(file); + } + myMoreFilesIndex = symbols.size() >= maxFiles ? myListModel.size() - 1 : -1; + } + } + }); + } + } + private void buildClasses(String pattern, boolean includeLibraries) { int clsCounter = 0; final int maxCount = includeLibraries ? 5 : 8; + if (myClasses == null) { + myClasses = myClassModel.getNames(false); + } List matches = collectResults(pattern, includeLibraries ? myClassModel.getNames(true) : myClasses, myClassModel); FindSymbolParameters parameters = FindSymbolParameters.wrap(pattern, project, includeLibraries); final List classes = new ArrayList(); @@ -1094,9 +1154,7 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA myClassModel = new GotoClassModel2(project); myFileModel = new GotoFileModel(project); myActionModel = createActionModel(); - myClasses = myClassModel.getNames(false); - myFiles = myFileModel.getNames(false); - myActions = myActionModel.getNames(true); + mySymbolsModel = new GotoSymbolModel2(project); myConfigurables.clear(); fillConfigurablesIds(null, new IdeConfigurablesGroup().getConfigurables()); fillConfigurablesIds(null, new ProjectConfigurablesGroup(project).getConfigurables()); @@ -1383,12 +1441,14 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA int actions; int settings; int toolWindows; + int symbols; final String gotoClassTitle; final String gotoFileTitle; final String gotoActionTitle; final String gotoSettingsTitle; final String gotoRecentFilesTitle; + final String gotoSymbolTitle; static final String toolWindowsTitle = "Tool Windows"; TitleIndexes() { @@ -1402,6 +1462,8 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA gotoSettingsTitle = StringUtil.isEmpty(gotoAction) ? "Preferences" : "Preferences (" + gotoSettings + ")"; String gotoRecentFiles = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction("RecentFiles")); gotoRecentFilesTitle = StringUtil.isEmpty(gotoRecentFiles) ? "Recent Files" : "Recent Files (" + gotoRecentFiles + ")"; + String gotoSymbol = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction("GotoSymbol")); + gotoSymbolTitle = StringUtil.isEmpty(gotoClass) ? "Symbols" : "Symbols (" + gotoSymbol + ")"; } String getTitle(int index) { @@ -1412,6 +1474,7 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA if (index == toolWindows) return toolWindowsTitle; if (index == actions) return gotoActionTitle; if (index == settings) return gotoSettingsTitle; + if (index == symbols) return gotoSymbolTitle; return null; }