diff options
Diffstat (limited to 'python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectService.java')
-rw-r--r-- | python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectService.java | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectService.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectService.java index 1e38bab865cb..c06925e9a453 100644 --- a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectService.java +++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectService.java @@ -32,6 +32,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.coursecreator.format.*; import java.io.File; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -70,6 +71,9 @@ public class CCProjectService implements PersistentStateComponent<Element> { @Override public void loadState(Element el) { myCourse = XmlSerializer.deserialize(el.getChild(COURSE_ELEMENT), Course.class); + if (myCourse != null) { + myCourse.init(); + } } public static CCProjectService getInstance(@NotNull Project project) { @@ -115,7 +119,7 @@ public class CCProjectService implements PersistentStateComponent<Element> { } List<TaskWindow> taskWindows = taskFile.getTaskWindows(); for (TaskWindow taskWindow : taskWindows) { - taskWindow.drawHighlighter(editor); + taskWindow.drawHighlighter(editor, false); } } @@ -131,8 +135,52 @@ public class CCProjectService implements PersistentStateComponent<Element> { myDocumentListeners.remove(document); } - public static boolean indexIsValid(int index, List<TaskWindow> collection) { + public static boolean indexIsValid(int index, Collection collection) { int size = collection.size(); return index >= 0 && index < size; } + + public boolean isTaskFile(VirtualFile file) { + if (myCourse == null || file == null) { + return false; + } + VirtualFile taskDir = file.getParent(); + if (taskDir != null) { + String taskDirName = taskDir.getName(); + if (taskDirName.contains("task")) { + VirtualFile lessonDir = taskDir.getParent(); + if (lessonDir != null) { + String lessonDirName = lessonDir.getName(); + int lessonIndex = getIndex(lessonDirName, "lesson"); + List<Lesson> lessons = myCourse.getLessons(); + if (!indexIsValid(lessonIndex, lessons)) { + return false; + } + Lesson lesson = lessons.get(lessonIndex); + int taskIndex = getIndex(taskDirName, "task"); + List<Task> tasks = lesson.getTaskList(); + if (!indexIsValid(taskIndex, tasks)) { + return false; + } + Task task = tasks.get(taskIndex); + return task.isTaskFile(file.getName()); + } + } + } + return false; + } + + public static int getIndex(@NotNull final String fullName, @NotNull final String logicalName) { + if (!fullName.contains(logicalName)) { + throw new IllegalArgumentException(); + } + return Integer.parseInt(fullName.substring(logicalName.length())) - 1; + } + public static String getRealTaskFileName(String name) { + if (!name.contains(".answer")) { + return null; + } + int nameEnd = name.indexOf(".answer"); + return name.substring(0, nameEnd) + ".py"; + } } |