Search in sources :

Example 36 with ItemPresentation

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

the class XPathEvalAction method showUsageView.

public static void showUsageView(@NotNull final Project project, MyUsageTarget usageTarget, Factory<UsageSearcher> searcherFactory, final EditExpressionAction editAction) {
    final UsageViewPresentation presentation = new UsageViewPresentation();
    presentation.setTargetsNodeText("XPath Expression");
    presentation.setCodeUsages(false);
    presentation.setCodeUsagesString("Found Matches");
    presentation.setNonCodeUsagesString("Result");
    presentation.setUsagesString("XPath Result");
    presentation.setUsagesWord("match");
    final ItemPresentation targetPresentation = usageTarget.getPresentation();
    if (targetPresentation != null) {
        presentation.setTabText(StringUtil.shortenTextWithEllipsis("XPath '" + targetPresentation.getPresentableText() + '\'', 60, 0, true));
    } else {
        presentation.setTabText("XPath");
    }
    presentation.setScopeText("XML Files");
    presentation.setOpenInNewTab(FindSettings.getInstance().isShowResultsInSeparateView());
    final FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation(presentation);
    processPresentation.setProgressIndicatorFactory(() -> new FindProgressIndicator(project, "XML Document(s)"));
    processPresentation.setShowPanelIfOnlyOneUsage(true);
    processPresentation.setShowNotFoundMessage(true);
    final UsageTarget[] usageTargets = { usageTarget };
    UsageViewManager.getInstance(project).searchAndShowUsages(usageTargets, searcherFactory, processPresentation, presentation, new UsageViewManager.UsageViewStateListener() {

        @Override
        public void usageViewCreated(@NotNull UsageView usageView) {
            usageView.addButtonToLowerPane(editAction, "&Edit Expression");
        }

        @Override
        public void findingUsagesFinished(UsageView usageView) {
        }
    });
}
Also used : FindProgressIndicator(com.intellij.find.FindProgressIndicator) ItemPresentation(com.intellij.navigation.ItemPresentation)

Example 37 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 38 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)

Example 39 with ItemPresentation

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

the class AbstractDartComponentImpl method getPresentation.

@Override
public ItemPresentation getPresentation() {
    return new ItemPresentation() {

        @Override
        public String getPresentableText() {
            final StringBuilder result = new StringBuilder();
            result.append(getComponentName());
            final DartComponentType type = DartComponentType.typeOf(AbstractDartComponentImpl.this);
            if ((type == DartComponentType.METHOD || type == DartComponentType.FUNCTION || type == DartComponentType.CONSTRUCTOR || type == DartComponentType.OPERATOR) && !(isGetter() || isSetter())) {
                final String parameterList = DartPresentableUtil.getPresentableParameterList(AbstractDartComponentImpl.this);
                result.append("(").append(parameterList).append(")");
            }
            if (type == DartComponentType.METHOD || type == DartComponentType.FIELD || type == DartComponentType.FUNCTION || type == DartComponentType.OPERATOR) {
                final DartReturnType returnType = PsiTreeUtil.getChildOfType(AbstractDartComponentImpl.this, DartReturnType.class);
                final DartType dartType = PsiTreeUtil.getChildOfType(AbstractDartComponentImpl.this, DartType.class);
                if (returnType != null) {
                    result.append(" ").append(DartPresentableUtil.RIGHT_ARROW).append(" ");
                    result.append(DartPresentableUtil.buildTypeText(AbstractDartComponentImpl.this, returnType, null));
                } else if (dartType != null) {
                    result.append(" ").append(DartPresentableUtil.RIGHT_ARROW).append(" ");
                    result.append(DartPresentableUtil.buildTypeText(AbstractDartComponentImpl.this, dartType, null));
                }
            }
            return result.toString();
        }

        @Nullable
        private String getComponentName() {
            String name = getName();
            if (DartComponentType.typeOf(AbstractDartComponentImpl.this) == DartComponentType.CONSTRUCTOR) {
                DartClass dartClass = PsiTreeUtil.getParentOfType(AbstractDartComponentImpl.this, DartClass.class);
                if (dartClass == null) {
                    return name;
                }
                return StringUtil.isEmpty(name) ? dartClass.getName() : dartClass.getName() + "." + name;
            }
            return name;
        }

        @Override
        public String getLocationString() {
            if (!isValid()) {
                return "";
            }
            if (!(AbstractDartComponentImpl.this instanceof DartClass)) {
                final DartClass dartClass = PsiTreeUtil.getParentOfType(AbstractDartComponentImpl.this, DartClass.class);
                if (dartClass != null) {
                    return dartClass.getName();
                }
            }
            DartExecutionScope root = PsiTreeUtil.getTopmostParentOfType(AbstractDartComponentImpl.this, DartExecutionScope.class);
            DartPartOfStatement partOfStatement = PsiTreeUtil.getChildOfType(root, DartPartOfStatement.class);
            return partOfStatement == null ? null : partOfStatement.getLibraryName();
        }

        @Override
        public Icon getIcon(boolean open) {
            return AbstractDartComponentImpl.this.getIcon(0);
        }
    };
}
Also used : DartComponentType(com.jetbrains.lang.dart.DartComponentType) ItemPresentation(com.intellij.navigation.ItemPresentation)

Example 40 with ItemPresentation

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

the class ReferenceExpressionPsiTest method testSimpleReference.

public void testSimpleReference() {
    final OgnlReferenceExpression expression = parse("exp");
    final ItemPresentation presentation = expression.getPresentation();
    assertNotNull(presentation);
    assertEquals("exp", presentation.getPresentableText());
    assertNull(expression.getType());
    final PsiReference reference = expression.getReference();
    assertNotNull(reference);
    assertEquals("exp", reference.getCanonicalText());
    assertEquals(expression.getNavigationElement(), reference.resolve());
}
Also used : ItemPresentation(com.intellij.navigation.ItemPresentation) PsiReference(com.intellij.psi.PsiReference)

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