fixed EDU-301 and some minor changes
authorliana.bakradze <liana.bakradze@jetbrains.com>
Sun, 21 Dec 2014 18:05:03 +0000 (21:05 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Sun, 21 Dec 2014 18:05:03 +0000 (21:05 +0300)
python/edu/learn-python/src/com/jetbrains/python/edu/actions/StudyCheckAction.java
python/edu/learn-python/src/com/jetbrains/python/edu/course/TaskWindow.java

index 8ca2671a45c8ef9a12162de617638f508082c26b..f9c78c422d3e9b989056267fa3eab338cbc42b8d 100644 (file)
@@ -176,6 +176,7 @@ public class StudyCheckAction extends DumbAwareAction {
                                                                          final StudyEditor selectedEditor) {
     final Task task = studyState.getTask();
     final VirtualFile taskDir = studyState.getTaskDir();
+    final StudyStatus statusBeforeCheck = task.getStatus();
     return new com.intellij.openapi.progress.Task.Backgroundable(project, "Checking task", true) {
       @Override
       public void onSuccess() {
@@ -188,13 +189,14 @@ public class StudyCheckAction extends DumbAwareAction {
 
       @Override
       public void onCancel() {
+        StudyStatus currentStatus = task.getStatus();
+        task.setStatus(statusBeforeCheck, currentStatus);
         deleteWindowDescriptions(task, taskDir);
         selectedEditor.getCheckButton().setEnabled(true);
       }
 
       @Override
       public void run(@NotNull ProgressIndicator indicator) {
-        final StudyStatus oldStatus = task.getStatus();
         final Map<String, TaskFile> taskFiles = task.getTaskFiles();
         final CapturingProcessHandler handler = new CapturingProcessHandler(testProcess);
         final ProcessOutput output = handler.runProcessWithProgressIndicator(indicator);
@@ -209,7 +211,7 @@ public class StudyCheckAction extends DumbAwareAction {
         }
         final String failedMessage = testRunner.getTestsOutput(output);
         if (StudyTestRunner.TEST_OK.equals(failedMessage)) {
-          task.setStatus(StudyStatus.Solved, oldStatus);
+          task.setStatus(StudyStatus.Solved, statusBeforeCheck);
           ApplicationManager.getApplication().invokeLater(new Runnable() {
             @Override
             public void run() {
@@ -222,7 +224,7 @@ public class StudyCheckAction extends DumbAwareAction {
             @Override
             public void run() {
               if (taskDir == null) return;
-              task.setStatus(StudyStatus.Failed, oldStatus);
+              task.setStatus(StudyStatus.Failed, statusBeforeCheck);
               for (Map.Entry<String, TaskFile> entry : taskFiles.entrySet()) {
                 final String name = entry.getKey();
                 final TaskFile taskFile = entry.getValue();
@@ -318,14 +320,14 @@ public class StudyCheckAction extends DumbAwareAction {
                                    final String taskFileName,
                                    @NotNull final TaskFile taskFile,
                                    @NotNull final Project project) {
-    TaskFile answerTaskFile = new TaskFile();
-    VirtualFile virtualFile = taskDir.findChild(taskFileName);
+    final TaskFile answerTaskFile = new TaskFile();
+    final VirtualFile virtualFile = taskDir.findChild(taskFileName);
     if (virtualFile == null) {
       return;
     }
-    VirtualFile answerFile = getCopyWithAnswers(taskDir, virtualFile, taskFile, answerTaskFile);
-    for (TaskWindow taskWindow : answerTaskFile.getTaskWindows()) {
-      Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
+    final VirtualFile answerFile = getCopyWithAnswers(taskDir, virtualFile, taskFile, answerTaskFile);
+    for (final TaskWindow taskWindow : answerTaskFile.getTaskWindows()) {
+      final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
       if (document == null) {
         continue;
       }
index a4211b17a15caff67f7be47244d47ab0f5a9d975..2229309092e723ba0b8a7ec03a8a875f944b88e8 100644 (file)
@@ -9,7 +9,10 @@ import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.colors.EditorColors;
 import com.intellij.openapi.editor.colors.EditorColorsManager;
-import com.intellij.openapi.editor.markup.*;
+import com.intellij.openapi.editor.markup.HighlighterLayer;
+import com.intellij.openapi.editor.markup.HighlighterTargetArea;
+import com.intellij.openapi.editor.markup.RangeHighlighter;
+import com.intellij.openapi.editor.markup.TextAttributes;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.TextRange;
@@ -197,19 +200,19 @@ public class TaskWindow implements Comparable, Stateful {
                          @NotNull final Document usersDocument) {
 
     try {
-      VirtualFile windowCopy =
-        answerFile.copy(this, answerFile.getParent(), answerFile.getNameWithoutExtension() + WINDOW_POSTFIX);
+      final VirtualFile windowCopy =
+        answerFile.copy(this, answerFile.getParent(), answerFile.getNameWithoutExtension() + myIndex + WINDOW_POSTFIX);
       final FileDocumentManager documentManager = FileDocumentManager.getInstance();
       final Document windowDocument = documentManager.getDocument(windowCopy);
       if (windowDocument != null) {
-        File resourceFile = StudyUtils.copyResourceFile(virtualFile.getName(), windowCopy.getName(), project, usersTaskFile.getTask());
-        TaskFile windowTaskFile = new TaskFile();
+        final File resourceFile = StudyUtils.copyResourceFile(virtualFile.getName(), windowCopy.getName(), project, usersTaskFile.getTask());
+        final TaskFile windowTaskFile = new TaskFile();
         TaskFile.copy(answerTaskFile, windowTaskFile);
         StudyDocumentListener listener = new StudyDocumentListener(windowTaskFile);
         windowDocument.addDocumentListener(listener);
         int start = getRealStartOffset(windowDocument);
         int end = start + getLength();
-        TaskWindow userTaskWindow = usersTaskFile.getTaskWindows().get(getIndex());
+        final TaskWindow userTaskWindow = usersTaskFile.getTaskWindows().get(getIndex());
         int userStart = userTaskWindow.getRealStartOffset(usersDocument);
         int userEnd = userStart + userTaskWindow.getLength();
         String text = usersDocument.getText(new TextRange(userStart, userEnd));