Search in sources :

Example 16 with SourceFolder

use of com.intellij.openapi.roots.SourceFolder in project intellij-community by JetBrains.

the class ContentEntryImpl method cloneEntry.

@Override
@NotNull
public ContentEntry cloneEntry(@NotNull RootModelImpl rootModel) {
    assert !isDisposed();
    ContentEntryImpl cloned = new ContentEntryImpl(myRoot.getUrl(), rootModel);
    for (final SourceFolder sourceFolder : mySourceFolders) {
        if (sourceFolder instanceof ClonableContentFolder) {
            ContentFolder folder = ((ClonableContentFolder) sourceFolder).cloneFolder(cloned);
            cloned.addSourceFolder((SourceFolderImpl) folder);
        }
    }
    for (final ExcludeFolder excludeFolder : myExcludeFolders) {
        if (excludeFolder instanceof ClonableContentFolder) {
            ContentFolder folder = ((ClonableContentFolder) excludeFolder).cloneFolder(cloned);
            cloned.addExcludeFolder((ExcludeFolder) folder);
        }
    }
    return cloned;
}
Also used : SourceFolder(com.intellij.openapi.roots.SourceFolder) ContentFolder(com.intellij.openapi.roots.ContentFolder) ExcludeFolder(com.intellij.openapi.roots.ExcludeFolder) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with SourceFolder

use of com.intellij.openapi.roots.SourceFolder in project intellij-community by JetBrains.

the class DirectoryPresentationProvider method getPresentation.

@Override
public ItemPresentation getPresentation(@NotNull final PsiDirectory directory) {
    final VirtualFile vFile = directory.getVirtualFile();
    final Project project = directory.getProject();
    final String locationString = vFile.getPath();
    if (ProjectRootsUtil.isProjectHome(directory)) {
        final Icon projectIcon = PlatformUtils.isJetBrainsProduct() ? AllIcons.Nodes.IdeaProject : IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl());
        return new PresentationData(project.getName(), locationString, projectIcon, null);
    }
    if (ProjectRootsUtil.isModuleContentRoot(directory)) {
        final Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(vFile);
        assert module != null : directory;
        return new PresentationData(module.getName(), locationString, PlatformIcons.CONTENT_ROOT_ICON_CLOSED, null);
    }
    if (ProjectRootsUtil.isSourceRoot(directory)) {
        SourceFolder sourceRoot = ProjectRootsUtil.getModuleSourceRoot(vFile, project);
        if (sourceRoot != null) {
            Icon icon = SourceRootPresentation.getSourceRootIcon(sourceRoot);
            return new PresentationData(directory.getName(), locationString, icon, null);
        }
    }
    return new PresentationData(directory.getName(), locationString, PlatformIcons.DIRECTORY_CLOSED_ICON, null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) SourceFolder(com.intellij.openapi.roots.SourceFolder) PresentationData(com.intellij.ide.projectView.PresentationData) Module(com.intellij.openapi.module.Module)

Example 18 with SourceFolder

use of com.intellij.openapi.roots.SourceFolder in project intellij-community by JetBrains.

the class ToggleSourcesStateAction method setSelected.

@Override
public void setSelected(final AnActionEvent e, final boolean isSelected) {
    final VirtualFile[] selectedFiles = getSelectedFiles();
    assert selectedFiles.length != 0;
    final ContentEntryEditor contentEntryEditor = myEntryTreeEditor.getContentEntryEditor();
    for (VirtualFile selectedFile : selectedFiles) {
        final SourceFolder sourceFolder = contentEntryEditor.getSourceFolder(selectedFile);
        if (isSelected) {
            if (sourceFolder == null) {
                // not marked yet
                P properties = myEditHandler.getRootType().createDefaultProperties();
                contentEntryEditor.addSourceFolder(selectedFile, myEditHandler.getRootType(), properties);
            } else if (!myEditHandler.getRootType().equals(sourceFolder.getRootType())) {
                P properties;
                if (myEditHandler.getRootType().getClass().equals(sourceFolder.getRootType().getClass())) {
                    properties = (P) sourceFolder.getJpsElement().getProperties().getBulkModificationSupport().createCopy();
                } else {
                    properties = myEditHandler.getRootType().createDefaultProperties();
                }
                contentEntryEditor.removeSourceFolder(sourceFolder);
                contentEntryEditor.addSourceFolder(selectedFile, myEditHandler.getRootType(), properties);
            }
        } else if (sourceFolder != null) {
            // already marked
            contentEntryEditor.removeSourceFolder(sourceFolder);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFolder(com.intellij.openapi.roots.SourceFolder) ContentEntryEditor(com.intellij.openapi.roots.ui.configuration.ContentEntryEditor)

Example 19 with SourceFolder

use of com.intellij.openapi.roots.SourceFolder in project intellij-community by JetBrains.

the class ContentEntryTreeCellRenderer method getPresentablePrefix.

private static String getPresentablePrefix(final ContentEntry entry, final VirtualFile file) {
    for (final SourceFolder sourceFolder : entry.getSourceFolders()) {
        if (file.equals(sourceFolder.getFile())) {
            JpsModuleSourceRoot element = sourceFolder.getJpsElement();
            JavaSourceRootProperties properties = element.getProperties(JavaModuleSourceRootTypes.SOURCES);
            if (properties != null)
                return properties.getPackagePrefix();
            JavaResourceRootProperties resourceRootProperties = element.getProperties(JavaModuleSourceRootTypes.RESOURCES);
            if (resourceRootProperties != null)
                return resourceRootProperties.getRelativeOutputPath();
        }
    }
    return "";
}
Also used : SourceFolder(com.intellij.openapi.roots.SourceFolder) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) JavaResourceRootProperties(org.jetbrains.jps.model.java.JavaResourceRootProperties) JavaSourceRootProperties(org.jetbrains.jps.model.java.JavaSourceRootProperties)

Example 20 with SourceFolder

use of com.intellij.openapi.roots.SourceFolder in project intellij-community by JetBrains.

the class PythonSourceRootConfigurator method addSourceRoot.

private static void addSourceRoot(Project project, final VirtualFile baseDir, final VirtualFile root, final boolean unique) {
    final Module[] modules = ModuleManager.getInstance(project).getModules();
    if (modules.length > 0 && root != null) {
        ApplicationManager.getApplication().runWriteAction(() -> {
            final ModifiableRootModel model = ModuleRootManager.getInstance(modules[0]).getModifiableModel();
            final ContentEntry[] contentEntries = model.getContentEntries();
            for (ContentEntry contentEntry : contentEntries) {
                if (Comparing.equal(contentEntry.getFile(), baseDir)) {
                    final SourceFolder[] sourceFolders = contentEntry.getSourceFolders();
                    if (!unique || sourceFolders.length == 0) {
                        contentEntry.addSourceFolder(root, false);
                    }
                }
            }
            model.commit();
        });
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) SourceFolder(com.intellij.openapi.roots.SourceFolder) ContentEntry(com.intellij.openapi.roots.ContentEntry) Module(com.intellij.openapi.module.Module)

Aggregations

SourceFolder (com.intellij.openapi.roots.SourceFolder)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 ContentEntry (com.intellij.openapi.roots.ContentEntry)7 Module (com.intellij.openapi.module.Module)6 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)5 NotNull (org.jetbrains.annotations.NotNull)5 ExcludeFolder (com.intellij.openapi.roots.ExcludeFolder)3 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)3 JavaSourceRootProperties (org.jetbrains.jps.model.java.JavaSourceRootProperties)3 JpsModuleSourceRootType (org.jetbrains.jps.model.module.JpsModuleSourceRootType)3 Project (com.intellij.openapi.project.Project)2 ContentFolder (com.intellij.openapi.roots.ContentFolder)2 File (java.io.File)2 Assert.assertNotNull (junit.framework.Assert.assertNotNull)2 GuiTask (org.fest.swing.edt.GuiTask)2 Nullable (org.jetbrains.annotations.Nullable)2 JpsElement (org.jetbrains.jps.model.JpsElement)2 JpsModuleSourceRoot (org.jetbrains.jps.model.module.JpsModuleSourceRoot)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1