Search in sources :

Example 6 with AbstractProjectViewPane

use of com.intellij.ide.projectView.impl.AbstractProjectViewPane in project android by JetBrains.

the class CreateTypedResourceFileAction method invokeDialog.

@NotNull
@Override
protected PsiElement[] invokeDialog(@NotNull Project project, @NotNull DataContext dataContext) {
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view != null) {
        // If you're in the Android View, we want to ask you not just the filename but also let you
        // create other resource folder configurations
        AbstractProjectViewPane pane = ProjectView.getInstance(project).getCurrentProjectViewPane();
        if (pane instanceof AndroidProjectViewPane) {
            return CreateResourceFileAction.getInstance().invokeDialog(project, dataContext);
        }
        final PsiDirectory directory = view.getOrChooseDirectory();
        if (directory != null) {
            InputValidator validator = createValidator(project, directory);
            Messages.showInputDialog(project, AndroidBundle.message("new.file.dialog.text"), AndroidBundle.message("new.typed.resource.dialog.title", myResourcePresentableName), Messages.getQuestionIcon(), "", validator);
        }
    }
    return PsiElement.EMPTY_ARRAY;
}
Also used : AndroidProjectViewPane(com.android.tools.idea.navigator.AndroidProjectViewPane) InputValidator(com.intellij.openapi.ui.InputValidator) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with AbstractProjectViewPane

use of com.intellij.ide.projectView.impl.AbstractProjectViewPane in project android by JetBrains.

the class CreateMultiRootResourceFileAction method invokeDialog.

@NotNull
@Override
protected PsiElement[] invokeDialog(@NotNull Project project, @NotNull DataContext dataContext) {
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view != null) {
        // If you're in the Android View, we want to ask you not just the filename but also let you
        // create other resource folder configurations
        AbstractProjectViewPane pane = ProjectView.getInstance(project).getCurrentProjectViewPane();
        if (pane instanceof AndroidProjectViewPane) {
            return CreateResourceFileAction.getInstance().invokeDialog(project, dataContext);
        }
        final PsiDirectory directory = view.getOrChooseDirectory();
        if (directory != null) {
            InputValidator validator = createValidator(project, directory);
            final AndroidFacet facet = AndroidFacet.getInstance(directory);
            if (facet != null) {
                final MyDialog dialog = new MyDialog(facet, validator);
                dialog.show();
                return PsiElement.EMPTY_ARRAY;
            }
        }
    }
    return PsiElement.EMPTY_ARRAY;
}
Also used : AndroidProjectViewPane(com.android.tools.idea.navigator.AndroidProjectViewPane) InputValidator(com.intellij.openapi.ui.InputValidator) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with AbstractProjectViewPane

use of com.intellij.ide.projectView.impl.AbstractProjectViewPane in project android by JetBrains.

the class CreateResourceDialogUtils method findResourceDirectory.

@Nullable
public static PsiDirectory findResourceDirectory(@NotNull DataContext dataContext) {
    // Look at the set of selected files and see if one *specific* resource directory is implied (selected, or a parent
    // of all selected nodes); if so, use it; otherwise return null.
    //
    // In the Android Project View we don't want to do this, since there is only ever a single "res" node,
    // even when you have other overlays.
    // If you're in the Android View, we want to ask you not just the filename but also let you
    // create other resource folder configurations
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project != null) {
        AbstractProjectViewPane pane = ProjectView.getInstance(project).getCurrentProjectViewPane();
        if (pane instanceof AndroidProjectViewPane) {
            return null;
        }
    }
    VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
    if (file != null) {
        // See if it's inside a res folder (or is equal to a resource folder)
        Module module = LangDataKeys.MODULE.getData(dataContext);
        if (module != null) {
            LocalResourceManager manager = LocalResourceManager.getInstance(module);
            if (manager != null) {
                VirtualFile resFolder = getResFolderParent(manager, file);
                if (resFolder != null) {
                    return AndroidPsiUtils.getPsiDirectorySafely(module.getProject(), resFolder);
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AndroidProjectViewPane(com.android.tools.idea.navigator.AndroidProjectViewPane) LocalResourceManager(org.jetbrains.android.resourceManagers.LocalResourceManager) Module(com.intellij.openapi.module.Module) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with AbstractProjectViewPane

use of com.intellij.ide.projectView.impl.AbstractProjectViewPane in project intellij-plugins by StepicOrg.

the class NavigationUtils method collapseNonSelected.

private static void collapseNonSelected(@NotNull PsiFileSystemItem file) {
    ProjectView projectView = ProjectView.getInstance(file.getProject());
    if (projectView == null) {
        return;
    }
    AbstractProjectViewPane projectViewPane = projectView.getCurrentProjectViewPane();
    if (projectViewPane == null) {
        return;
    }
    JTree tree = projectViewPane.getTree();
    Set<TreePath> paths = new HashSet<>(TreeUtil.collectExpandedPaths(tree));
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
    DefaultMutableTreeNode selectionNode = findNodeWithObject(root, file);
    if (selectionNode != null) {
        List<TreePath> toCollapse = new ArrayList<>();
        TreePath selectedPath = getPathFromRoot(selectionNode);
        for (TreePath treePath : paths) {
            if (treePath.isDescendant(selectedPath)) {
                continue;
            }
            TreePath currPath = treePath;
            TreePath parent = treePath.getParentPath();
            while (parent != null) {
                if (parent.isDescendant(selectedPath)) {
                    toCollapse.add(currPath);
                    break;
                }
                currPath = parent;
                parent = parent.getParentPath();
            }
        }
        for (TreePath path : toCollapse) {
            tree.collapsePath(path);
            tree.fireTreeCollapsed(path);
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) ProjectView(com.intellij.ide.projectView.ProjectView) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) HashSet(java.util.HashSet)

Example 10 with AbstractProjectViewPane

use of com.intellij.ide.projectView.impl.AbstractProjectViewPane in project android by JetBrains.

the class Projects method getModulesToBuildFromSelection.

/**
   * Returns the modules to build based on the current selection in the 'Project' tool window. If the module that corresponds to the project
   * is selected, all the modules in such projects are returned. If there is no selection, an empty array is returned.
   *
   * @param project     the given project.
   * @param dataContext knows the modules that are selected. If {@code null}, this method gets the {@code DataContext} from the 'Project'
   *                    tool window directly.
   * @return the modules to build based on the current selection in the 'Project' tool window.
   */
@NotNull
public static Module[] getModulesToBuildFromSelection(@NotNull Project project, @Nullable DataContext dataContext) {
    if (dataContext == null) {
        ProjectView projectView = ProjectView.getInstance(project);
        AbstractProjectViewPane pane = projectView.getCurrentProjectViewPane();
        if (pane != null) {
            JComponent treeComponent = pane.getComponentToFocus();
            dataContext = DataManager.getInstance().getDataContext(treeComponent);
        } else {
            return Module.EMPTY_ARRAY;
        }
    }
    Module[] modules = MODULE_CONTEXT_ARRAY.getData(dataContext);
    if (modules != null) {
        if (modules.length == 1 && isProjectModule(modules[0])) {
            return ModuleManager.getInstance(project).getModules();
        }
        return modules;
    }
    Module module = MODULE.getData(dataContext);
    if (module != null) {
        return isProjectModule(module) ? ModuleManager.getInstance(project).getModules() : new Module[] { module };
    }
    return Module.EMPTY_ARRAY;
}
Also used : ProjectView(com.intellij.ide.projectView.ProjectView) Module(com.intellij.openapi.module.Module) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AbstractProjectViewPane (com.intellij.ide.projectView.impl.AbstractProjectViewPane)14 NotNull (org.jetbrains.annotations.NotNull)6 Module (com.intellij.openapi.module.Module)4 AndroidProjectViewPane (com.android.tools.idea.navigator.AndroidProjectViewPane)3 ProjectView (com.intellij.ide.projectView.ProjectView)3 Project (com.intellij.openapi.project.Project)3 PsiDirectory (com.intellij.psi.PsiDirectory)3 ArrayList (java.util.ArrayList)3 IdeView (com.intellij.ide.IdeView)2 SelectInTarget (com.intellij.ide.SelectInTarget)2 InputValidator (com.intellij.openapi.ui.InputValidator)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Executor (com.intellij.execution.Executor)1 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)1 CompositeSelectInTarget (com.intellij.ide.CompositeSelectInTarget)1 FavoriteNodeProvider (com.intellij.ide.favoritesTreeView.FavoriteNodeProvider)1 ModuleGroup (com.intellij.ide.projectView.impl.ModuleGroup)1 AbstractTreeBuilder (com.intellij.ide.util.treeView.AbstractTreeBuilder)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 ResourceBundle (com.intellij.lang.properties.ResourceBundle)1