Search in sources :

Example 1 with ItemPresentation

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

the class PyFileImpl method getPresentation.

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

        @Override
        public String getPresentableText() {
            return getModuleName(PyFileImpl.this);
        }

        @Override
        public String getLocationString() {
            final String name = getLocationName();
            return name != null ? "(" + name + ")" : null;
        }

        @Override
        public Icon getIcon(final boolean open) {
            if (PyUtil.isPackage(PyFileImpl.this)) {
                return AllIcons.Modules.SourceFolder;
            }
            return PyFileImpl.this.getIcon(0);
        }

        @NotNull
        private String getModuleName(@NotNull PyFile file) {
            if (PyUtil.isPackage(file)) {
                final PsiDirectory dir = file.getContainingDirectory();
                if (dir != null) {
                    return dir.getName();
                }
            }
            return FileUtil.getNameWithoutExtension(file.getName());
        }

        @Nullable
        private String getLocationName() {
            final QualifiedName name = QualifiedNameFinder.findShortestImportableQName(PyFileImpl.this);
            if (name != null) {
                final QualifiedName prefix = name.removeTail(1);
                if (prefix.getComponentCount() > 0) {
                    return prefix.toString();
                }
            }
            final String relativePath = getRelativeContainerPath();
            if (relativePath != null) {
                return relativePath;
            }
            final PsiDirectory psiDirectory = getParent();
            if (psiDirectory != null) {
                return psiDirectory.getVirtualFile().getPresentableUrl();
            }
            return null;
        }

        @Nullable
        private String getRelativeContainerPath() {
            final PsiDirectory psiDirectory = getParent();
            if (psiDirectory != null) {
                final VirtualFile virtualFile = getVirtualFile();
                if (virtualFile != null) {
                    final VirtualFile root = ProjectFileIndex.SERVICE.getInstance(getProject()).getContentRootForFile(virtualFile);
                    if (root != null) {
                        final VirtualFile parent = virtualFile.getParent();
                        final VirtualFile rootParent = root.getParent();
                        if (rootParent != null && parent != null) {
                            return VfsUtilCore.getRelativePath(parent, rootParent, File.separatorChar);
                        }
                    }
                }
            }
            return null;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) QualifiedName(com.intellij.psi.util.QualifiedName) ItemPresentation(com.intellij.navigation.ItemPresentation) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ItemPresentation

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

the class PyElementNode method updateImpl.

@Override
protected void updateImpl(PresentationData data) {
    final PyElement value = getValue();
    final String name = value.getName();
    final ItemPresentation presentation = value.getPresentation();
    String presentableText = name != null ? name : PyNames.UNNAMED_ELEMENT;
    Icon presentableIcon = value.getIcon(0);
    if (presentation != null) {
        final String text = presentation.getPresentableText();
        if (text != null) {
            presentableText = text;
        }
        final Icon icon = presentation.getIcon(false);
        if (icon != null) {
            presentableIcon = icon;
        }
    }
    data.setPresentableText(presentableText);
    data.setIcon(presentableIcon);
}
Also used : ItemPresentation(com.intellij.navigation.ItemPresentation) PyElement(com.jetbrains.python.psi.PyElement)

Example 3 with ItemPresentation

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

the class PyStructureViewElement method getPresentation.

@NotNull
@Override
public ItemPresentation getPresentation() {
    final PyElement element = getValue();
    final ItemPresentation presentation = element != null ? element.getPresentation() : null;
    return new ColoredItemPresentation() {

        @Nullable
        @Override
        public String getPresentableText() {
            if (element instanceof PyFile) {
                return element.getName();
            }
            return presentation != null ? presentation.getPresentableText() : PyNames.UNNAMED_ELEMENT;
        }

        @Nullable
        @Override
        public TextAttributesKey getTextAttributesKey() {
            if (isInherited()) {
                return CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES;
            }
            return null;
        }

        @Nullable
        @Override
        public String getLocationString() {
            return null;
        }

        @Nullable
        @Override
        public Icon getIcon(boolean open) {
            if (element == null) {
                return null;
            }
            Icon normal_icon = element.getIcon(0);
            // override normal
            if (myIcon != null)
                normal_icon = myIcon;
            if (myVisibility == Visibility.NORMAL) {
                return normal_icon;
            } else {
                LayeredIcon icon = new LayeredIcon(2);
                icon.setIcon(normal_icon, 0);
                Icon overlay = null;
                if (myVisibility == Visibility.PRIVATE || myVisibility == Visibility.PROTECTED) {
                    overlay = PythonIcons.Python.Nodes.Lock;
                } else if (myVisibility == Visibility.PREDEFINED) {
                    overlay = PythonIcons.Python.Nodes.Cyan_dot;
                } else if (myVisibility == Visibility.INVISIBLE) {
                    overlay = PythonIcons.Python.Nodes.Red_inv_triangle;
                }
                if (overlay != null) {
                    icon.setIcon(overlay, 1);
                }
                return icon;
            }
        }
    };
}
Also used : LayeredIcon(com.intellij.ui.LayeredIcon) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) ItemPresentation(com.intellij.navigation.ItemPresentation) LayeredIcon(com.intellij.ui.LayeredIcon) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ItemPresentation

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

the class ResourceBundleEditorRenderer method customize.

private boolean customize(Object value) {
    final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
    if (!(userObject instanceof TreeElementWrapper)) {
        return false;
    }
    final TreeElement treeElement = ((TreeElementWrapper) userObject).getValue();
    if (treeElement == null) {
        return false;
    }
    final ItemPresentation presentation = treeElement.getPresentation();
    if (presentation instanceof TextAttributesPresentation) {
        final TextAttributesPresentation textAttributesPresentation = (TextAttributesPresentation) presentation;
        final String text = textAttributesPresentation.getPresentableText();
        if (text != null) {
            final SimpleTextAttributes attr = SimpleTextAttributes.fromTextAttributes(textAttributesPresentation.getTextAttributes(getColorsScheme()));
            append(text, new SimpleTextAttributes(attr.getBgColor(), attr.getFgColor(), attr.getWaveColor(), attr.getStyle() | SimpleTextAttributes.STYLE_OPAQUE));
            return true;
        }
    }
    return false;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeElementWrapper(com.intellij.ide.util.treeView.smartTree.TreeElementWrapper) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) ItemPresentation(com.intellij.navigation.ItemPresentation) TreeElement(com.intellij.ide.util.treeView.smartTree.TreeElement)

Example 5 with ItemPresentation

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

the class PyHierarchyNodeDescriptor method update.

@Override
public boolean update() {
    boolean changes = super.update();
    final CompositeAppearance oldText = myHighlightedText;
    myHighlightedText = new CompositeAppearance();
    NavigatablePsiElement element = (NavigatablePsiElement) getPsiElement();
    if (element == null) {
        final String invalidPrefix = IdeBundle.message("node.hierarchy.invalid");
        if (!myHighlightedText.getText().startsWith(invalidPrefix)) {
            myHighlightedText.getBeginning().addText(invalidPrefix, HierarchyNodeDescriptor.getInvalidPrefixAttributes());
        }
        return true;
    }
    final ItemPresentation presentation = element.getPresentation();
    if (presentation != null) {
        if (element instanceof PyFunction) {
            final PyClass cls = ((PyFunction) element).getContainingClass();
            if (cls != null) {
                myHighlightedText.getEnding().addText(cls.getName() + ".");
            }
        }
        myHighlightedText.getEnding().addText(presentation.getPresentableText());
        myHighlightedText.getEnding().addText(" " + presentation.getLocationString(), HierarchyNodeDescriptor.getPackageNameAttributes());
    }
    myName = myHighlightedText.getText();
    if (!Comparing.equal(myHighlightedText, oldText)) {
        changes = true;
    }
    return changes;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyFunction(com.jetbrains.python.psi.PyFunction) ItemPresentation(com.intellij.navigation.ItemPresentation) CompositeAppearance(com.intellij.openapi.roots.ui.util.CompositeAppearance) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement)

Aggregations

ItemPresentation (com.intellij.navigation.ItemPresentation)43 NotNull (org.jetbrains.annotations.NotNull)11 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 CompositeAppearance (com.intellij.openapi.roots.ui.util.CompositeAppearance)4 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)4 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)4 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)3 LayeredIcon (com.intellij.ui.LayeredIcon)3 DartClass (com.jetbrains.lang.dart.psi.DartClass)3 StructureViewTreeElement (com.intellij.ide.structureView.StructureViewTreeElement)2 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