Search in sources :

Example 6 with NavigationItem

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

the class PsiElement2UsageTargetAdapter method update.

private void update(PsiElement element) {
    if (element != null && element.isValid()) {
        final ItemPresentation presentation = ((NavigationItem) element).getPresentation();
        myIconOpen = presentation == null ? null : ComputableIcon.create(presentation, true);
        myIconClosed = presentation == null ? null : ComputableIcon.create(presentation, false);
        myPresentableText = presentation == null ? UsageViewUtil.createNodeText(element) : presentation.getPresentableText();
        if (myIconOpen == null || myIconClosed == null) {
            if (element instanceof PsiMetaOwner) {
                final PsiMetaOwner psiMetaOwner = (PsiMetaOwner) element;
                final PsiMetaData metaData = psiMetaOwner.getMetaData();
                if (metaData instanceof PsiPresentableMetaData) {
                    final PsiPresentableMetaData psiPresentableMetaData = (PsiPresentableMetaData) metaData;
                    if (myIconOpen == null)
                        myIconOpen = ComputableIcon.create(psiPresentableMetaData);
                    if (myIconClosed == null)
                        myIconClosed = ComputableIcon.create(psiPresentableMetaData);
                }
            } else if (element instanceof PsiFile) {
                final PsiFile psiFile = (PsiFile) element;
                final VirtualFile virtualFile = psiFile.getVirtualFile();
                if (virtualFile != null) {
                    myIconOpen = ComputableIcon.create(virtualFile);
                    myIconClosed = ComputableIcon.create(virtualFile);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiPresentableMetaData(com.intellij.psi.meta.PsiPresentableMetaData) NavigationItem(com.intellij.navigation.NavigationItem) PsiElementNavigationItem(com.intellij.navigation.PsiElementNavigationItem) PsiMetaData(com.intellij.psi.meta.PsiMetaData) ItemPresentation(com.intellij.navigation.ItemPresentation) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner)

Example 7 with NavigationItem

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

the class SearchEverywherePsiRenderer method customizeNonPsiElementLeftRenderer.

@Override
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
    if (!(value instanceof NavigationItem))
        return false;
    NavigationItem item = (NavigationItem) value;
    TextAttributes attributes = getNavigationItemAttributes(item);
    SimpleTextAttributes nameAttributes = attributes != null ? SimpleTextAttributes.fromTextAttributes(attributes) : null;
    Color color = list.getForeground();
    if (nameAttributes == null)
        nameAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
    renderer.append(item + " ", nameAttributes);
    ItemPresentation itemPresentation = item.getPresentation();
    assert itemPresentation != null;
    renderer.setIcon(itemPresentation.getIcon(true));
    String locationString = itemPresentation.getLocationString();
    if (!StringUtil.isEmpty(locationString)) {
        renderer.append(locationString, new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
    }
    return true;
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) JBColor(com.intellij.ui.JBColor) ItemPresentation(com.intellij.navigation.ItemPresentation) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Example 8 with NavigationItem

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

the class NavigationUtil method openFileWithPsiElement.

public static boolean openFileWithPsiElement(PsiElement element, boolean searchForOpen, boolean requestFocus) {
    boolean openAsNative = false;
    if (element instanceof PsiFile) {
        VirtualFile virtualFile = ((PsiFile) element).getVirtualFile();
        if (virtualFile != null) {
            openAsNative = ElementBase.isNativeFileType(virtualFile.getFileType());
        }
    }
    if (searchForOpen) {
        element.putUserData(FileEditorManager.USE_CURRENT_WINDOW, null);
    } else {
        element.putUserData(FileEditorManager.USE_CURRENT_WINDOW, true);
    }
    if (openAsNative || !activatePsiElementIfOpen(element, searchForOpen, requestFocus)) {
        final NavigationItem navigationItem = (NavigationItem) element;
        if (!navigationItem.canNavigate())
            return false;
        navigationItem.navigate(requestFocus);
        return true;
    }
    element.putUserData(FileEditorManager.USE_CURRENT_WINDOW, null);
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NavigationItem(com.intellij.navigation.NavigationItem) PsiFile(com.intellij.psi.PsiFile)

Example 9 with NavigationItem

use of com.intellij.navigation.NavigationItem in project kotlin by JetBrains.

the class ReferenceUtils method renderAsGotoImplementation.

public static String renderAsGotoImplementation(@NotNull PsiElement element) {
    PsiElement navigationElement = element.getNavigationElement();
    if (navigationElement instanceof KtObjectDeclaration && ((KtObjectDeclaration) navigationElement).isCompanion()) {
        //default presenter return null for companion object
        KtClass containingClass = PsiTreeUtil.getParentOfType(navigationElement, KtClass.class);
        assert containingClass != null;
        return "companion object of " + renderAsGotoImplementation(containingClass);
    }
    if (navigationElement instanceof KtStringTemplateExpression) {
        return KtPsiUtilKt.getPlainContent((KtStringTemplateExpression) navigationElement);
    }
    Assert.assertTrue(navigationElement instanceof NavigationItem);
    ItemPresentation presentation = ((NavigationItem) navigationElement).getPresentation();
    if (presentation == null) {
        String elementText = element.getText();
        return elementText != null ? elementText : navigationElement.getText();
    }
    String presentableText = presentation.getPresentableText();
    String locationString = presentation.getLocationString();
    if (locationString == null && element.getParent() instanceof PsiAnonymousClass) {
        locationString = "<anonymous>";
    }
    return locationString == null || navigationElement instanceof PsiPackage ? // for PsiPackage, presentableText is FQ name of current package
    presentableText : locationString + "." + presentableText;
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) KtClass(org.jetbrains.kotlin.psi.KtClass) KtStringTemplateExpression(org.jetbrains.kotlin.psi.KtStringTemplateExpression) ItemPresentation(com.intellij.navigation.ItemPresentation) KtObjectDeclaration(org.jetbrains.kotlin.psi.KtObjectDeclaration)

Example 10 with NavigationItem

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

the class GoToPackageSymbolProvider method addItems.

protected void addItems(@NotNull final Module module, final String name, final List<NavigationItem> result) {
    final StrutsModel strutsModel = StrutsManager.getInstance(module.getProject()).getCombinedModel(module);
    if (strutsModel == null) {
        return;
    }
    final List<StrutsPackage> strutsPackageList = strutsModel.getStrutsPackages();
    for (final StrutsPackage strutsPackage : strutsPackageList) {
        if (Comparing.strEqual(name, strutsPackage.getName().getStringValue())) {
            final NavigationItem item = createNavigationItem(strutsPackage.getXmlTag(), name, StrutsIcons.STRUTS_PACKAGE);
            result.add(item);
        }
    }
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)

Aggregations

NavigationItem (com.intellij.navigation.NavigationItem)25 ItemPresentation (com.intellij.navigation.ItemPresentation)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)6 PsiFile (com.intellij.psi.PsiFile)5 PsiElementNavigationItem (com.intellij.navigation.PsiElementNavigationItem)4 PsiElement (com.intellij.psi.PsiElement)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 ArrayList (java.util.ArrayList)4 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)3 Project (com.intellij.openapi.project.Project)3 ChooseByNameContributor (com.intellij.navigation.ChooseByNameContributor)2 Logger (com.intellij.openapi.diagnostic.Logger)2 com.intellij.psi (com.intellij.psi)2 HintManager (com.intellij.codeInsight.hint.HintManager)1 DebuggerBundle (com.intellij.debugger.DebuggerBundle)1 NoDataException (com.intellij.debugger.NoDataException)1 SourcePosition (com.intellij.debugger.SourcePosition)1 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 PositionManagerImpl (com.intellij.debugger.engine.PositionManagerImpl)1