Search in sources :

Example 51 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.

the class SearchEverywherePsiRenderer method getContainerText.

@Override
protected String getContainerText(PsiElement element, String name) {
    if (element instanceof PsiFileSystemItem) {
        PsiFileSystemItem parent = ((PsiFileSystemItem) element).getParent();
        final PsiDirectory psiDirectory = parent instanceof PsiDirectory ? (PsiDirectory) parent : null;
        VirtualFile virtualFile = psiDirectory == null ? null : psiDirectory.getVirtualFile();
        if (virtualFile == null)
            return null;
        String relativePath = GotoFileCellRenderer.getRelativePath(virtualFile, element.getProject());
        if (relativePath == null)
            return "( " + File.separator + " )";
        int width = myList.getWidth();
        if (width == 0)
            width += 800;
        String path = FilePathSplittingPolicy.SPLIT_BY_SEPARATOR.getOptimalTextForComponent(name, new File(relativePath), this, width - myRightComponentWidth - 16 - 10);
        return "(" + path + ")";
    }
    return getSymbolContainerText(name, element);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 52 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.

the class GoToLinkTargetAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = getEventProject(e);
    VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    if (project != null && file != null && file.is(VFileProperty.SYMLINK)) {
        VirtualFile target = file.getCanonicalFile();
        if (target != null) {
            PsiManager psiManager = PsiManager.getInstance(project);
            PsiFileSystemItem psiFile = target.isDirectory() ? psiManager.findDirectory(target) : psiManager.findFile(target);
            if (psiFile != null) {
                ProjectView.getInstance(project).select(psiFile, target, false);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PsiManager(com.intellij.psi.PsiManager) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

Example 53 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.

the class GotoFileItemProvider method filterElements.

@Override
public boolean filterElements(@NotNull ChooseByNameBase base, @NotNull String pattern, boolean everywhere, @NotNull ProgressIndicator indicator, @NotNull Processor<Object> consumer) {
    if (pattern.contains("/") || pattern.contains("\\")) {
        String path = FileUtil.toSystemIndependentName(ChooseByNamePopup.getTransformedPattern(pattern, myModel));
        VirtualFile vFile = LocalFileSystem.getInstance().findFileByPathIfCached(path);
        if (vFile != null) {
            ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(myProject);
            if (index.isInContent(vFile) || index.isInLibraryClasses(vFile) || index.isInLibrarySource(vFile)) {
                PsiFileSystemItem fileOrDir = vFile.isDirectory() ? PsiManager.getInstance(myProject).findDirectory(vFile) : PsiManager.getInstance(myProject).findFile(vFile);
                if (fileOrDir != null && !consumer.process(fileOrDir)) {
                    return false;
                }
            }
        }
    }
    if (pattern.startsWith("./") || pattern.startsWith(".\\")) {
        pattern = pattern.substring(1);
    }
    return super.filterElements(base, pattern, everywhere, indicator, consumer);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

Example 54 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.

the class NewElementToolbarAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    if (e.getData(LangDataKeys.IDE_VIEW) == null) {
        final Project project = e.getData(CommonDataKeys.PROJECT);
        final PsiFileSystemItem psiFile = e.getData(CommonDataKeys.PSI_FILE).getParent();
        ProjectViewImpl.getInstance(project).selectCB(psiFile, psiFile.getVirtualFile(), true).doWhenDone(() -> showPopup(DataManager.getInstance().getDataContext()));
    } else {
        super.actionPerformed(e);
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

Example 55 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.

the class PyStdlibDocumentationLinkProvider method getExternalDocumentationUrl.

@Override
public String getExternalDocumentationUrl(PsiElement element, PsiElement originalElement) {
    PsiFileSystemItem file = element instanceof PsiFileSystemItem ? (PsiFileSystemItem) element : element.getContainingFile();
    if (PyNames.INIT_DOT_PY.equals(file.getName())) {
        file = file.getParent();
        assert file != null;
    }
    Sdk sdk = PyBuiltinCache.findSdkForFile(file);
    VirtualFile vFile = file.getVirtualFile();
    if (vFile != null && sdk != null && PythonSdkType.isStdLib(vFile, sdk)) {
        QualifiedName qName = QualifiedNameFinder.findCanonicalImportPath(element, originalElement);
        return getStdlibUrlFor(element, qName, sdk);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) QualifiedName(com.intellij.psi.util.QualifiedName) Sdk(com.intellij.openapi.projectRoots.Sdk) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

Aggregations

PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)60 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 Nullable (org.jetbrains.annotations.Nullable)20 PsiElement (com.intellij.psi.PsiElement)18 PsiFile (com.intellij.psi.PsiFile)18 Project (com.intellij.openapi.project.Project)14 PsiDirectory (com.intellij.psi.PsiDirectory)14 NotNull (org.jetbrains.annotations.NotNull)8 Module (com.intellij.openapi.module.Module)7 File (java.io.File)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 ArrayList (java.util.ArrayList)5 PsiManager (com.intellij.psi.PsiManager)4 IProperty (com.intellij.lang.properties.IProperty)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)2 SearchScope (com.intellij.psi.search.SearchScope)2 QualifiedName (com.intellij.psi.util.QualifiedName)2 XmlFile (com.intellij.psi.xml.XmlFile)2