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);
}
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;
}
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();
}
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");
}
}
}
}
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);
}
}
});
}
Aggregations