fix unpack course action
[idea/community.git] / python / educational-core / course-creator / src / com / jetbrains / edu / coursecreator / actions / CCFromCourseArchive.java
index a7c6a91dc52e12210526f5a4c77ef41cb580879e..7c45e53a920e0c834609fccf75061be2971192b1 100644 (file)
@@ -22,10 +22,11 @@ import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.platform.templates.github.ZipUtil;
+import com.jetbrains.edu.coursecreator.CCUtils;
+import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.core.EduDocumentListener;
 import com.jetbrains.edu.learning.core.EduNames;
 import com.jetbrains.edu.learning.core.EduUtils;
-import com.jetbrains.edu.coursecreator.CCProjectService;
 import com.jetbrains.edu.learning.courseFormat.*;
 import com.jetbrains.edu.learning.oldCourseFormat.OldCourse;
 import org.jetbrains.annotations.NotNull;
@@ -58,7 +59,6 @@ public class CCFromCourseArchive extends DumbAwareAction {
     }
     final String basePath = project.getBasePath();
     if (basePath == null) return;
-    final CCProjectService service = CCProjectService.getInstance(project);
     Reader reader = null;
     try {
       ZipUtil.unzip(null, new File(basePath), new File(virtualFile.getPath()), null, null, true);
@@ -77,7 +77,8 @@ public class CCFromCourseArchive extends DumbAwareAction {
         course = EduUtils.transformOldCourse(oldCourse);
       }
 
-      service.setCourse(course);
+      StudyTaskManager.getInstance(project).setCourse(course);
+      course.setCourseMode(CCUtils.COURSE_MODE);
       project.getBaseDir().refresh(false, true);
       int index = 1;
       int taskIndex = 1;
@@ -94,7 +95,7 @@ public class CCFromCourseArchive extends DumbAwareAction {
             ApplicationManager.getApplication().runWriteAction(new Runnable() {
               @Override
               public void run() {
-                createAnswerFile(project, taskDir, taskDir, entry);
+                createAnswerFile(project, taskDir, entry);
               }
             });
           }
@@ -103,6 +104,7 @@ public class CCFromCourseArchive extends DumbAwareAction {
         index += 1;
         taskIndex = 1;
       }
+      course.initCourse(true);
     }
     catch (FileNotFoundException e) {
       LOG.error(e.getMessage());
@@ -128,7 +130,6 @@ public class CCFromCourseArchive extends DumbAwareAction {
 
   public static void createAnswerFile(@NotNull final Project project,
                                       @NotNull final VirtualFile userFileDir,
-                                      @NotNull final VirtualFile answerFileDir,
                                       @NotNull final Map.Entry<String, TaskFile> taskFileEntry) {
     final String name = taskFileEntry.getKey();
     final TaskFile taskFile = taskFileEntry.getValue();
@@ -185,6 +186,7 @@ public class CCFromCourseArchive extends DumbAwareAction {
           public void run() {
             final String text = document.getText(TextRange.create(offset, offset + answerPlaceholder.getLength()));
             answerPlaceholder.setTaskText(text);
+            answerPlaceholder.init();
             final VirtualFile hints = project.getBaseDir().findChild(EduNames.HINTS);
             if (hints != null) {
               final String hintFile = answerPlaceholder.getHint();