Search in sources :

Example 41 with IdeView

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

the class CreateInDirectoryActionBase 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 42 with IdeView

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

the class CreateTemplateInPackageAction method isAvailable.

@Override
protected boolean isAvailable(final DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (project == null || view == null || view.getDirectories().length == 0) {
        return false;
    }
    if (mySourceRootTypes == null) {
        return true;
    }
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    for (PsiDirectory dir : view.getDirectories()) {
        if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), mySourceRootTypes) && checkPackageExists(dir)) {
            return true;
        }
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView)

Example 43 with IdeView

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

the class CreatePackageAction method isEnabled.

private static boolean isEnabled(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    final IdeView ideView = e.getData(LangDataKeys.IDE_VIEW);
    if (project == null || ideView == null) {
        return false;
    }
    final PsiDirectory[] directories = ideView.getDirectories();
    if (directories.length == 0) {
        return false;
    }
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView)

Example 44 with IdeView

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

the class CCPushCourse method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (view == null || project == null) {
        return;
    }
    final Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    if (course.getId() > 0) {
        ProgressManager.getInstance().run(new Task.Modal(project, "Updating Course", true) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                for (Lesson lesson : course.getLessons()) {
                    if (lesson.getId() > 0) {
                        CCStepicConnector.updateLesson(project, lesson, indicator);
                    } else {
                        final CourseInfo info = CourseInfo.fromCourse(course);
                        final int lessonId = CCStepicConnector.postLesson(project, lesson, indicator);
                        if (lessonId != -1) {
                            final List<Integer> sections = info.getSections();
                            final Integer sectionId = sections.get(sections.size() - 1);
                            CCStepicConnector.postUnit(lessonId, lesson.getIndex(), sectionId);
                        }
                    }
                }
            }
        });
    } else {
        CCStepicConnector.postCourseWithProgress(project, course);
    }
    EduUsagesCollector.courseUploaded();
}
Also used : Project(com.intellij.openapi.project.Project) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IdeView(com.intellij.ide.IdeView) Course(com.jetbrains.edu.learning.courseFormat.Course) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo)

Example 45 with IdeView

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

the class CCPushLesson method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (view == null || project == null) {
        return;
    }
    final Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    PsiDirectory lessonDir = DirectoryChooserUtil.getOrChooseDirectory(view);
    if (lessonDir == null || !lessonDir.getName().contains("lesson")) {
        return;
    }
    final Lesson lesson = course.getLesson(lessonDir.getName());
    if (lesson == null) {
        return;
    }
    ProgressManager.getInstance().run(new Task.Modal(project, "Uploading Lesson", true) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setText("Uploading lesson to " + EduStepicNames.STEPIC_URL);
            if (lesson.getId() > 0) {
                CCStepicConnector.updateLesson(project, lesson, indicator);
            } else {
                final CourseInfo info = CourseInfo.fromCourse(course);
                final int lessonId = CCStepicConnector.postLesson(project, lesson, indicator);
                final List<Integer> sections = info.getSections();
                final Integer sectionId = sections.get(sections.size() - 1);
                CCStepicConnector.postUnit(lessonId, lesson.getIndex(), sectionId);
            }
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) Task(com.intellij.openapi.progress.Task) PsiDirectory(com.intellij.psi.PsiDirectory) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IdeView(com.intellij.ide.IdeView) Course(com.jetbrains.edu.learning.courseFormat.Course) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo)

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