Search in sources :

Example 1 with AndroidProjectViewPane

use of com.android.tools.idea.navigator.AndroidProjectViewPane 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 2 with AndroidProjectViewPane

use of com.android.tools.idea.navigator.AndroidProjectViewPane 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 3 with AndroidProjectViewPane

use of com.android.tools.idea.navigator.AndroidProjectViewPane 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)

Aggregations

AndroidProjectViewPane (com.android.tools.idea.navigator.AndroidProjectViewPane)3 AbstractProjectViewPane (com.intellij.ide.projectView.impl.AbstractProjectViewPane)3 IdeView (com.intellij.ide.IdeView)2 InputValidator (com.intellij.openapi.ui.InputValidator)2 PsiDirectory (com.intellij.psi.PsiDirectory)2 NotNull (org.jetbrains.annotations.NotNull)2 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 LocalResourceManager (org.jetbrains.android.resourceManagers.LocalResourceManager)1 Nullable (org.jetbrains.annotations.Nullable)1