mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extracted course initialization
This commit is contained in:
+3
-2
@@ -33,6 +33,7 @@ import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
import com.jetbrains.edu.courseFormat.TaskFile;
|
||||
import com.jetbrains.edu.learning.actions.*;
|
||||
import com.jetbrains.edu.learning.courseGeneration.StudyGenerator;
|
||||
import com.jetbrains.edu.learning.ui.StudyCondition;
|
||||
import com.jetbrains.edu.learning.ui.StudyToolWindowFactory;
|
||||
import org.jdom.Element;
|
||||
@@ -99,7 +100,7 @@ public class StudyTaskManager implements ProjectComponent, PersistentStateCompon
|
||||
public void loadState(Element el) {
|
||||
myCourse = XmlSerializer.deserialize(el.getChild(COURSE_ELEMENT), Course.class);
|
||||
if (myCourse != null) {
|
||||
myCourse.init(true);
|
||||
StudyGenerator.initCourse(myCourse, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,7 +367,7 @@ public class StudyTaskManager implements ProjectComponent, PersistentStateCompon
|
||||
if (StudyUtils.indexIsValid(taskIndex, tasks)) {
|
||||
final Task task = tasks.get(taskIndex);
|
||||
final TaskFile taskFile = new TaskFile();
|
||||
taskFile.init(task, false);
|
||||
StudyGenerator.initTaskFile(taskFile, task, false);
|
||||
taskFile.setUserCreated(true);
|
||||
task.getTaskFiles().put(createdFile.getName(), taskFile);
|
||||
}
|
||||
|
||||
+58
-5
@@ -1,4 +1,4 @@
|
||||
package com.jetbrains.edu.learning;
|
||||
package com.jetbrains.edu.learning.courseGeneration;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -6,15 +6,15 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.edu.StudyNames;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
import com.jetbrains.edu.courseFormat.TaskFile;
|
||||
import com.jetbrains.edu.courseFormat.*;
|
||||
import com.jetbrains.edu.courseFormat.info.LessonInfo;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -135,4 +135,57 @@ public class StudyGenerator {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes state of course
|
||||
*/
|
||||
public static void initCourse(@NotNull final Course course, boolean isRestarted) {
|
||||
for (Lesson lesson : course.lessons) {
|
||||
initLesson(lesson, course, isRestarted);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initLesson(@NotNull final Lesson lesson, final Course course, boolean isRestarted) {
|
||||
lesson.setCourse(course);
|
||||
final LessonInfo info = lesson.getLessonInfo();
|
||||
final List<Task> taskList = lesson.getTaskList();
|
||||
info.setTaskNum(taskList.size());
|
||||
info.setTaskUnchecked(taskList.size());
|
||||
for (Task task : taskList) {
|
||||
initTask(task, lesson, isRestarted);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes state of task file
|
||||
*
|
||||
* @param lesson lesson which task belongs to
|
||||
*/
|
||||
public static void initTask(@NotNull final Task task, final Lesson lesson, boolean isRestarted) {
|
||||
task.setLesson(lesson);
|
||||
for (TaskFile taskFile : task.getTaskFiles().values()) {
|
||||
initTaskFile(taskFile, task, isRestarted);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initTaskFile(@NotNull final TaskFile taskFile, final Task task, boolean isRestarted) {
|
||||
taskFile.setTask(task);
|
||||
final List<AnswerPlaceholder> answerPlaceholders = taskFile.getAnswerPlaceholders();
|
||||
for (AnswerPlaceholder answerPlaceholder : answerPlaceholders) {
|
||||
initAnswerPlaceholder(answerPlaceholder, taskFile, isRestarted);
|
||||
}
|
||||
Collections.sort(answerPlaceholders);
|
||||
for (int i = 0; i < answerPlaceholders.size(); i++) {
|
||||
answerPlaceholders.get(i).setIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initAnswerPlaceholder(@NotNull final AnswerPlaceholder placeholder, final TaskFile file, boolean isRestarted) {
|
||||
if (!isRestarted) {
|
||||
placeholder.setInitialState(new AnswerPlaceholder.MyInitialState(placeholder.getLine(), placeholder.getLength(),
|
||||
placeholder.getStart()));
|
||||
}
|
||||
placeholder.setTaskFile(file);
|
||||
}
|
||||
|
||||
}
|
||||
+6
-2
@@ -1,4 +1,4 @@
|
||||
package com.jetbrains.edu.learning;
|
||||
package com.jetbrains.edu.learning.courseGeneration;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@@ -28,6 +28,10 @@ import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
import com.jetbrains.edu.courseFormat.TaskFile;
|
||||
import com.jetbrains.edu.learning.CourseInfo;
|
||||
import com.jetbrains.edu.learning.StudyLanguageManager;
|
||||
import com.jetbrains.edu.learning.StudyTaskManager;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import com.jetbrains.edu.learning.stepic.StudyStepicConnector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -57,7 +61,7 @@ public class StudyProjectGenerator {
|
||||
final Course course = StudyStepicConnector.getCourse(mySelectedCourseInfo);
|
||||
if (course == null) return;
|
||||
flushCourse(course);
|
||||
course.init(false);
|
||||
StudyGenerator.initCourse(course, false);
|
||||
final File courseDirectory = new File(myCoursesDir, course.getName());
|
||||
StudyGenerator.createCourse(course, baseDir, courseDirectory, project);
|
||||
course.setCourseDirectory(new File(myCoursesDir, mySelectedCourseInfo.getName()).getAbsolutePath());
|
||||
+1
-1
@@ -4,8 +4,8 @@ import com.intellij.facet.ui.FacetValidatorsManager;
|
||||
import com.intellij.facet.ui.ValidationResult;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.jetbrains.edu.learning.CourseInfo;
|
||||
import com.jetbrains.edu.learning.StudyProjectGenerator;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -24,14 +25,7 @@ public class AnswerPlaceholder implements Comparable, StudyStateful {
|
||||
private MyInitialState myInitialState;
|
||||
|
||||
|
||||
private TaskFile myTaskFile;
|
||||
|
||||
public void init(final TaskFile file, boolean isRestarted) {
|
||||
if (!isRestarted) {
|
||||
myInitialState = new MyInitialState(line, length, start);
|
||||
}
|
||||
myTaskFile = file;
|
||||
}
|
||||
@Transient private TaskFile myTaskFile;
|
||||
|
||||
public StudyStatus getStatus() {
|
||||
return myStatus;
|
||||
@@ -97,10 +91,16 @@ public class AnswerPlaceholder implements Comparable, StudyStateful {
|
||||
myInitialState = initialState;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public TaskFile getTaskFile() {
|
||||
return myTaskFile;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public void setTaskFile(TaskFile taskFile) {
|
||||
myTaskFile = taskFile;
|
||||
}
|
||||
|
||||
public JBColor getColor() {
|
||||
if (myStatus == StudyStatus.Solved) {
|
||||
return JBColor.GREEN;
|
||||
@@ -146,7 +146,7 @@ public class AnswerPlaceholder implements Comparable, StudyStateful {
|
||||
length = myInitialState.myLength;
|
||||
}
|
||||
|
||||
private static class MyInitialState {
|
||||
public static class MyInitialState {
|
||||
public int myLine = -1;
|
||||
public int myLength = -1;
|
||||
public int myStart = -1;
|
||||
|
||||
@@ -16,15 +16,6 @@ public class Course {
|
||||
private boolean myUpToDate;
|
||||
private String myLanguage;
|
||||
|
||||
/**
|
||||
* Initializes state of course
|
||||
*/
|
||||
public void init(boolean isRestarted) {
|
||||
for (Lesson lesson : lessons) {
|
||||
lesson.init(this, isRestarted);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Lesson> getLessons() {
|
||||
return lessons;
|
||||
}
|
||||
|
||||
@@ -20,20 +20,13 @@ public class Lesson implements StudyStateful {
|
||||
private String name;
|
||||
|
||||
public List<Task> taskList = new ArrayList<Task>();
|
||||
|
||||
@Transient
|
||||
private Course myCourse = null;
|
||||
private int myIndex = -1;
|
||||
private LessonInfo myLessonInfo = new LessonInfo();
|
||||
|
||||
|
||||
public void init(final Course course, boolean isRestarted) {
|
||||
myCourse = course;
|
||||
myLessonInfo.setTaskNum(taskList.size());
|
||||
myLessonInfo.setTaskUnchecked(taskList.size());
|
||||
for (Task task : taskList) {
|
||||
task.init(this, isRestarted);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -76,7 +69,13 @@ public class Lesson implements StudyStateful {
|
||||
return taskList;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public Course getCourse() {
|
||||
return myCourse;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public void setCourse(Course course) {
|
||||
myCourse = course;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,22 +24,10 @@ public class Task implements StudyStateful {
|
||||
private String text;
|
||||
private String testsText;
|
||||
|
||||
private Lesson myLesson;
|
||||
@Transient private Lesson myLesson;
|
||||
private List<UserTest> userTests = new ArrayList<UserTest>();
|
||||
|
||||
|
||||
/**
|
||||
* Initializes state of task file
|
||||
*
|
||||
* @param lesson lesson which task belongs to
|
||||
*/
|
||||
public void init(final Lesson lesson, boolean isRestarted) {
|
||||
myLesson = lesson;
|
||||
for (TaskFile taskFile : taskFiles.values()) {
|
||||
taskFile.init(this, isRestarted);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -120,10 +108,15 @@ public class Task implements StudyStateful {
|
||||
return taskFiles.get(fileName);
|
||||
}
|
||||
|
||||
@Transient
|
||||
public Lesson getLesson() {
|
||||
return myLesson;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public void setLesson(Lesson lesson) {
|
||||
myLesson = lesson;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public VirtualFile getTaskDir(Project project) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -24,24 +23,13 @@ public class TaskFile implements StudyStateful {
|
||||
|
||||
public String name;
|
||||
public String text;
|
||||
private Task myTask;
|
||||
@Transient private Task myTask;
|
||||
@Transient
|
||||
private AnswerPlaceholder mySelectedAnswerPlaceholder = null;
|
||||
private boolean myUserCreated = false;
|
||||
private boolean myTrackChanges = true;
|
||||
private boolean myHighlightErrors = false;
|
||||
|
||||
public void init(final Task task, boolean isRestarted) {
|
||||
myTask = task;
|
||||
for (AnswerPlaceholder answerPlaceholder : myAnswerPlaceholders) {
|
||||
answerPlaceholder.init(this, isRestarted);
|
||||
}
|
||||
Collections.sort(myAnswerPlaceholders);
|
||||
for (int i = 0; i < myAnswerPlaceholders.size(); i++) {
|
||||
myAnswerPlaceholders.get(i).setIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if all the windows in task file are marked as resolved
|
||||
*/
|
||||
@@ -96,10 +84,16 @@ public class TaskFile implements StudyStateful {
|
||||
myIndex = index;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public Task getTask() {
|
||||
return myTask;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public void setTask(Task task) {
|
||||
myTask = task;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pos position in editor
|
||||
* @return task window located in specified position or null if there is no task window in this position
|
||||
|
||||
Reference in New Issue
Block a user