Search in sources :

Example 31 with IdeView

use of com.intellij.ide.IdeView in project android by JetBrains.

the class AndroidAssetStudioAction method isAvailable.

protected static boolean isAvailable(DataContext dataContext) {
    final Module module = LangDataKeys.MODULE.getData(dataContext);
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (module == null || view == null || view.getDirectories().length == 0 || AndroidFacet.getInstance(module) == null) {
        return false;
    }
    return true;
}
Also used : Module(com.intellij.openapi.module.Module) IdeView(com.intellij.ide.IdeView)

Example 32 with IdeView

use of com.intellij.ide.IdeView in project android by JetBrains.

the class NewAndroidComponentAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null) {
        return;
    }
    Module module = LangDataKeys.MODULE.getData(dataContext);
    if (module == null) {
        return;
    }
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null || facet.getAndroidModel() == null) {
        return;
    }
    VirtualFile targetFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
    File file = TemplateManager.getInstance().getTemplateFile(myTemplateCategory, myTemplateName);
    assert targetFile != null;
    VirtualFile targetDirectory = targetFile;
    if (!targetDirectory.isDirectory()) {
        targetDirectory = targetFile.getParent();
        assert targetDirectory != null;
    }
    assert file != null;
    // e.g. "Empty Activity", "Tabbed Activity"
    String activityDescription = e.getPresentation().getText();
    List<AndroidSourceSet> sourceSets = AndroidSourceSet.getSourceSets(facet, targetDirectory);
    assert sourceSets.size() > 0;
    String initialPackageSuggestion = AndroidPackageUtils.getPackageForPath(facet, sourceSets, targetDirectory);
    Project project = module.getProject();
    RenderTemplateModel templateModel = new RenderTemplateModel(project, new TemplateHandle(file), initialPackageSuggestion, sourceSets.get(0), "New " + activityDescription);
    boolean isActivity = isActivityTemplate();
    String dialogTitle = AndroidBundle.message(isActivity ? "android.wizard.new.activity.title" : "android.wizard.new.component.title");
    String stepTitle = AndroidBundle.message(isActivity ? "android.wizard.config.activity.title" : "android.wizard.config.component.title");
    ModelWizard.Builder wizardBuilder = new ModelWizard.Builder();
    wizardBuilder.addStep(new ConfigureTemplateParametersStep(templateModel, stepTitle, sourceSets, facet));
    ModelWizardDialog dialog = new StudioWizardDialogBuilder(wizardBuilder.build(), dialogTitle).setProject(project).build();
    dialog.show();
/*
    // TODO: Implement the getCreatedElements call for the wizard
    final PsiElement[] createdElements = dialog.getCreatedElements();

    for (PsiElement createdElement : createdElements) {
      view.selectElement(createdElement);
    }
    */
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) RenderTemplateModel(com.android.tools.idea.npw.template.RenderTemplateModel) IdeView(com.intellij.ide.IdeView) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) StudioWizardDialogBuilder(com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder) TemplateHandle(com.android.tools.idea.npw.template.TemplateHandle) ConfigureTemplateParametersStep(com.android.tools.idea.npw.template.ConfigureTemplateParametersStep) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) AndroidSourceSet(com.android.tools.idea.npw.project.AndroidSourceSet) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard)

Example 33 with IdeView

use of com.intellij.ide.IdeView in project android by JetBrains.

the class CreateResourceActionBase method actionPerformed.

@Override
public final void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null) {
        return;
    }
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return;
    }
    // This is where we differ from CreateElementActionBase:
    // Rather than asking for a directory here, we just allow
    // *any* directory
    final PsiElement[] createdElements = invokeDialog(project, dataContext);
    for (PsiElement createdElement : createdElements) {
        view.selectElement(createdElement);
    }
}
Also used : Project(com.intellij.openapi.project.Project) IdeView(com.intellij.ide.IdeView) PsiElement(com.intellij.psi.PsiElement)

Example 34 with IdeView

use of com.intellij.ide.IdeView in project android by JetBrains.

the class CreateResourceActionBase method isAvailable.

protected boolean isAvailable(final DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return false;
    }
    if (DumbService.getInstance(project).isDumb() && !isDumbAware()) {
        return false;
    }
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null || view.getDirectories().length == 0) {
        return false;
    }
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) IdeView(com.intellij.ide.IdeView)

Example 35 with IdeView

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

the class CreatePackageInfoAction method isAvailable.

private static boolean isAvailable(DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (project == null || view == null) {
        return false;
    }
    final PsiDirectory[] directories = view.getDirectories();
    if (directories.length == 0) {
        return false;
    }
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final JavaDirectoryService directoryService = JavaDirectoryService.getInstance();
    final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
    for (PsiDirectory directory : directories) {
        if (projectFileIndex.isUnderSourceRootOfType(directory.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && PsiUtil.isLanguageLevel5OrHigher(directory)) {
            final PsiPackage aPackage = directoryService.getPackage(directory);
            if (aPackage != null) {
                final String qualifiedName = aPackage.getQualifiedName();
                if (StringUtil.isEmpty(qualifiedName) || nameHelper.isQualifiedName(qualifiedName)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : PsiNameHelper(com.intellij.psi.PsiNameHelper) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) IdeView(com.intellij.ide.IdeView) JavaDirectoryService(com.intellij.psi.JavaDirectoryService)

Aggregations

IdeView (com.intellij.ide.IdeView)47 Project (com.intellij.openapi.project.Project)35 PsiDirectory (com.intellij.psi.PsiDirectory)30 Module (com.intellij.openapi.module.Module)10 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)10 Course (com.jetbrains.edu.learning.courseFormat.Course)7 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)6 Presentation (com.intellij.openapi.actionSystem.Presentation)5 PsiElement (com.intellij.psi.PsiElement)5 Lesson (com.jetbrains.edu.learning.courseFormat.Lesson)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)4 NotNull (org.jetbrains.annotations.NotNull)4 DataContext (com.intellij.openapi.actionSystem.DataContext)3 Task (com.intellij.openapi.progress.Task)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 JavaDirectoryService (com.intellij.psi.JavaDirectoryService)3 AndroidProjectViewPane (com.android.tools.idea.navigator.AndroidProjectViewPane)2 StudioWizardDialogBuilder (com.android.tools.idea.ui.wizard.StudioWizardDialogBuilder)2 ModelWizard (com.android.tools.idea.wizard.model.ModelWizard)2 AbstractProjectViewPane (com.intellij.ide.projectView.impl.AbstractProjectViewPane)2