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;
}
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);
}
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);
}
}
}
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 "";
}
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();
});
}
}
Aggregations