EDU-487 Broken placeholders
authorliana.bakradze <liana.bakradze@jetbrains.com>
Wed, 23 Sep 2015 11:50:45 +0000 (14:50 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Wed, 23 Sep 2015 11:52:21 +0000 (14:52 +0300)
python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateCourseArchive.java

index 94222fb32a9b27bef4aa9b4c21a75119851ea72a..87f15abad5154cbf02557aba7d80cd306a9cf9b8 100644 (file)
@@ -15,6 +15,7 @@ import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
+import com.intellij.util.containers.hash.HashMap;
 import com.intellij.util.io.ZipUtil;
 import com.jetbrains.edu.EduNames;
 import com.jetbrains.edu.EduUtils;
 import com.intellij.util.io.ZipUtil;
 import com.jetbrains.edu.EduNames;
 import com.jetbrains.edu.EduUtils;
@@ -76,6 +77,7 @@ public class CCCreateCourseArchive extends DumbAwareAction {
     final VirtualFile baseDir = project.getBaseDir();
     final List<Lesson> lessons = course.getLessons();
 
     final VirtualFile baseDir = project.getBaseDir();
     final List<Lesson> lessons = course.getLessons();
 
+    final Map<TaskFile, TaskFile> savedTaskFiles = new HashMap<TaskFile, TaskFile>();
     for (Lesson lesson : lessons) {
       final VirtualFile lessonDir = baseDir.findChild(EduNames.LESSON + String.valueOf(lesson.getIndex()));
       if (lessonDir == null) continue;
     for (Lesson lesson : lessons) {
       final VirtualFile lessonDir = baseDir.findChild(EduNames.LESSON + String.valueOf(lesson.getIndex()));
       if (lessonDir == null) continue;
@@ -86,8 +88,10 @@ public class CCCreateCourseArchive extends DumbAwareAction {
           ApplicationManager.getApplication().runWriteAction(new Runnable() {
             @Override
             public void run() {
           ApplicationManager.getApplication().runWriteAction(new Runnable() {
             @Override
             public void run() {
-              TaskFile taskFile = new TaskFile();
-              TaskFile.copy(entry.getValue(), taskFile);
+              TaskFile taskFileCopy = new TaskFile();
+              TaskFile taskFile = entry.getValue();
+              TaskFile.copy(taskFile, taskFileCopy);
+              savedTaskFiles.put(taskFile, taskFileCopy);
               EduUtils.createStudentFileFromAnswer(project, taskDir, taskDir, entry.getKey(), taskFile);
             }
           });
               EduUtils.createStudentFileFromAnswer(project, taskDir, taskDir, entry.getKey(), taskFile);
             }
           });
@@ -98,6 +102,13 @@ public class CCCreateCourseArchive extends DumbAwareAction {
     VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
     packCourse(baseDir, course);
     synchronize(project);
     VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
     packCourse(baseDir, course);
     synchronize(project);
+    resetTaskFiles(savedTaskFiles);
+  }
+
+  private static void resetTaskFiles(Map<TaskFile, TaskFile> savedTaskFiles) {
+    for (Map.Entry<TaskFile, TaskFile> entry : savedTaskFiles.entrySet()) {
+      entry.getKey().setAnswerPlaceholders(entry.getValue().getAnswerPlaceholders());
+    }
   }
 
   private static void synchronize(@NotNull final Project project) {
   }
 
   private static void synchronize(@NotNull final Project project) {