Search in sources :

Example 1 with PackageElementNode

use of com.intellij.ide.projectView.impl.nodes.PackageElementNode in project intellij-community by JetBrains.

the class PackageViewPane method getSelectedDirectories.

@NotNull
@Override
public PsiDirectory[] getSelectedDirectories() {
    List<PsiDirectory> directories = ContainerUtil.newArrayList();
    for (PackageElementNode node : getSelectedNodes(PackageElementNode.class)) {
        PackageElement packageElement = node.getValue();
        PsiPackage aPackage = packageElement != null ? packageElement.getPackage() : null;
        final Module module = packageElement != null ? packageElement.getModule() : null;
        if (aPackage != null && module != null) {
            GlobalSearchScope scope = GlobalSearchScope.moduleScope(module);
            Collections.addAll(directories, aPackage.getDirectories(scope));
            if (Registry.is("projectView.choose.directory.on.compacted.middle.packages")) {
                Object parentValue = node.getParent().getValue();
                PsiPackage parentNodePackage = parentValue instanceof PackageElement ? ((PackageElement) parentValue).getPackage() : null;
                while (true) {
                    aPackage = aPackage.getParentPackage();
                    if (aPackage == null || aPackage.getQualifiedName().isEmpty() || aPackage.equals(parentNodePackage)) {
                        break;
                    }
                    Collections.addAll(directories, aPackage.getDirectories(scope));
                }
            }
        }
    }
    if (!directories.isEmpty()) {
        return directories.toArray(new PsiDirectory[directories.size()]);
    }
    return super.getSelectedDirectories();
}
Also used : PackageElementNode(com.intellij.ide.projectView.impl.nodes.PackageElementNode) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PackageElement (com.intellij.ide.projectView.impl.nodes.PackageElement)1 PackageElementNode (com.intellij.ide.projectView.impl.nodes.PackageElementNode)1 Module (com.intellij.openapi.module.Module)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiPackage (com.intellij.psi.PsiPackage)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 NotNull (org.jetbrains.annotations.NotNull)1