From 466e61a43d21f310709299d7a552c12fd623f5da Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 7 Feb 2012 11:17:17 +0100 Subject: [PATCH] present a correct scope in show usages action, not just 'project files' always --- .../find/actions/ShowUsagesAction.java | 28 ++++++++++--------- .../find/findUsages/FindUsagesManager.java | 13 ++------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java index fa52ac698e9b..80ead536ae99 100644 --- a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java +++ b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java @@ -20,11 +20,9 @@ import com.intellij.codeInsight.hint.HintManager; import com.intellij.codeInsight.hint.HintUtil; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.find.FindManager; -import com.intellij.find.findUsages.AbstractFindUsagesDialog; -import com.intellij.find.findUsages.FindUsagesHandler; -import com.intellij.find.findUsages.FindUsagesManager; -import com.intellij.find.findUsages.PsiElement2UsageTargetAdapter; +import com.intellij.find.findUsages.*; import com.intellij.find.impl.FindManagerImpl; +import com.intellij.ide.DataManager; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ActionManagerEx; @@ -225,14 +223,15 @@ public class ShowUsagesAction extends AnAction implements PopupAction { } }; FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(handler.getProject())).getFindUsagesManager(); - presentation = findUsagesManager.processUsages(handler, collect); + FindUsagesOptions options = handler.getFindUsagesOptions(DataManager.getInstance().getDataContext()); + presentation = findUsagesManager.processUsages(handler, collect, options); if (presentation == null) { Disposer.dispose(usageView); return; } final String title = presentation.getTabText(); - JBPopup popup = createUsagePopup(usages, visibleNodes, title, handler, editor, popupPosition, maxUsages, usageView); + JBPopup popup = createUsagePopup(usages, visibleNodes, title, handler, editor, popupPosition, maxUsages, usageView, options); if (popup == null) { Disposer.dispose(usageView); } @@ -301,9 +300,9 @@ public class ShowUsagesAction extends AnAction implements PopupAction { } } - private static String searchScopePresentableName(final FindUsagesHandler handler) { - SearchScope searchScope = FindUsagesManager.getCurrentSearchScope(handler); - if (searchScope == null) searchScope = ProjectScope.getAllScope(handler.getProject()); + private static String searchScopePresentableName(FindUsagesOptions options, Project project) { + SearchScope searchScope = options.searchScope; + if (searchScope == null) searchScope = ProjectScope.getAllScope(project); return searchScope.getDisplayName(); } @@ -314,14 +313,15 @@ public class ShowUsagesAction extends AnAction implements PopupAction { final Editor editor, final RelativePoint popupPosition, final int maxUsages, - final UsageViewImpl usageView) { + final UsageViewImpl usageView, FindUsagesOptions options) { boolean hasMore = visibleNodes.remove(UsageViewImpl.NULL_NODE); final Project project = handler.getProject(); if (visibleNodes.isEmpty()) { if (usages.isEmpty()) { - String text = UsageViewBundle.message("no.usages.found.in", searchScopePresentableName(handler)); + String text = UsageViewBundle.message("no.usages.found.in", searchScopePresentableName(options, + project)); showHint(text, editor, popupPosition, handler, maxUsages); return null; } @@ -332,7 +332,8 @@ public class ShowUsagesAction extends AnAction implements PopupAction { if (visibleNodes.size() == 1 && usages.size() == 1) { //the only usage Usage usage = visibleNodes.iterator().next().getUsage(); - navigateAndHint(usage, UsageViewBundle.message("show.usages.only.usage", searchScopePresentableName(handler)), handler, popupPosition, + navigateAndHint(usage, UsageViewBundle.message("show.usages.only.usage", + searchScopePresentableName(options, project)), handler, popupPosition, maxUsages); return null; } @@ -340,7 +341,8 @@ public class ShowUsagesAction extends AnAction implements PopupAction { // usage view can filter usages down to one Usage usage = visibleNodes.iterator().next().getUsage(); if (areAllUsagesInThisLine(usage, usages)) { - String hint = UsageViewBundle.message("all.usages.are.in.this.line", usages.size(), searchScopePresentableName(handler)); + String hint = UsageViewBundle.message("all.usages.are.in.this.line", usages.size(), + searchScopePresentableName(options, project)); navigateAndHint(usage, hint, handler, popupPosition, maxUsages); return null; } diff --git a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java index 2103f229738b..1682455dfe00 100644 --- a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java +++ b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java @@ -20,7 +20,6 @@ import com.intellij.codeInsight.hint.HintManager; import com.intellij.codeInsight.hint.HintManagerImpl; import com.intellij.codeInsight.hint.HintUtil; import com.intellij.find.FindBundle; -import com.intellij.ide.DataManager; import com.intellij.lang.findUsages.LanguageFindUsages; import com.intellij.navigation.NavigationItem; import com.intellij.openapi.actionSystem.ActionManager; @@ -273,13 +272,6 @@ public class FindUsagesManager implements JDOMExternalizable { } } - @Nullable - public static SearchScope getCurrentSearchScope(FindUsagesHandler handler) { - if (handler == null) return null; - FindUsagesOptions findUsagesOptions = handler.getFindUsagesOptions(); - return findUsagesOptions.searchScope; - } - public boolean isUsed(@NotNull PsiElement element, @NotNull FindUsagesOptions findUsagesOptions) { FindUsagesHandler handler = getFindUsagesHandler(element, true); if (handler == null) return false; @@ -298,11 +290,10 @@ public class FindUsagesManager implements JDOMExternalizable { // return null on failure or cancel @Nullable - public UsageViewPresentation processUsages(FindUsagesHandler handler, @NotNull final Processor processor) { + public UsageViewPresentation processUsages(FindUsagesHandler handler, + @NotNull final Processor processor, FindUsagesOptions findUsagesOptions) { if (handler == null) return null; - FindUsagesOptions findUsagesOptions = handler.getFindUsagesOptions(DataManager.getInstance().getDataContext()); - PsiElement element = handler.getPsiElement(); LOG.assertTrue(element.isValid()); final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor =