create course archive for subtasks
authorLiana.Bakradze <liana.bakradze@jetbrains.com>
Thu, 29 Sep 2016 13:06:07 +0000 (16:06 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 17 Nov 2016 14:08:21 +0000 (17:08 +0300)
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateCourseArchive.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCShowPreview.java
python/educational-core/student/src/com/jetbrains/edu/learning/StudySubtaskUtils.java
python/educational-core/student/src/com/jetbrains/edu/learning/core/EduUtils.java
python/educational-core/student/src/com/jetbrains/edu/learning/stepic/StepicWrappers.java

index ebd5030f7b730aa821f70a13c1f34fc8226f3c6d..28443bc23e5b551aea8b36ca42086460dccc5616 100644 (file)
@@ -231,7 +231,7 @@ public class CCUtils {
         continue;
       }
       ApplicationManager.getApplication().runWriteAction(() -> {
-        EduUtils.createStudentFile(CCUtils.class, project, answerFile, studentDir, null);
+        EduUtils.createStudentFile(CCUtils.class, project, answerFile, studentDir, null, task.getActiveSubtaskIndex());
       });
     }
   }
index 85c257fa03af592de46b1bf3373e2c3357df60c0..45f8d8ba8b8110be4f3027ca64e76856fe358c21 100644 (file)
@@ -127,7 +127,7 @@ public class CCCreateCourseArchive extends DumbAwareAction {
               if (answerFile == null) {
                 continue;
               }
-              EduUtils.createStudentFile(this, project, answerFile, studentFileDir, task);
+              EduUtils.createStudentFile(this, project, answerFile, studentFileDir, task, 0);
             }
         }
       }
index d4185c7e6a4d48f1fadb12644c45503eb61937e4..b6e1e806ce41637deb27a2715df7f6a60090c02c 100644 (file)
@@ -124,7 +124,7 @@ public class CCShowPreview extends DumbAwareAction {
       @Override
       public void run() {
         Pair<VirtualFile, TaskFile> pair =
-          EduUtils.createStudentFile(this, project, virtualFile, generatedFilesFolder, null);
+          EduUtils.createStudentFile(this, project, virtualFile, generatedFilesFolder, null, taskFile.getTask().getActiveSubtaskIndex());
         if (pair != null) {
           showPreviewDialog(project, pair.getFirst(), pair.getSecond());
         }
index ba18c52fd6b0b03a2a35fa5f5e4179117bba3a5c..45499d5aa637d4bb5a08db9798501d03bf4e2651 100644 (file)
@@ -46,7 +46,11 @@ public class StudySubtaskUtils {
         continue;
       }
       TaskFile taskFile = entry.getValue();
-      updatePlaceholderTexts(project, virtualFile, taskFile, fromSubtaskIndex, toSubtaskIndex);
+      Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
+      if (document == null) {
+        continue;
+      }
+      updatePlaceholderTexts(project, document, taskFile, fromSubtaskIndex, toSubtaskIndex);
       EditorNotifications.getInstance(project).updateNotifications(virtualFile);
     }
     task.setActiveSubtaskIndex(toSubtaskIndex);
@@ -67,17 +71,21 @@ public class StudySubtaskUtils {
     }
   }
 
-  private static void updatePlaceholderTexts(@NotNull Project project,
-                                             @NotNull VirtualFile virtualFile,
+  public static void updatePlaceholderTexts(@NotNull Project project,
+                                             @NotNull Document document,
                                              @NotNull TaskFile taskFile,
                                              int fromSubtaskIndex,
                                              int toSubtaskIndex) {
-    Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
-    if (document == null) {
-      return;
-    }
     taskFile.setTrackLengths(false);
     for (AnswerPlaceholder placeholder : taskFile.getAnswerPlaceholders()) {
+      AnswerPlaceholderSubtaskInfo fromSubtaskInfo = placeholder.getSubtaskInfos().get(fromSubtaskIndex);
+      if (fromSubtaskIndex == toSubtaskIndex && fromSubtaskInfo != null) {
+        String placeholderText = fromSubtaskInfo.getPlaceholderText();
+        if (placeholderText != null) {
+          EduUtils.replaceAnswerPlaceholder(project, document, placeholder, placeholder.getRealLength(), placeholderText);
+        }
+        continue;
+      }
       Set<Integer> indexes = placeholder.getSubtaskInfos().keySet();
       Integer minIndex = Collections.min(indexes);
       int visibleLength = placeholder.getVisibleLength(fromSubtaskIndex);
index 2d225567eba0ab48bfbbfb2289265d0b734d30c5..276c1988f73d65e285ef0a9efaa31c7796b28e77 100644 (file)
@@ -20,7 +20,7 @@ import com.intellij.openapi.vfs.VfsUtilCore;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.psi.PsiDirectory;
-import com.intellij.util.containers.ContainerUtil;
+import com.jetbrains.edu.learning.StudySubtaskUtils;
 import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.courseFormat.*;
 import org.jetbrains.annotations.NonNls;
@@ -140,7 +140,8 @@ public class EduUtils {
                                                               Project project,
                                                               VirtualFile answerFile,
                                                               VirtualFile parentDir,
-                                                              @Nullable Task task) {
+                                                              @Nullable Task task,
+                                                              int toSubtaskIndex) {
 
     VirtualFile studentFile = copyFile(requestor, parentDir, answerFile);
     if (studentFile == null) {
@@ -163,18 +164,7 @@ public class EduUtils {
     }
     EduDocumentListener listener = new EduDocumentListener(taskFile, false);
     studentDocument.addDocumentListener(listener);
-
-    for (AnswerPlaceholder placeholder : taskFile.getActivePlaceholders()) {
-      Set<Integer> indexes = placeholder.getSubtaskInfos().keySet();
-      int activeSubtaskIndex = task.getActiveSubtaskIndex();
-      if (Collections.min(indexes) < activeSubtaskIndex) {
-        Integer max = Collections.max(ContainerUtil.filter(indexes, i -> i < activeSubtaskIndex));
-        String possibleAnswer = placeholder.getSubtaskInfos().get(max).getPossibleAnswer();
-        replaceAnswerPlaceholder(project, studentDocument, placeholder, placeholder.getRealLength(), possibleAnswer);
-        continue;
-      }
-      replaceAnswerPlaceholder(project, studentDocument, placeholder, placeholder.getRealLength(), placeholder.getTaskText());
-    }
+    StudySubtaskUtils.updatePlaceholderTexts(project, studentDocument, taskFile, task.getActiveSubtaskIndex(), toSubtaskIndex);
     studentDocument.removeDocumentListener(listener);
     return Pair.create(studentFile, taskFile);
   }
index 01336b30eb05874851ead68a5cf91aecad5cfda6..edae1ae80acb450411bf6563bb2a2901b6207224 100644 (file)
@@ -78,7 +78,7 @@ public class StepicWrappers {
           }
           String name = entry.getKey();
           VirtualFile answerFile = taskDir.findChild(name);
-          Pair<VirtualFile, TaskFile> pair = EduUtils.createStudentFile(StepicWrappers.class, project, answerFile, stepicDir, null);
+          Pair<VirtualFile, TaskFile> pair = EduUtils.createStudentFile(StepicWrappers.class, project, answerFile, stepicDir, null, 0);
           if (pair == null) {
             return;
           }