fixed EDU-328 Answer placeholder ranges are removable after first check
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Mon, 12 Jan 2015 12:53:08 +0000 (15:53 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Mon, 12 Jan 2015 12:53:08 +0000 (15:53 +0300)
python/edu/learn-python/src/com/jetbrains/python/edu/StudyEditorFactoryListener.java
python/edu/learn-python/src/com/jetbrains/python/edu/TaskWindowDeleteHandler.java [new file with mode: 0644]
python/edu/learn-python/src/com/jetbrains/python/edu/course/TaskFile.java

index 70612a70eddc19e90b2ce1ede56d3ea4dfbdcb3e..8d580923f6e41ee2ac5373ddb70e77383d0ef5e9 100644 (file)
@@ -1,15 +1,10 @@
 package com.jetbrains.python.edu;
 
 
-import com.intellij.codeInsight.hint.HintManager;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.LogicalPosition;
-import com.intellij.openapi.editor.ReadOnlyFragmentModificationException;
-import com.intellij.openapi.editor.actionSystem.EditorActionManager;
-import com.intellij.openapi.editor.actionSystem.ReadonlyFragmentModificationHandler;
-import com.intellij.openapi.editor.colors.EditorColors;
 import com.intellij.openapi.editor.event.EditorFactoryEvent;
 import com.intellij.openapi.editor.event.EditorFactoryListener;
 import com.intellij.openapi.editor.event.EditorMouseAdapter;
@@ -74,16 +69,12 @@ class StudyEditorFactoryListener implements EditorFactoryListener {
                 StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
                 TaskFile taskFile = taskManager.getTaskFile(openedFile);
                 if (taskFile != null) {
-                  EditorActionManager.getInstance()
-                    .setReadonlyFragmentModificationHandler(document, new TaskWindowDeleteHandler(editor));
                   taskFile.navigateToFirstTaskWindow(editor);
                   editor.addEditorMouseListener(new WindowSelectionListener(taskFile));
                   StudyDocumentListener listener = new StudyDocumentListener(taskFile);
                   StudyEditor.addDocumentListener(document, listener);
                   document.addDocumentListener(listener);
                   taskFile.drawAllWindows(editor);
-                  taskFile.createGuardedBlocks(document, editor);
-                  editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
                 }
               }
             }
@@ -105,18 +96,4 @@ class StudyEditorFactoryListener implements EditorFactoryListener {
     editor.getMarkupModel().removeAllHighlighters();
     editor.getSelectionModel().removeSelection();
   }
-
-  private static class TaskWindowDeleteHandler implements ReadonlyFragmentModificationHandler {
-
-    private final Editor myEditor;
-
-    public TaskWindowDeleteHandler(@NotNull final Editor editor) {
-      myEditor = editor;
-    }
-
-    @Override
-    public void handle(ReadOnlyFragmentModificationException e) {
-      HintManager.getInstance().showErrorHint(myEditor, "It's not allowed to delete answer placeholders");
-    }
-  }
 }
diff --git a/python/edu/learn-python/src/com/jetbrains/python/edu/TaskWindowDeleteHandler.java b/python/edu/learn-python/src/com/jetbrains/python/edu/TaskWindowDeleteHandler.java
new file mode 100644 (file)
index 0000000..334d78f
--- /dev/null
@@ -0,0 +1,21 @@
+package com.jetbrains.python.edu;
+
+import com.intellij.codeInsight.hint.HintManager;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.editor.ReadOnlyFragmentModificationException;
+import com.intellij.openapi.editor.actionSystem.ReadonlyFragmentModificationHandler;
+import org.jetbrains.annotations.NotNull;
+
+public class TaskWindowDeleteHandler implements ReadonlyFragmentModificationHandler {
+
+  private final Editor myEditor;
+
+  public TaskWindowDeleteHandler(@NotNull final Editor editor) {
+    myEditor = editor;
+  }
+
+  @Override
+  public void handle(ReadOnlyFragmentModificationException e) {
+    HintManager.getInstance().showErrorHint(myEditor, "It's not allowed to delete answer placeholders");
+  }
+}
index 74cb4bb1e51ee65bd90daac62b7fe5547231973f..b8908b606311ead9ef18effef4c64f74360d0551 100644 (file)
@@ -4,6 +4,8 @@ import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.LogicalPosition;
 import com.intellij.openapi.editor.RangeMarker;
+import com.intellij.openapi.editor.actionSystem.EditorActionManager;
+import com.intellij.openapi.editor.colors.EditorColors;
 import com.intellij.openapi.editor.impl.DocumentImpl;
 import com.intellij.openapi.editor.markup.HighlighterLayer;
 import com.intellij.openapi.editor.markup.HighlighterTargetArea;
@@ -12,6 +14,7 @@ import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.xmlb.annotations.Transient;
 import com.jetbrains.python.edu.StudyUtils;
+import com.jetbrains.python.edu.TaskWindowDeleteHandler;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -101,6 +104,11 @@ public class TaskFile implements Stateful {
     for (TaskWindow taskWindow : taskWindows) {
       taskWindow.draw(editor, false, false);
     }
+    final Document document = editor.getDocument();
+    EditorActionManager.getInstance()
+      .setReadonlyFragmentModificationHandler(document, new TaskWindowDeleteHandler(editor));
+    createGuardedBlocks(document, editor);
+    editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
   }
 
   /**