refresh placeholder for subtasks
authorLiana.Bakradze <liana.bakradze@jetbrains.com>
Mon, 3 Oct 2016 10:04:41 +0000 (13:04 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 17 Nov 2016 14:08:26 +0000 (17:08 +0300)
python/educational-core/student/src/com/jetbrains/edu/learning/StudySubtaskUtils.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyRefreshAnswerPlaceholder.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyRefreshTaskFileAction.java

index 895acdba3c2c691e93e74a7005104442ca869dc7..008389400d2a010fd5d26ee2ba9f3e068f5470c9 100644 (file)
@@ -2,6 +2,7 @@ package com.jetbrains.edu.learning;
 
 import com.intellij.ide.projectView.ProjectView;
 import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
@@ -9,7 +10,9 @@ import com.intellij.problems.WolfTheProblemSolver;
 import com.intellij.ui.EditorNotifications;
 import com.jetbrains.edu.learning.checker.StudyCheckUtils;
 import com.jetbrains.edu.learning.core.EduNames;
+import com.jetbrains.edu.learning.core.EduUtils;
 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
+import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo;
 import com.jetbrains.edu.learning.courseFormat.Task;
 import com.jetbrains.edu.learning.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.ui.StudyToolWindow;
@@ -84,4 +87,11 @@ public class StudySubtaskUtils {
     }
     taskFile.setTrackLengths(true);
   }
+
+  public static void refreshPlaceholder(@NotNull Project project, @NotNull Editor editor, @NotNull AnswerPlaceholder placeholder) {
+    int prevSubtaskIndex = placeholder.getActiveSubtaskIndex() - 1;
+    AnswerPlaceholderSubtaskInfo info = placeholder.getSubtaskInfos().get(prevSubtaskIndex);
+    String replacementText = info != null ? info.getAnswer() : placeholder.getTaskText();
+    EduUtils.replaceAnswerPlaceholder(project, editor.getDocument(), placeholder, placeholder.getRealLength(), replacementText);
+  }
 }
\ No newline at end of file
index b2b7c86aadf05253f47c61a1bd643d93ce43d68e..3c45e8e701e07ecf555ffa5ed7d33fb727aed88f 100644 (file)
@@ -11,14 +11,11 @@ import com.intellij.openapi.extensions.Extensions;
 import com.intellij.openapi.project.DumbAwareAction;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.TextRange;
-import com.jetbrains.edu.learning.StudyActionListener;
-import com.jetbrains.edu.learning.StudyTaskManager;
+import com.jetbrains.edu.learning.*;
 import com.jetbrains.edu.learning.core.EduNames;
 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.learning.courseFormat.Course;
 import com.jetbrains.edu.learning.courseFormat.TaskFile;
-import com.jetbrains.edu.learning.StudyState;
-import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.editor.StudyEditor;
 import org.jetbrains.annotations.Nullable;
 
@@ -45,6 +42,10 @@ public class StudyRefreshAnswerPlaceholder extends DumbAwareAction {
     }
     StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
     final StudyState studyState = new StudyState(studyEditor);
+    if (answerPlaceholder.getTaskFile().getTask().hasSubtasks()) {
+      StudySubtaskUtils.refreshPlaceholder(project, studyState.getEditor(), answerPlaceholder);
+      return;
+    }
     Document patternDocument = StudyUtils.getPatternDocument(answerPlaceholder.getTaskFile(), studyState.getVirtualFile().getName());
     if (patternDocument == null) {
       return;
index 2a1f54ad2cb1024f9e1c8bcb3a67452e4cd5ea6a..1949b84bb6b296a88fe3cfd0dd24d738f6eeaede 100644 (file)
@@ -20,14 +20,13 @@ import com.intellij.openapi.ui.popup.JBPopupFactory;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.wm.IdeFocusManager;
 import com.intellij.problems.WolfTheProblemSolver;
-import com.jetbrains.edu.learning.StudyActionListener;
-import com.jetbrains.edu.learning.StudyState;
-import com.jetbrains.edu.learning.StudyTaskManager;
-import com.jetbrains.edu.learning.StudyUtils;
+import com.jetbrains.edu.learning.*;
 import com.jetbrains.edu.learning.core.EduAnswerPlaceholderPainter;
 import com.jetbrains.edu.learning.core.EduNames;
-import com.jetbrains.edu.learning.core.EduUtils;
-import com.jetbrains.edu.learning.courseFormat.*;
+import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
+import com.jetbrains.edu.learning.courseFormat.Course;
+import com.jetbrains.edu.learning.courseFormat.StudyStatus;
+import com.jetbrains.edu.learning.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.editor.StudyEditor;
 import com.jetbrains.edu.learning.navigation.StudyNavigator;
 import icons.InteractiveLearningIcons;
@@ -63,11 +62,8 @@ public class StudyRefreshTaskFileAction extends StudyActionWithShortcut {
     final Editor editor = studyState.getEditor();
     final TaskFile taskFile = studyState.getTaskFile();
     if (taskFile.getTask().hasSubtasks()) {
-      int prevSubtaskIndex = taskFile.getTask().getActiveSubtaskIndex() - 1;
       for (AnswerPlaceholder placeholder : taskFile.getActivePlaceholders()) {
-        AnswerPlaceholderSubtaskInfo info = placeholder.getSubtaskInfos().get(prevSubtaskIndex);
-        String replacementText = info != null ? info.getAnswer() : placeholder.getTaskText();
-        EduUtils.replaceAnswerPlaceholder(project, editor.getDocument(), placeholder, placeholder.getRealLength(), replacementText);
+        StudySubtaskUtils.refreshPlaceholder(project, editor, placeholder);
       }
     }
     else {