Search in sources :

Example 6 with TaskFile

use of com.jetbrains.edu.learning.courseFormat.TaskFile 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 7 with TaskFile

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

the class CCHideFromStudent method performAction.

@Override
protected void performAction(VirtualFile file, Task task, Course course, Project project) {
    TaskFile taskFile = StudyUtils.getTaskFile(project, file);
    if (taskFile == null) {
        return;
    }
    EduUtils.runUndoableAction(project, ACTION_NAME, new HideTaskFile(project, course, file, task, taskFile));
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile)

Example 8 with TaskFile

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

the class CCShowPreview method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = e.getProject();
    Module module = LangDataKeys.MODULE.getData(e.getDataContext());
    if (project == null || module == null) {
        return;
    }
    final PsiFile file = CommonDataKeys.PSI_FILE.getData(e.getDataContext());
    if (file == null) {
        return;
    }
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    VirtualFile virtualFile = file.getVirtualFile();
    TaskFile taskFile = StudyUtils.getTaskFile(project, virtualFile);
    if (taskFile == null) {
        return;
    }
    final PsiDirectory taskDir = file.getContainingDirectory();
    if (taskDir == null) {
        return;
    }
    PsiDirectory lessonDir = taskDir.getParentDirectory();
    if (lessonDir == null) {
        return;
    }
    if (taskFile.getActivePlaceholders().isEmpty()) {
        Messages.showInfoMessage("Preview is available for task files with answer placeholders only", "No Preview for This File");
        return;
    }
    VirtualFile generatedFilesFolder = CCUtils.getGeneratedFilesFolder(project, module);
    if (generatedFilesFolder == null) {
        return;
    }
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            Pair<VirtualFile, TaskFile> pair = EduUtils.createStudentFile(this, project, virtualFile, generatedFilesFolder, null, taskFile.getTask().getActiveSubtaskIndex());
            if (pair != null) {
                showPreviewDialog(project, pair.getFirst(), pair.getSecond());
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) Course(com.jetbrains.edu.learning.courseFormat.Course) Pair(com.intellij.openapi.util.Pair)

Example 9 with TaskFile

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

the class CCAddAnswerPlaceholder method canAddPlaceholder.

private static boolean canAddPlaceholder(@NotNull CCState state) {
    Editor editor = state.getEditor();
    SelectionModel selectionModel = editor.getSelectionModel();
    TaskFile taskFile = state.getTaskFile();
    if (selectionModel.hasSelection()) {
        int start = selectionModel.getSelectionStart();
        int end = selectionModel.getSelectionEnd();
        return !arePlaceholdersIntersect(taskFile, start, end);
    }
    int offset = editor.getCaretModel().getOffset();
    return StudyUtils.getAnswerPlaceholder(offset, taskFile.getAnswerPlaceholders()) == null;
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) SelectionModel(com.intellij.openapi.editor.SelectionModel) Editor(com.intellij.openapi.editor.Editor)

Example 10 with TaskFile

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

the class CCAnswerPlaceholderAction method getState.

@Nullable
protected CCState getState(@NotNull AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null || !CCUtils.isCourseCreator(project)) {
        return null;
    }
    final PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(e.getDataContext());
    if (psiFile == null) {
        return null;
    }
    VirtualFile virtualFile = psiFile.getVirtualFile();
    if (virtualFile == null) {
        return null;
    }
    final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
    if (editor == null) {
        return null;
    }
    TaskFile taskFile = StudyUtils.getTaskFile(project, virtualFile);
    if (taskFile == null) {
        return null;
    }
    AnswerPlaceholder answerPlaceholder = StudyUtils.getAnswerPlaceholder(editor.getCaretModel().getOffset(), getPlaceholders(taskFile));
    return new CCState(taskFile, answerPlaceholder, psiFile, editor, project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)30 Project (com.intellij.openapi.project.Project)14 Editor (com.intellij.openapi.editor.Editor)11 AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)11 Map (java.util.Map)10 Course (com.jetbrains.edu.learning.courseFormat.Course)9 Task (com.jetbrains.edu.learning.courseFormat.Task)8 Document (com.intellij.openapi.editor.Document)7 PsiFile (com.intellij.psi.PsiFile)7 StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)7 File (java.io.File)6 Nullable (org.jetbrains.annotations.Nullable)6 FileEditor (com.intellij.openapi.fileEditor.FileEditor)5 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)4 Lesson (com.jetbrains.edu.learning.courseFormat.Lesson)4 Presentation (com.intellij.openapi.actionSystem.Presentation)3 EduDocumentListener (com.jetbrains.edu.learning.core.EduDocumentListener)3 AnswerPlaceholderSubtaskInfo (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo)3 ExecutionException (com.intellij.execution.ExecutionException)2