Search in sources :

Example 31 with ItemPresentation

use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.

the class YAMLKeyValueImpl method getPresentation.

@Override
public ItemPresentation getPresentation() {
    final YAMLFile yamlFile = (YAMLFile) getContainingFile();
    final PsiElement value = getValue();
    return new ItemPresentation() {

        public String getPresentableText() {
            if (value instanceof YAMLScalar) {
                return getValueText();
            }
            return getName();
        }

        public String getLocationString() {
            return "[" + yamlFile.getName() + "]";
        }

        public Icon getIcon(boolean open) {
            return YAMLKeyValueImpl.this.getIcon(0);
        }
    };
}
Also used : ItemPresentation(com.intellij.navigation.ItemPresentation) PsiElement(com.intellij.psi.PsiElement)

Example 32 with ItemPresentation

use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.

the class Bookmark method getQualifiedName.

public String getQualifiedName() {
    String presentableUrl = myFile.getPresentableUrl();
    if (myFile.isDirectory())
        return presentableUrl;
    final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(myFile);
    if (psiFile == null)
        return presentableUrl;
    StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(psiFile);
    if (builder instanceof TreeBasedStructureViewBuilder) {
        StructureViewModel model = ((TreeBasedStructureViewBuilder) builder).createStructureViewModel(null);
        Object element;
        try {
            element = model.getCurrentEditorElement();
        } finally {
            model.dispose();
        }
        if (element instanceof NavigationItem) {
            ItemPresentation presentation = ((NavigationItem) element).getPresentation();
            if (presentation != null) {
                presentableUrl = ((NavigationItem) element).getName() + " " + presentation.getLocationString();
            }
        }
    }
    return IdeBundle.message("bookmark.file.X.line.Y", presentableUrl, getLine() + 1);
}
Also used : LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) NavigationItem(com.intellij.navigation.NavigationItem) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) ItemPresentation(com.intellij.navigation.ItemPresentation) PsiFile(com.intellij.psi.PsiFile)

Example 33 with ItemPresentation

use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.

the class ShowRecentFindUsagesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    UsageView usageView = e.getData(UsageView.USAGE_VIEW_KEY);
    Project project = e.getData(CommonDataKeys.PROJECT);
    final FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager();
    List<ConfigurableUsageTarget> history = new ArrayList<>(findUsagesManager.getHistory().getAll());
    if (!history.isEmpty()) {
        // skip most recent find usage, it's under your nose
        history.remove(history.size() - 1);
        Collections.reverse(history);
    }
    if (history.isEmpty()) {
        // to fill the popup
        history.add(null);
    }
    BaseListPopupStep<ConfigurableUsageTarget> step = new BaseListPopupStep<ConfigurableUsageTarget>(FindBundle.message("recent.find.usages.action.title"), history) {

        @Override
        public Icon getIconFor(final ConfigurableUsageTarget data) {
            ItemPresentation presentation = data == null ? null : data.getPresentation();
            return presentation == null ? null : presentation.getIcon(false);
        }

        @Override
        @NotNull
        public String getTextFor(final ConfigurableUsageTarget data) {
            if (data == null) {
                return FindBundle.message("recent.find.usages.action.nothing");
            }
            return data.getLongDescriptiveName();
        }

        @Override
        public PopupStep onChosen(final ConfigurableUsageTarget selectedValue, final boolean finalChoice) {
            return doFinalStep(() -> {
                if (selectedValue != null) {
                    TransactionGuard.getInstance().submitTransactionAndWait(() -> findUsagesManager.rerunAndRecallFromHistory(selectedValue));
                }
            });
        }
    };
    RelativePoint point;
    if (e.getInputEvent() instanceof MouseEvent) {
        point = new RelativePoint((MouseEvent) e.getInputEvent());
    } else {
        point = new RelativePoint(usageView.getComponent(), new Point(4, 4));
    }
    JBPopupFactory.getInstance().createListPopup(step).show(point);
}
Also used : MouseEvent(java.awt.event.MouseEvent) ArrayList(java.util.ArrayList) ItemPresentation(com.intellij.navigation.ItemPresentation) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) UsageView(com.intellij.usages.UsageView) Project(com.intellij.openapi.project.Project) ConfigurableUsageTarget(com.intellij.usages.ConfigurableUsageTarget) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) FindUsagesManager(com.intellij.find.findUsages.FindUsagesManager)

Example 34 with ItemPresentation

use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.

the class HighlightOverridingMethodsHandler method computeUsages.

@Override
public void computeUsages(final List<PsiClass> classes) {
    for (PsiMethod method : myClass.getMethods()) {
        List<HierarchicalMethodSignature> superSignatures = method.getHierarchicalMethodSignature().getSuperSignatures();
        for (HierarchicalMethodSignature superSignature : superSignatures) {
            PsiClass containingClass = superSignature.getMethod().getContainingClass();
            if (containingClass == null)
                continue;
            for (PsiClass classToAnalyze : classes) {
                if (InheritanceUtil.isInheritorOrSelf(classToAnalyze, containingClass, true)) {
                    PsiIdentifier identifier = method.getNameIdentifier();
                    if (identifier != null) {
                        addOccurrence(identifier);
                        break;
                    }
                }
            }
        }
    }
    if (myReadUsages.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode())
            return;
        String name;
        if (classes.size() == 1) {
            final ItemPresentation presentation = classes.get(0).getPresentation();
            name = presentation != null ? presentation.getPresentableText() : "";
        } else {
            name = "";
        }
        myHintText = CodeInsightBundle.message("no.methods.overriding.0.are.found", classes.size(), name);
    } else {
        addOccurrence(myTarget);
        // exclude 'target' keyword
        final int methodCount = myReadUsages.size() - 1;
        myStatusText = CodeInsightBundle.message("status.bar.overridden.methods.highlighted.message", methodCount, HighlightUsagesHandler.getShortcutText());
    }
}
Also used : ItemPresentation(com.intellij.navigation.ItemPresentation)

Example 35 with ItemPresentation

use of com.intellij.navigation.ItemPresentation in project intellij-community by JetBrains.

the class PyStructureViewTest method testInvalidatedElement.

// EA-83566
public void testInvalidatedElement() {
    myFixture.configureByText("a.py", "def f():\n" + "    pass");
    final PyFunction function = myFixture.findElementByText("f", PyFunction.class);
    final PyStructureViewElement node = new PyStructureViewElement(function);
    WriteCommandAction.runWriteCommandAction(myFixture.getProject(), function::delete);
    assertNull(node.getValue());
    final ItemPresentation presentation = node.getPresentation();
    assertNotNull(presentation);
    final Icon icon = presentation.getIcon(false);
    assertNull(icon);
}
Also used : PyFunction(com.jetbrains.python.psi.PyFunction) PyStructureViewElement(com.jetbrains.python.structureView.PyStructureViewElement) ItemPresentation(com.intellij.navigation.ItemPresentation)

Aggregations

ItemPresentation (com.intellij.navigation.ItemPresentation)40 NotNull (org.jetbrains.annotations.NotNull)10 NavigationItem (com.intellij.navigation.NavigationItem)8 Nullable (org.jetbrains.annotations.Nullable)8 PsiFile (com.intellij.psi.PsiFile)6 Parent (org.elixir_lang.navigation.item_presentation.Parent)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 PsiElement (com.intellij.psi.PsiElement)5 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)4 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)3 CompositeAppearance (com.intellij.openapi.roots.ui.util.CompositeAppearance)3 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)3 LayeredIcon (com.intellij.ui.LayeredIcon)3 DartClass (com.jetbrains.lang.dart.psi.DartClass)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 ColoredItemPresentation (com.intellij.navigation.ColoredItemPresentation)2 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 JBColor (com.intellij.ui.JBColor)2 RowIcon (com.intellij.ui.RowIcon)2