Search in sources :

Example 6 with Course

use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.

the class CCCreateStudyItemActionBase method update.

@Override
public void update(@NotNull AnActionEvent event) {
    final Presentation presentation = event.getPresentation();
    presentation.setEnabledAndVisible(false);
    final Project project = event.getData(CommonDataKeys.PROJECT);
    final IdeView view = event.getData(LangDataKeys.IDE_VIEW);
    if (project == null || view == null) {
        return;
    }
    if (!StudyUtils.isStudyProject(project) || !CCUtils.isCourseCreator(project)) {
        return;
    }
    final PsiDirectory[] directories = view.getDirectories();
    if (directories.length == 0) {
        return;
    }
    final PsiDirectory sourceDirectory = DirectoryChooserUtil.getOrChooseDirectory(view);
    final Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null || sourceDirectory == null) {
        return;
    }
    if (!isAddedAsLast(sourceDirectory, project, course) && getThresholdItem(course, sourceDirectory) == null) {
        return;
    }
    if (CommonDataKeys.PSI_FILE.getData(event.getDataContext()) != null) {
        return;
    }
    presentation.setEnabledAndVisible(true);
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) Presentation(com.intellij.openapi.actionSystem.Presentation) IdeView(com.intellij.ide.IdeView) Course(com.jetbrains.edu.learning.courseFormat.Course)

Example 7 with Course

use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.

the class CCCreateStudyItemActionBase method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    final Project project = e.getProject();
    if (view == null || project == null) {
        return;
    }
    final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
    if (directory == null)
        return;
    final Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    createItem(view, project, directory, course);
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView) Course(com.jetbrains.edu.learning.courseFormat.Course)

Example 8 with Course

use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.

the class StudyMoveDelegate method canMove.

@Override
public boolean canMove(PsiElement[] elements, @Nullable PsiElement targetContainer) {
    if (elements.length == 1) {
        Project project = elements[0].getProject();
        Course course = StudyTaskManager.getInstance(project).getCourse();
        if (course == null || !EduNames.STUDY.equals(course.getCourseMode())) {
            return false;
        }
        return !StudyUtils.isRenameableOrMoveable(project, course, elements[0]);
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) Course(com.jetbrains.edu.learning.courseFormat.Course)

Example 9 with Course

use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.

the class CCGetCourseFromStepic method createCourse.

private static void createCourse(Project project, String courseId) {
    final VirtualFile baseDir = project.getBaseDir();
    final CourseInfo info = CCStepicConnector.getCourseInfo(courseId);
    if (info == null)
        return;
    final Course course = EduStepicConnector.getCourse(project, info);
    if (course != null) {
        flushCourse(course);
        final File courseDirectory = StudyUtils.getCourseDirectory(course);
        ApplicationManager.getApplication().invokeAndWait(() -> ApplicationManager.getApplication().runWriteAction(() -> {
            final VirtualFile[] children = baseDir.getChildren();
            for (VirtualFile child : children) {
                StudyUtils.deleteFile(child);
            }
            StudyGenerator.createCourse(course, baseDir, courseDirectory, project);
        }));
        StudyTaskManager.getInstance(project).setCourse(course);
        File courseDir = new File(OUR_COURSES_DIR, course.getName() + "-" + project.getName());
        course.setCourseDirectory(courseDir.getPath());
        course.setCourseMode(CCUtils.COURSE_MODE);
        project.getBaseDir().refresh(false, true);
        int index = 1;
        int taskIndex = 1;
        for (Lesson lesson : course.getLessons()) {
            final VirtualFile lessonDir = project.getBaseDir().findChild(EduNames.LESSON + String.valueOf(index));
            lesson.setIndex(index);
            if (lessonDir == null)
                continue;
            for (Task task : lesson.getTaskList()) {
                final VirtualFile taskDir = lessonDir.findChild(EduNames.TASK + String.valueOf(taskIndex));
                task.setIndex(taskIndex);
                task.setLesson(lesson);
                if (taskDir == null)
                    continue;
                for (final Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
                    ApplicationManager.getApplication().invokeAndWait(() -> ApplicationManager.getApplication().runWriteAction(() -> createAnswerFile(project, taskDir, entry)));
                }
                taskIndex += 1;
            }
            index += 1;
            taskIndex = 1;
        }
        course.initCourse(true);
        ApplicationManager.getApplication().invokeAndWait(() -> StudyUtils.registerStudyToolWindow(course, project));
    }
    VirtualFileManager.getInstance().refreshWithoutFileWatcher(true);
    ProjectView.getInstance(project).refresh();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) Course(com.jetbrains.edu.learning.courseFormat.Course) StudyProjectGenerator.flushCourse(com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator.flushCourse) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) File(java.io.File) CCFromCourseArchive.createAnswerFile(com.jetbrains.edu.coursecreator.actions.CCFromCourseArchive.createAnswerFile) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) Map(java.util.Map)

Example 10 with Course

use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.

the class CCLessonMoveHandlerDelegate method doMove.

@Override
public void doMove(final Project project, PsiElement[] elements, @Nullable PsiElement targetContainer, @Nullable MoveCallback callback) {
    if (targetContainer == null || !(targetContainer instanceof PsiDirectory)) {
        return;
    }
    final Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    final PsiDirectory sourceDirectory = (PsiDirectory) elements[0];
    final Lesson sourceLesson = course.getLesson(sourceDirectory.getName());
    final Lesson targetLesson = course.getLesson(((PsiDirectory) targetContainer).getName());
    if (targetLesson == null) {
        Messages.showInfoMessage("Lessons can be moved only to other lessons", "Incorrect Target For Move");
        return;
    }
    final CCMoveStudyItemDialog dialog = new CCMoveStudyItemDialog(project, EduNames.LESSON, targetLesson.getName());
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
        return;
    }
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            try {
                sourceDirectory.getVirtualFile().rename(this, "tmp");
            } catch (IOException e) {
                LOG.error(e);
            }
        }
    });
    final VirtualFile[] lessonDirs = project.getBaseDir().getChildren();
    final Function<VirtualFile, StudyItem> getStudyItem = file -> course.getLesson(file.getName());
    int sourceLessonIndex = sourceLesson.getIndex();
    sourceLesson.setIndex(-1);
    CCUtils.updateHigherElements(lessonDirs, getStudyItem, sourceLessonIndex, EduNames.LESSON, -1);
    final int newItemIndex = targetLesson.getIndex() + dialog.getIndexDelta();
    CCUtils.updateHigherElements(lessonDirs, getStudyItem, newItemIndex - 1, EduNames.LESSON, 1);
    sourceLesson.setIndex(newItemIndex);
    Collections.sort(course.getLessons(), EduUtils.INDEX_COMPARATOR);
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            try {
                sourceDirectory.getVirtualFile().rename(this, EduNames.LESSON + newItemIndex);
            } catch (IOException e) {
                LOG.error(e);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MoveHandlerDelegate(com.intellij.refactoring.move.MoveHandlerDelegate) DataContext(com.intellij.openapi.actionSystem.DataContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeView(com.intellij.ide.IdeView) EduUtils(com.jetbrains.edu.learning.core.EduUtils) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) MoveCallback(com.intellij.refactoring.move.MoveCallback) CCMoveStudyItemDialog(com.jetbrains.edu.coursecreator.ui.CCMoveStudyItemDialog) PsiReference(com.intellij.psi.PsiReference) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) IOException(java.io.IOException) StudyTaskManager(com.jetbrains.edu.learning.StudyTaskManager) Editor(com.intellij.openapi.editor.Editor) DirectoryChooserUtil(com.intellij.ide.util.DirectoryChooserUtil) Nullable(org.jetbrains.annotations.Nullable) Function(com.intellij.util.Function) EduNames(com.jetbrains.edu.learning.core.EduNames) StudyItem(com.jetbrains.edu.learning.courseFormat.StudyItem) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PsiDirectory(com.intellij.psi.PsiDirectory) LangDataKeys(com.intellij.openapi.actionSystem.LangDataKeys) Collections(java.util.Collections) CCUtils(com.jetbrains.edu.coursecreator.CCUtils) Course(com.jetbrains.edu.learning.courseFormat.Course) IOException(java.io.IOException) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) PsiDirectory(com.intellij.psi.PsiDirectory) Course(com.jetbrains.edu.learning.courseFormat.Course) CCMoveStudyItemDialog(com.jetbrains.edu.coursecreator.ui.CCMoveStudyItemDialog) StudyItem(com.jetbrains.edu.learning.courseFormat.StudyItem)

Aggregations

Course (com.jetbrains.edu.learning.courseFormat.Course)51 Project (com.intellij.openapi.project.Project)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)12 PsiDirectory (com.intellij.psi.PsiDirectory)11 Lesson (com.jetbrains.edu.learning.courseFormat.Lesson)10 File (java.io.File)10 IdeView (com.intellij.ide.IdeView)8 Nullable (org.jetbrains.annotations.Nullable)6 Presentation (com.intellij.openapi.actionSystem.Presentation)5 PsiFile (com.intellij.psi.PsiFile)5 Task (com.jetbrains.edu.learning.courseFormat.Task)5 NotNull (org.jetbrains.annotations.NotNull)5 Editor (com.intellij.openapi.editor.Editor)4 PsiElement (com.intellij.psi.PsiElement)4 List (java.util.List)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)3 ApplicationManager (com.intellij.openapi.application.ApplicationManager)3 Module (com.intellij.openapi.module.Module)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3