show preview for subtasks
authorLiana.Bakradze <liana.bakradze@jetbrains.com>
Thu, 29 Sep 2016 11:57:28 +0000 (14:57 +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/actions/CCShowPreview.java
python/educational-core/student/src/com/jetbrains/edu/learning/core/EduUtils.java

index ef6b7a6c960c81b12b04e613eb3a28cbeb056dd5..d4185c7e6a4d48f1fadb12644c45503eb61937e4 100644 (file)
@@ -52,6 +52,7 @@ import javax.swing.border.EmptyBorder;
 import java.awt.*;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
+import java.util.Collections;
 
 public class CCShowPreview extends DumbAwareAction {
   public static final String SHOW_PREVIEW = "Show Preview";
@@ -147,7 +148,8 @@ public class CCShowPreview extends DumbAwareAction {
       }
     });
     for (AnswerPlaceholder answerPlaceholder : taskFile.getActivePlaceholders()) {
-      answerPlaceholder.setUseLength(true);
+      Integer minIndex = Collections.min(answerPlaceholder.getSubtaskInfos().keySet());
+      answerPlaceholder.setUseLength(minIndex >= answerPlaceholder.getActiveSubtaskIndex());
       EduAnswerPlaceholderPainter.drawAnswerPlaceholder(createdEditor, answerPlaceholder, JBColor.BLUE);
     }
     JPanel header = new JPanel();
index 6a7bb8c1b3e64e06898320e1629af07770f36115..2d225567eba0ab48bfbbfb2289265d0b734d30c5 100644 (file)
@@ -20,6 +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.StudyUtils;
 import com.jetbrains.edu.learning.courseFormat.*;
 import org.jetbrains.annotations.NonNls;
@@ -164,6 +165,14 @@ public class EduUtils {
     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());
     }
     studentDocument.removeDocumentListener(listener);