Search in sources :

Example 1 with PerlSourceRootType

use of com.perl5.lang.perl.idea.modules.PerlSourceRootType in project Perl5-IDEA by Camelcade.

the class PerlUnmarkSourceRootAction method update.

@Override
public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    RootsSelection selection = getSelection(e);
    if (selection.myModule == null) {
        presentation.setEnabledAndVisible(false);
        return;
    }
    boolean enabled = isEnabled(selection, selection.myModule);
    presentation.setEnabledAndVisible(enabled);
    if (!enabled) {
        return;
    }
    List<VirtualFile> virtualFiles = getFilesFromSelection(selection);
    PerlModuleExtension perlModuleExtension = PerlModuleExtension.getInstance(selection.myModule);
    if (perlModuleExtension == null || virtualFiles.isEmpty()) {
        return;
    }
    if (virtualFiles.size() == 1) {
        PerlSourceRootType type = perlModuleExtension.getRootType(virtualFiles.get(0));
        if (type == null) {
            return;
        }
        ModuleSourceRootEditHandler<?> handler = type.getEditHandler();
        presentation.setText(handler.getUnmarkRootButtonText());
        presentation.setIcon(new LayeredIcon(handler.getRootIcon(), AllIcons.RunConfigurations.InvalidConfigurationLayer));
    } else {
        presentation.setText(PerlBundle.message("perl.action.unmark.multi"));
        presentation.setIcon(new LayeredIcon(PerlIcons.PERL_LANGUAGE_ICON, AllIcons.RunConfigurations.InvalidConfigurationLayer));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LayeredIcon(com.intellij.ui.LayeredIcon) PerlSourceRootType(com.perl5.lang.perl.idea.modules.PerlSourceRootType) Presentation(com.intellij.openapi.actionSystem.Presentation) PerlModuleExtension(com.intellij.openapi.projectRoots.impl.PerlModuleExtension)

Example 2 with PerlSourceRootType

use of com.perl5.lang.perl.idea.modules.PerlSourceRootType 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

VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PerlSourceRootType (com.perl5.lang.perl.idea.modules.PerlSourceRootType)2 PresentationData (com.intellij.ide.projectView.PresentationData)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 Project (com.intellij.openapi.project.Project)1 PerlModuleExtension (com.intellij.openapi.projectRoots.impl.PerlModuleExtension)1 ModuleSourceRootEditHandler (com.intellij.openapi.roots.ui.configuration.ModuleSourceRootEditHandler)1 LayeredIcon (com.intellij.ui.LayeredIcon)1 NotNull (org.jetbrains.annotations.NotNull)1