com.intellij.ide.projectView.impl.ProjectRootsUtil Java Examples

The following examples show how to use com.intellij.ide.projectView.impl.ProjectRootsUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PsiDirectoryNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public String getNavigateActionText(boolean focusEditor) {
  VirtualFile file = getVirtualFile();
  Project project = getProject();

  if (file != null) {
    if (ProjectRootsUtil.isModuleContentRoot(file, project) ||
        ProjectRootsUtil.isSourceOrTestRoot(file, project)) {
      return "Open Module Settings";
    }
    if (ProjectRootsUtil.isLibraryRoot(file, project)) {
      return "Open Library Settings";
    }
  }

  return null;
}
 
Example #2
Source File: PsiDirectoryNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
public void navigate(final boolean requestFocus) {
  Module module = ModuleUtil.findModuleForPsiElement(getValue());
  if (module != null) {
    final VirtualFile file = getVirtualFile();
    final Project project = getProject();
    ProjectSettingsService service = ProjectSettingsService.getInstance(myProject);
    if (ProjectRootsUtil.isModuleContentRoot(file, project)) {
      service.openModuleSettings(module);
    }
    else if (ProjectRootsUtil.isLibraryRoot(file, project)) {
      final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(file, module.getProject());
      if (orderEntry != null) {
        service.openLibraryOrSdkSettings(orderEntry);
      }
    }
    else {
      service.openContentEntriesSettings(module);
    }
  }
}
 
Example #3
Source File: PackageDecoration.java    From SVNToolBox with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isForMe(ProjectViewNode node) {
    if (node instanceof PsiDirectoryNode) {
        PsiDirectoryNode dirNode = (PsiDirectoryNode) node;
        final Project project = dirNode.getProject();
        final PsiDirectory psiDirectory = dirNode.getValue();
        if (project != null && psiDirectory != null) {
            final VirtualFile directoryFile = psiDirectory.getVirtualFile();
            return ProjectRootsUtil.isInSource(directoryFile, project) ||
                    ProjectRootsUtil.isInTestSource(directoryFile, project);
        }
    }
    return false;
}
 
Example #4
Source File: PsiFileNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(boolean requestFocus) {
  final VirtualFile jarRoot = getArchiveRoot();
  final Project project = getProject();
  if (requestFocus && jarRoot != null && ProjectRootsUtil.isLibraryRoot(jarRoot, project)) {
    final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(jarRoot, project);
    if (orderEntry != null) {
      ProjectSettingsService.getInstance(project).openLibraryOrSdkSettings(orderEntry);
      return;
    }
  }

  super.navigate(requestFocus);
}
 
Example #5
Source File: PsiFileNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean isNavigatableLibraryRoot() {
  VirtualFile jarRoot = getArchiveRoot();
  final Project project = getProject();
  if (jarRoot != null && ProjectRootsUtil.isLibraryRoot(jarRoot, project)) {
    final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(jarRoot, project);
    return orderEntry != null ;
  }
  return false;
}
 
Example #6
Source File: BaseProjectViewDirectoryHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public static String getNodeName(ViewSettings settings, Object parentValue, @Nonnull PsiDirectory directory) {
  Project project = directory.getProject();

  PsiPackage aPackage = PsiPackageManager.getInstance(project).findAnyPackage(directory);

  String name = directory.getName();
  VirtualFile dirFile = directory.getVirtualFile();
  if (dirFile.getFileSystem() instanceof ArchiveFileSystem && dirFile.getParent() == null) {
    VirtualFile virtualFileForArchive = ArchiveVfsUtil.getVirtualFileForArchive(dirFile);
    if (virtualFileForArchive != null) {
      name = virtualFileForArchive.getName();
    }
  }

  PsiPackage parentPackage;
  if (!ProjectRootsUtil.isSourceRoot(directory) && aPackage != null && !aPackage.getQualifiedName().isEmpty() && parentValue instanceof PsiDirectory) {

    parentPackage = PsiPackageManager.getInstance(project).findAnyPackage(((PsiDirectory)parentValue));
  }
  else if (ProjectRootsUtil.isSourceRoot(directory) && aPackage != null) {   //package prefix
    aPackage = null;
    parentPackage = null;
  }
  else {
    parentPackage = null;
  }

  return TreeViewUtil.getNodeName(settings, aPackage, parentPackage, name, isShowFQName(project, settings, parentValue, directory));
}
 
Example #7
Source File: BaseProjectViewDirectoryHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@RequiredReadAction
public static String getLocationString(@Nonnull PsiDirectory psiDirectory) {
  PsiPackage aPackage = PsiPackageManager.getInstance(psiDirectory.getProject()).findAnyPackage(psiDirectory);
  if (ProjectRootsUtil.isSourceRoot(psiDirectory) && aPackage != null) {
    return aPackage.getQualifiedName();
  }

  final VirtualFile directory = psiDirectory.getVirtualFile();
  final VirtualFile contentRootForFile = ProjectRootManager.getInstance(psiDirectory.getProject()).getFileIndex().getContentRootForFile(directory);
  if (Comparing.equal(contentRootForFile, psiDirectory)) {
    return PathUtil.toPresentableUrl(directory.getUrl());
  }
  return null;
}
 
Example #8
Source File: PsiDirectoryNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canNavigate() {
  VirtualFile file = getVirtualFile();
  Project project = getProject();

  ProjectSettingsService service = ProjectSettingsService.getInstance(myProject);
  return file != null && ((ProjectRootsUtil.isModuleContentRoot(file, project) && service.canOpenModuleSettings()) ||
                          (ProjectRootsUtil.isModuleSourceRoot(file, project)  && service.canOpenContentEntriesSettings()) ||
                          (ProjectRootsUtil.isLibraryRoot(file, project) && service.canOpenModuleLibrarySettings()));
}
 
Example #9
Source File: TodoDirNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void setupIcon(PresentationData data, PsiDirectory psiDirectory) {
  final VirtualFile virtualFile = psiDirectory.getVirtualFile();
  if (ProjectRootsUtil.isModuleContentRoot(virtualFile, psiDirectory.getProject())) {
    data.setIcon(IconDescriptorUpdaters.getIcon(psiDirectory, 0));
  }
  else {
    super.setupIcon(data, psiDirectory);
  }
}
 
Example #10
Source File: GeneratedOnRootSourcesFilter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public boolean isGeneratedSource(@Nonnull VirtualFile file, @Nonnull Project project) {
  VirtualFile contentRootForFile = ProjectFileIndex.getInstance(project).getSourceRootForFile(file);
  if(contentRootForFile == null) {
    return false;
  }
  ContentFolder contentFolder = ProjectRootsUtil.findContentFolderForDirectory(contentRootForFile, project);
  if(contentFolder == null) {
    return false;
  }

  return contentFolder.getPropertyValue(GeneratedContentFolderPropertyProvider.IS_GENERATED) == Boolean.TRUE;
}
 
Example #11
Source File: OpenModuleSettingsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isModuleInContext(@Nonnull AnActionEvent e) {
  final Project project = getEventProject(e);
  final Module module = e.getData(LangDataKeys.MODULE);
  if (project != null && module != null) {
    final VirtualFile moduleFolder = e.getData(CommonDataKeys.VIRTUAL_FILE);
    if (moduleFolder == null) {
      return false;
    }
    if (ProjectRootsUtil.isModuleContentRoot(moduleFolder, project) || ProjectRootsUtil.isModuleSourceRoot(moduleFolder, project)) {
      return true;
    }
  }
  return false;
}
 
Example #12
Source File: ContentRootDecoration.java    From SVNToolBox with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isForMe(ProjectViewNode node) {
    if (node instanceof PsiDirectoryNode) {
        PsiDirectoryNode dirNode = (PsiDirectoryNode) node;            
        final PsiDirectory psiDirectory = dirNode.getValue();
        if (psiDirectory != null) {
            final Project project = dirNode.getProject();
            final VirtualFile directoryFile = psiDirectory.getVirtualFile();
            return ProjectRootsUtil.isModuleContentRoot(directoryFile, project)
                    || ProjectRootsUtil.isInSource(directoryFile, project);
        }
    }
    return false;
}
 
Example #13
Source File: NavBarPresentation.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected SimpleTextAttributes getTextAttributes(final Object object, final boolean selected) {
  if (!NavBarModel.isValid(object)) return SimpleTextAttributes.REGULAR_ATTRIBUTES;
  if (object instanceof PsiElement) {
    if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
      @Override
      public Boolean compute() {
        return ((PsiElement)object).isValid();
      }
    }).booleanValue()) {
      return SimpleTextAttributes.GRAYED_ATTRIBUTES;
    }
    PsiFile psiFile = ((PsiElement)object).getContainingFile();
    if (psiFile != null) {
      final VirtualFile virtualFile = psiFile.getVirtualFile();
      return new SimpleTextAttributes(null, selected ? null : FileStatusManager.getInstance(myProject).getStatus(virtualFile).getColor(), JBColor.red,
                                      WolfTheProblemSolver.getInstance(myProject).isProblemFile(virtualFile) ? SimpleTextAttributes.STYLE_WAVED : SimpleTextAttributes.STYLE_PLAIN);
    }
    else {
      if (object instanceof PsiDirectory) {
        VirtualFile vDir = ((PsiDirectory)object).getVirtualFile();
        if (vDir.getParent() == null || ProjectRootsUtil.isModuleContentRoot(vDir, myProject)) {
          return SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
        }
      }

      if (wolfHasProblemFilesBeneath((PsiElement)object)) {
        return WOLFED;
      }
    }
  }
  else if (object instanceof Module) {
    if (WolfTheProblemSolver.getInstance(myProject).hasProblemFilesBeneath((Module)object)) {
      return WOLFED;
    }

  }
  else if (object instanceof Project) {
    final Project project = (Project)object;
    final Module[] modules = ApplicationManager.getApplication().runReadAction(new Computable<Module[]>() {
      @Override
      public Module[] compute() {
        return ModuleManager.getInstance(project).getModules();
      }
    });
    for (Module module : modules) {
      if (WolfTheProblemSolver.getInstance(project).hasProblemFilesBeneath(module)) {
        return WOLFED;
      }
    }
  }
  return SimpleTextAttributes.REGULAR_ATTRIBUTES;
}
 
Example #14
Source File: PsiDirectoryNode.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void updateImpl(PresentationData data) {
  final Project project = getProject();
  final PsiDirectory psiDirectory = getValue();
  final VirtualFile directoryFile = psiDirectory.getVirtualFile();

  final Object parentValue = getParentValue();
  if (ProjectRootsUtil.isModuleContentRoot(directoryFile, project)) {
    ProjectFileIndex fi = ProjectRootManager.getInstance(project).getFileIndex();
    Module module = fi.getModuleForFile(directoryFile);

    data.setPresentableText(directoryFile.getName());
    if (module != null) {
      if (!(parentValue instanceof Module)) {
        if (Comparing.equal(module.getName(), directoryFile.getName())) {
          data.addText(directoryFile.getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
        }
        else {
          data.addText(directoryFile.getName() + " ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
          data.addText("[" + module.getName() + "]", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
        }
      }
      else {
        data.addText(directoryFile.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
      }

      if (parentValue instanceof Module || parentValue instanceof Project) {
        final String location = FileUtil.getLocationRelativeToUserHome(directoryFile.getPresentableUrl());
        data.addText(" (" + location + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
      }
      else if (ProjectRootsUtil.isSourceOrTestRoot(directoryFile, project)) {
        if (ProjectRootsUtil.isInTestSource(directoryFile, project)) {
          data.addText(" (test source root)", SimpleTextAttributes.GRAY_ATTRIBUTES);
        }
        else {
          data.addText(" (source root)",  SimpleTextAttributes.GRAY_ATTRIBUTES);
        }
      }

      setupIcon(data, psiDirectory);

      return;
    }
  }

  final String name = parentValue instanceof Project
                      ? psiDirectory.getVirtualFile().getPresentableUrl()
                      : BaseProjectViewDirectoryHelper.getNodeName(getSettings(), parentValue, psiDirectory);
  if (name == null) {
    setValue(null);
    return;
  }

  data.setPresentableText(name);
  if (ProjectRootsUtil.isLibraryRoot(directoryFile, project)) {
    data.setLocationString("library home");
  }
  else {
    data.setLocationString(BaseProjectViewDirectoryHelper.getLocationString(psiDirectory));
  }

  setupIcon(data, psiDirectory);
}
 
Example #15
Source File: DirectoryNode.java    From consulo with Apache License 2.0 4 votes vote down vote up
public DirectoryNode(VirtualFile aDirectory,
                     Project project,
                     boolean compactPackages,
                     boolean showFQName,
                     VirtualFile baseDir, final VirtualFile[] contentRoots) {
  super(project);
  myVDirectory = aDirectory;
  final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
  final ProjectFileIndex index = projectRootManager.getFileIndex();
  String dirName = aDirectory.getName();
  if (showFQName) {
    final VirtualFile contentRoot = index.getContentRootForFile(myVDirectory);
    if (contentRoot != null) {
      if (Comparing.equal(myVDirectory, contentRoot)) {
        myFQName = dirName;
      }
      else {
        final VirtualFile sourceRoot = index.getSourceRootForFile(myVDirectory);
        if (Comparing.equal(myVDirectory, sourceRoot)) {
          myFQName = VfsUtilCore.getRelativePath(myVDirectory, contentRoot, '/');
        }
        else if (sourceRoot != null) {
          myFQName = VfsUtilCore.getRelativePath(myVDirectory, sourceRoot, '/');
        }
        else {
          myFQName = VfsUtilCore.getRelativePath(myVDirectory, contentRoot, '/');
        }
      }

      if (contentRoots.length > 1 && ProjectRootsUtil.isModuleContentRoot(myVDirectory, project)) {
        myFQName = getContentRootName(baseDir, myFQName);
      }
    }
    else {
      myFQName = FilePatternPackageSet.getLibRelativePath(myVDirectory, index);
    }
    dirName = myFQName;
  } else {
    if (contentRoots.length > 1 && ProjectRootsUtil.isModuleContentRoot(myVDirectory, project)) {
      dirName = getContentRootName(baseDir, dirName);
    }
  }
  myDirName = dirName;
  myCompactPackages = compactPackages;
}
 
Example #16
Source File: PsiDirectoryIconDescriptorUpdater.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Override
public void updateIcon(@Nonnull IconDescriptor iconDescriptor, @Nonnull PsiElement element, int flags) {
  if (element instanceof PsiDirectory) {
    PsiDirectory psiDirectory = (PsiDirectory)element;
    VirtualFile virtualFile = psiDirectory.getVirtualFile();

    Image symbolIcon;
    if (virtualFile.getFileSystem() instanceof ArchiveFileSystem) {
      if (virtualFile.getParent() == null) {
        symbolIcon = AllIcons.Nodes.PpJar;
      }
      else {
        PsiPackage psiPackage = myPsiPackageManager.findAnyPackage(virtualFile);
        symbolIcon = psiPackage != null ? AllIcons.Nodes.Package : AllIcons.Nodes.TreeClosed;
      }
    }
    else if (ProjectRootsUtil.isModuleContentRoot(myProjectFileIndex, virtualFile)) {
      symbolIcon = AllIcons.Nodes.Module;
    }
    else {
      boolean ignored = myProjectRootManager.getFileIndex().isExcluded(virtualFile);
      if (ignored) {
        symbolIcon = AllIcons.Modules.ExcludeRoot;
      }
      else {
        ContentFolder contentFolder = ProjectRootsUtil.findContentFolderForDirectory(myProjectFileIndex, virtualFile);
        if (contentFolder != null) {
          symbolIcon = contentFolder.getType().getIcon(contentFolder.getProperties());
        }
        else {
          ContentFolderTypeProvider contentFolderTypeForFile = myProjectFileIndex.getContentFolderTypeForFile(virtualFile);
          symbolIcon = contentFolderTypeForFile != null ? contentFolderTypeForFile.getChildDirectoryIcon(psiDirectory, myPsiPackageManager) : AllIcons.Nodes.TreeClosed;
        }
      }
    }

    if (symbolIcon != null) {
      iconDescriptor.setMainIcon(symbolIcon);
    }

    if (virtualFile.is(VFileProperty.SYMLINK)) {
      iconDescriptor.addLayerIcon(AllIcons.Nodes.Symlink);
    }
  }
  else if (element instanceof PsiPackage) {
    iconDescriptor.setMainIcon(AllIcons.Nodes.Package);
  }
}
 
Example #17
Source File: BlazePsiDirectoryNode.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static boolean isSourceRoot(PsiDirectory psi) {
  return ProjectRootsUtil.isModuleSourceRoot(psi.getVirtualFile(), psi.getProject());
}