Search in sources :

Example 1 with ModuleSourceRootEditHandler

use of com.intellij.openapi.roots.ui.configuration.ModuleSourceRootEditHandler in project intellij-community by JetBrains.

the class ProjectViewDirectoryHelper method getLocationString.

@Nullable
public String getLocationString(@NotNull PsiDirectory psiDirectory, boolean includeUrl, boolean includeRootType) {
    StringBuilder result = new StringBuilder();
    final VirtualFile directory = psiDirectory.getVirtualFile();
    if (ProjectRootsUtil.isLibraryRoot(directory, psiDirectory.getProject())) {
        result.append(ProjectBundle.message("module.paths.root.node", "library").toLowerCase(Locale.getDefault()));
    } else if (includeRootType) {
        SourceFolder sourceRoot = ProjectRootsUtil.getModuleSourceRoot(psiDirectory.getVirtualFile(), psiDirectory.getProject());
        if (sourceRoot != null) {
            ModuleSourceRootEditHandler<?> handler = ModuleSourceRootEditHandler.getEditHandler(sourceRoot.getRootType());
            if (handler != null) {
                JavaSourceRootProperties properties = sourceRoot.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
                if (properties != null && properties.isForGeneratedSources()) {
                    result.append("generated ");
                }
                result.append(handler.getFullRootTypeName().toLowerCase(Locale.getDefault()));
            }
        }
    }
    if (includeUrl) {
        if (result.length() > 0)
            result.append(",").append(FontUtil.spaceAndThinSpace());
        result.append(FileUtil.getLocationRelativeToUserHome(directory.getPresentableUrl()));
    }
    return result.length() == 0 ? null : result.toString();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleSourceRootEditHandler(com.intellij.openapi.roots.ui.configuration.ModuleSourceRootEditHandler) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ModuleSourceRootEditHandler

use of com.intellij.openapi.roots.ui.configuration.ModuleSourceRootEditHandler in project Perl5-IDEA by Camelcade.

the class PerlTreeStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    Map<VirtualFile, PerlSourceRootType> roots = myProjectManager.getAllModulesRoots();
    return ContainerUtil.map2List(children, node -> {
        if (!(node instanceof PsiDirectoryNode)) {
            return node;
        }
        Project nodeProject = node.getProject();
        if (nodeProject == null) {
            return node;
        }
        // fixme support different roots here
        VirtualFile virtualFile = ((PsiDirectoryNode) node).getVirtualFile();
        if (virtualFile != null && roots.containsKey(virtualFile)) {
            PerlSourceRootType rootType = roots.get(virtualFile);
            ModuleSourceRootEditHandler handler = rootType.getEditHandler();
            node = new PsiDirectoryNode(node.getProject(), ((PsiDirectoryNode) node).getValue(), ((PsiDirectoryNode) node).getSettings()) {

                @Override
                protected void updateImpl(PresentationData data) {
                    super.updateImpl(data);
                    data.setIcon(handler.getRootIcon());
                    data.addText(virtualFile.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
                    data.addText(" " + handler.getRootTypeName(), SimpleTextAttributes.GRAY_ATTRIBUTES);
                }
            };
        }
        return node;
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PresentationData(com.intellij.ide.projectView.PresentationData) PerlSourceRootType(com.perl5.lang.perl.idea.modules.PerlSourceRootType) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) ModuleSourceRootEditHandler(com.intellij.openapi.roots.ui.configuration.ModuleSourceRootEditHandler) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ModuleSourceRootEditHandler (com.intellij.openapi.roots.ui.configuration.ModuleSourceRootEditHandler)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PresentationData (com.intellij.ide.projectView.PresentationData)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 Project (com.intellij.openapi.project.Project)1 PerlSourceRootType (com.perl5.lang.perl.idea.modules.PerlSourceRootType)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 JavaSourceRootProperties (org.jetbrains.jps.model.java.JavaSourceRootProperties)1