Search in sources :

Example 41 with Course

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

the class StudyShowHintAction method showHint.

public void showHint(Project project) {
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    StudyState studyState = new StudyState(StudyUtils.getSelectedStudyEditor(project));
    if (!studyState.isValid()) {
        return;
    }
    PsiFile file = PsiManager.getInstance(project).findFile(studyState.getVirtualFile());
    final Editor editor = studyState.getEditor();
    int offset = editor.getCaretModel().getOffset();
    AnswerPlaceholder answerPlaceholder = studyState.getTaskFile().getAnswerPlaceholder(offset);
    if (file == null) {
        return;
    }
    EduUsagesCollector.hintShown();
    final StudyToolWindow hintComponent = getHint(project, answerPlaceholder).getStudyToolWindow();
    hintComponent.setPreferredSize(new Dimension(400, 150));
    showHintPopUp(project, studyState, editor, hintComponent);
}
Also used : AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) StudyState(com.jetbrains.edu.learning.StudyState) PsiFile(com.intellij.psi.PsiFile) StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow) Course(com.jetbrains.edu.learning.courseFormat.Course) Editor(com.intellij.openapi.editor.Editor) StudyHint(com.jetbrains.edu.learning.ui.StudyHint)

Example 42 with Course

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

the class StudyProjectGenerator method readCourseFromCache.

@Nullable
private static Course readCourseFromCache(@NotNull File courseFile, boolean isAdaptive) {
    Reader reader = null;
    try {
        reader = new InputStreamReader(new FileInputStream(courseFile), "UTF-8");
        Gson gson = new GsonBuilder().registerTypeAdapter(Course.class, new StudySerializationUtils.Json.CourseTypeAdapter(courseFile)).create();
        final Course course = gson.fromJson(reader, Course.class);
        course.initCourse(isAdaptive);
        return course;
    } catch (UnsupportedEncodingException | FileNotFoundException e) {
        LOG.warn(e.getMessage());
    } finally {
        StudyUtils.closeSilently(reader);
    }
    return null;
}
Also used : StudySerializationUtils(com.jetbrains.edu.learning.StudySerializationUtils) JsonReader(com.google.gson.stream.JsonReader) Course(com.jetbrains.edu.learning.courseFormat.Course) Nullable(org.jetbrains.annotations.Nullable)

Example 43 with Course

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

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

the class CCPushCourse method update.

@Override
public void update(@NotNull AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    Project project = e.getProject();
    presentation.setEnabledAndVisible(project != null && CCUtils.isCourseCreator(project));
    if (project != null) {
        final Course course = StudyTaskManager.getInstance(project).getCourse();
        if (course != null) {
            final int id = course.getId();
            if (id > 0) {
                presentation.setText("Update Course on Stepik");
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) Presentation(com.intellij.openapi.actionSystem.Presentation) Course(com.jetbrains.edu.learning.courseFormat.Course)

Example 45 with Course

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

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