Search in sources :

Example 1 with FavoriteNodeProvider

use of com.intellij.ide.favoritesTreeView.FavoriteNodeProvider in project intellij-community by JetBrains.

the class AddToFavoritesAction method getNodesToAdd.

@NotNull
public static Collection<AbstractTreeNode> getNodesToAdd(final DataContext dataContext, final boolean inProjectView) {
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null)
        return Collections.emptyList();
    Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
    Collection<AbstractTreeNode> nodesToAdd = null;
    for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project)) {
        nodesToAdd = provider.getFavoriteNodes(dataContext, ViewSettings.DEFAULT);
        if (nodesToAdd != null) {
            break;
        }
    }
    if (nodesToAdd == null) {
        Object elements = collectSelectedElements(dataContext);
        if (elements != null) {
            nodesToAdd = createNodes(project, moduleContext, elements, inProjectView, ViewSettings.DEFAULT);
        }
    }
    return nodesToAdd == null ? Collections.<AbstractTreeNode>emptyList() : nodesToAdd;
}
Also used : Project(com.intellij.openapi.project.Project) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Module(com.intellij.openapi.module.Module) FavoriteNodeProvider(com.intellij.ide.favoritesTreeView.FavoriteNodeProvider) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with FavoriteNodeProvider

use of com.intellij.ide.favoritesTreeView.FavoriteNodeProvider in project intellij-community by JetBrains.

the class AddToFavoritesAction method createNodes.

@NotNull
public static Collection<AbstractTreeNode> createNodes(Project project, Module moduleContext, Object object, boolean inProjectView, ViewSettings favoritesConfig) {
    if (project == null)
        return Collections.emptyList();
    ArrayList<AbstractTreeNode> result = new ArrayList<>();
    for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project)) {
        final AbstractTreeNode treeNode = provider.createNode(project, object, favoritesConfig);
        if (treeNode != null) {
            result.add(treeNode);
            return result;
        }
    }
    final PsiManager psiManager = PsiManager.getInstance(project);
    final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
    AbstractProjectViewPane pane = ProjectView.getInstance(project).getProjectViewPaneById(currentViewId);
    //on psi elements
    if (object instanceof PsiElement[]) {
        for (PsiElement psiElement : (PsiElement[]) object) {
            addPsiElementNode(psiElement, project, result, favoritesConfig);
        }
        return result;
    }
    //on psi element
    if (object instanceof PsiElement) {
        Module containingModule = null;
        if (inProjectView && ProjectView.getInstance(project).isShowModules(currentViewId)) {
            if (pane != null && pane.getSelectedDescriptor() != null && pane.getSelectedDescriptor().getElement() instanceof AbstractTreeNode) {
                AbstractTreeNode abstractTreeNode = ((AbstractTreeNode) pane.getSelectedDescriptor().getElement());
                while (abstractTreeNode != null && !(abstractTreeNode.getParent() instanceof AbstractModuleNode)) {
                    abstractTreeNode = abstractTreeNode.getParent();
                }
                if (abstractTreeNode != null) {
                    containingModule = ((AbstractModuleNode) abstractTreeNode.getParent()).getValue();
                }
            }
        }
        addPsiElementNode((PsiElement) object, project, result, favoritesConfig);
        return result;
    }
    if (object instanceof VirtualFile[]) {
        for (VirtualFile vFile : (VirtualFile[]) object) {
            PsiElement element = psiManager.findFile(vFile);
            if (element == null)
                element = psiManager.findDirectory(vFile);
            addPsiElementNode(element, project, result, favoritesConfig);
        }
        return result;
    }
    //on form in editor
    if (object instanceof VirtualFile) {
        final VirtualFile vFile = (VirtualFile) object;
        final PsiFile psiFile = psiManager.findFile(vFile);
        addPsiElementNode(psiFile, project, result, favoritesConfig);
        return result;
    }
    //on module groups
    if (object instanceof ModuleGroup[]) {
        for (ModuleGroup moduleGroup : (ModuleGroup[]) object) {
            result.add(new ProjectViewModuleGroupNode(project, moduleGroup, favoritesConfig));
        }
        return result;
    }
    //on module nodes
    if (object instanceof Module)
        object = new Module[] { (Module) object };
    if (object instanceof Module[]) {
        for (Module module1 : (Module[]) object) {
            result.add(new ProjectViewModuleNode(project, module1, favoritesConfig));
        }
        return result;
    }
    //on library group node
    if (object instanceof LibraryGroupElement[]) {
        for (LibraryGroupElement libraryGroup : (LibraryGroupElement[]) object) {
            result.add(new LibraryGroupNode(project, libraryGroup, favoritesConfig));
        }
        return result;
    }
    //on named library node
    if (object instanceof NamedLibraryElement[]) {
        for (NamedLibraryElement namedLibrary : (NamedLibraryElement[]) object) {
            result.add(new NamedLibraryElementNode(project, namedLibrary, favoritesConfig));
        }
        return result;
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiManager(com.intellij.psi.PsiManager) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) FavoriteNodeProvider(com.intellij.ide.favoritesTreeView.FavoriteNodeProvider) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FavoriteNodeProvider (com.intellij.ide.favoritesTreeView.FavoriteNodeProvider)2 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 Module (com.intellij.openapi.module.Module)2 NotNull (org.jetbrains.annotations.NotNull)2 AbstractProjectViewPane (com.intellij.ide.projectView.impl.AbstractProjectViewPane)1 ModuleGroup (com.intellij.ide.projectView.impl.ModuleGroup)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiManager (com.intellij.psi.PsiManager)1 ArrayList (java.util.ArrayList)1