Search in sources :

Example 6 with UsageViewPresentation

use of com.intellij.usages.UsageViewPresentation in project intellij-community by JetBrains.

the class IconsReferencesContributor method execute.

@Override
public boolean execute(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiReference> consumer) {
    final PsiElement file = queryParameters.getElementToSearch();
    if (file instanceof PsiBinaryFile) {
        final Module module = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {

            @Override
            public Module compute() {
                return ModuleUtilCore.findModuleForPsiElement(file);
            }
        });
        final VirtualFile image = ((PsiBinaryFile) file).getVirtualFile();
        if (isImage(image) && isIconsModule(module)) {
            final Project project = file.getProject();
            final FindModel model = new FindModel();
            final String path = getPathToImage(image, module);
            if (path == null)
                return true;
            model.setStringToFind(path);
            model.setCaseSensitive(true);
            model.setFindAll(true);
            model.setWholeWordsOnly(true);
            FindInProjectUtil.findUsages(model, project, usage -> {
                ApplicationManager.getApplication().runReadAction(() -> {
                    final PsiElement element = usage.getElement();
                    final ProperTextRange textRange = usage.getRangeInElement();
                    if (element != null && textRange != null) {
                        final PsiElement start = element.findElementAt(textRange.getStartOffset());
                        final PsiElement end = element.findElementAt(textRange.getEndOffset());
                        if (start != null && end != null) {
                            PsiElement value = PsiTreeUtil.findCommonParent(start, end);
                            if (value instanceof PsiJavaToken) {
                                value = value.getParent();
                            }
                            if (value != null) {
                                final PsiFileReference reference = FileReferenceUtil.findFileReference(value);
                                if (reference != null) {
                                    consumer.process(reference);
                                }
                            }
                        }
                    }
                });
                return true;
            }, new FindUsagesProcessPresentation(new UsageViewPresentation()));
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UsageViewPresentation(com.intellij.usages.UsageViewPresentation) FindModel(com.intellij.find.FindModel) FindUsagesProcessPresentation(com.intellij.usages.FindUsagesProcessPresentation) ProperTextRange(com.intellij.openapi.util.ProperTextRange) Project(com.intellij.openapi.project.Project) PsiFileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.PsiFileReference) Module(com.intellij.openapi.module.Module)

Example 7 with UsageViewPresentation

use of com.intellij.usages.UsageViewPresentation in project intellij-community by JetBrains.

the class DeclarationConflictChecker method showConflicts.

/**
   * Shows a panel with name redefinition conflicts, if needed.
   * @param project
   * @param conflicts what {@link #findDefinitions} would return
   * @param obscured name or its topmost qualifier that is obscured, used at top of pane.
   * @param name full name (maybe qualified) to show as obscured and display as qualifier in "would be" chunks.
   * @return true iff conflicts is not empty and the panel is shown.
   */
public static boolean showConflicts(Project project, List<Pair<PsiElement, PsiElement>> conflicts, String obscured, @Nullable String name) {
    if (conflicts.size() > 0) {
        Usage[] usages = new Usage[conflicts.size()];
        int i = 0;
        for (Pair<PsiElement, PsiElement> pair : conflicts) {
            usages[i] = new NameUsage(pair.getFirst(), pair.getSecond(), name != null ? name : obscured, name != null);
            i += 1;
        }
        UsageViewPresentation prsnt = new UsageViewPresentation();
        prsnt.setTabText(PyBundle.message("CONFLICT.name.$0.obscured", obscured));
        prsnt.setCodeUsagesString(PyBundle.message("CONFLICT.name.$0.obscured.cannot.convert", obscured));
        prsnt.setUsagesWord(PyBundle.message("CONFLICT.occurrence.sing"));
        prsnt.setUsagesString(PyBundle.message("CONFLICT.occurrence.pl"));
        UsageViewManager.getInstance(project).showUsages(UsageTarget.EMPTY_ARRAY, usages, prsnt);
        return true;
    }
    return false;
}
Also used : UsageViewPresentation(com.intellij.usages.UsageViewPresentation) Usage(com.intellij.usages.Usage) PsiElement(com.intellij.psi.PsiElement)

Aggregations

UsageViewPresentation (com.intellij.usages.UsageViewPresentation)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 UsagePreviewPanel (com.intellij.usages.impl.UsagePreviewPanel)3 ActionButton (com.intellij.openapi.actionSystem.impl.ActionButton)2 Project (com.intellij.openapi.project.Project)2 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)2 ListPopup (com.intellij.openapi.ui.popup.ListPopup)2 FindUsagesProcessPresentation (com.intellij.usages.FindUsagesProcessPresentation)2 NotNull (org.jetbrains.annotations.NotNull)2 CommonBundle (com.intellij.CommonBundle)1 com.intellij.find (com.intellij.find)1 FindModel (com.intellij.find.FindModel)1 ShowUsagesAction (com.intellij.find.actions.ShowUsagesAction)1 PsiElement2UsageTargetAdapter (com.intellij.find.findUsages.PsiElement2UsageTargetAdapter)1 AllIcons (com.intellij.icons.AllIcons)1 UISettings (com.intellij.ide.ui.UISettings)1 Disposable (com.intellij.openapi.Disposable)1 MnemonicHelper (com.intellij.openapi.MnemonicHelper)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 CustomComponentAction (com.intellij.openapi.actionSystem.ex.CustomComponentAction)1