extracted answer placeholder painting
authorEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Sat, 14 Feb 2015 14:51:48 +0000 (17:51 +0300)
committerEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Sat, 14 Feb 2015 14:51:48 +0000 (17:51 +0300)
22 files changed:
python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCAnswerPlaceholderPainter.java [deleted file]
python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCEditorFactoryListener.java
python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCProjectService.java
python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCAddAnswerPlaceholder.java
python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCDeleteTaskWindow.java
python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCShowPreview.java
python/educational/educational.iml
python/educational/interactive-learning/src/com/jetbrains/edu/learning/StudyProjectComponent.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/StudyUtils.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyCheckAction.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyEditInputAction.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyRefreshTaskFileAction.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyTaskNavigationAction.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/courseGeneration/StudyGenerator.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/editor/StudyEditorFactoryListener.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/projectView/StudyDirectoryNode.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/projectView/StudyTreeStructureProvider.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudySmartChecker.java
python/educational/src/com/jetbrains/edu/EduAnswerPlaceholderPainter.java [moved from python/educational/interactive-learning/src/com/jetbrains/edu/learning/StudyAnswerPlaceholderPainter.java with 57% similarity]
python/educational/src/com/jetbrains/edu/EduNames.java [moved from python/educational/src/com/jetbrains/edu/StudyNames.java with 96% similarity]
python/educational/src/com/jetbrains/edu/EduTaskWindowDeleteHandler.java [moved from python/educational/interactive-learning/src/com/jetbrains/edu/learning/TaskWindowDeleteHandler.java with 74% similarity]
python/educational/src/com/jetbrains/edu/courseFormat/Task.java

diff --git a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCAnswerPlaceholderPainter.java b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCAnswerPlaceholderPainter.java
deleted file mode 100644 (file)
index 9b2d236..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-package com.jetbrains.edu.coursecreator;
-
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.RangeMarker;
-import com.intellij.openapi.editor.colors.EditorColorsManager;
-import com.intellij.openapi.editor.colors.EditorColorsScheme;
-import com.intellij.openapi.editor.impl.DocumentImpl;
-import com.intellij.openapi.editor.markup.*;
-import com.intellij.openapi.project.Project;
-import com.intellij.ui.JBColor;
-import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
-import com.jetbrains.edu.courseFormat.TaskFile;
-import org.jetbrains.annotations.NotNull;
-
-import java.awt.*;
-import java.util.List;
-
-public class CCAnswerPlaceholderPainter {
-  private CCAnswerPlaceholderPainter() {
-
-  }
-
-  public static void drawHighlighter(@NotNull final AnswerPlaceholder placeholder, @NotNull final Editor editor, boolean useLength) {
-    drawAnswerPlaceholder(editor, placeholder, useLength, JBColor.BLUE);
-    //int startOffset = placeholder.getRealStartOffset(editor.getDocument());
-    //final int length = placeholder.getLength();
-    //final int replacementLength = placeholder.getPossibleAnswer().length();
-    //int highlighterLength = useLength ? length : replacementLength;
-    //int endOffset = startOffset + highlighterLength;
-    //TextAttributes defaultTestAttributes =
-    //  EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.LIVE_TEMPLATE_ATTRIBUTES);
-    //defaultTestAttributes.setEffectColor(JBColor.BLUE);
-    //RangeHighlighter highlighter =
-    //  editor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, HighlighterLayer.LAST + 1, defaultTestAttributes,
-    //                                              HighlighterTargetArea.EXACT_RANGE);
-    //highlighter.setGreedyToLeft(true);
-    //highlighter.setGreedyToRight(true);
-  }
-
-
-
-  public static void drawAnswerPlaceholder(@NotNull final Editor editor, @NotNull final AnswerPlaceholder placeholder, boolean useLength,
-                                           @NotNull final JBColor color) {
-    Document document = editor.getDocument();
-    if (useLength && !placeholder.isValid(document)) {
-      return;
-    }
-    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
-    final TextAttributes defaultTestAttributes = new TextAttributes(scheme.getDefaultForeground(), scheme.getDefaultBackground(), null,
-                                                                    EffectType.BOXED, Font.PLAIN);
-    final Project project = editor.getProject();
-    assert project != null;
-    int startOffset = placeholder.getRealStartOffset(document);
-    final int length = placeholder.getLength();
-    final int replacementLength = placeholder.getPossibleAnswerLength();
-    int highlighterLength = useLength ? length : replacementLength;
-    int endOffset = startOffset + highlighterLength;
-    RangeHighlighter
-      highlighter = editor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, HighlighterLayer.LAST + 1,
-                                                                defaultTestAttributes, HighlighterTargetArea.EXACT_RANGE);
-    highlighter.setCustomRenderer(new CustomHighlighterRenderer() {
-      @Override
-      public void paint(@NotNull Editor editor, @NotNull RangeHighlighter highlighter, @NotNull Graphics g) {
-        g.setColor(color);
-        Point point = editor.logicalPositionToXY(editor.offsetToLogicalPosition(highlighter.getStartOffset()));
-        Point pointEnd = editor.logicalPositionToXY(editor.offsetToLogicalPosition(highlighter.getEndOffset()));
-        g.drawRect(point.x, point.y - 2, (pointEnd.x - point.x), editor.getLineHeight() + 1);
-      }
-    });
-    editor.getCaretModel().moveToOffset(startOffset);
-    highlighter.setGreedyToLeft(true);
-    highlighter.setGreedyToRight(true);
-  }
-
-  /*
-  public static void drawAnswerPlaceholder(@NotNull final Editor editor, AnswerPlaceholder answerPlaceholder) {
-    Document document = editor.getDocument();
-    if (!answerPlaceholder.isValid(document)) {
-      return;
-    }
-    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
-    final TextAttributes defaultTestAttributes = new TextAttributes(scheme.getDefaultForeground(), scheme.getDefaultBackground(), null,
-                                                                    EffectType.BOXED, Font.PLAIN);
-    final Project project = editor.getProject();
-    assert project != null;
-    final JBColor color = StudyTaskManager.getInstance(project).getColor(answerPlaceholder);
-    int startOffset = answerPlaceholder.getRealStartOffset(document);
-    RangeHighlighter
-      highlighter = editor.getMarkupModel().addRangeHighlighter(startOffset, startOffset + answerPlaceholder.getLength(), HighlighterLayer.LAST + 1,
-                                                                defaultTestAttributes, HighlighterTargetArea.EXACT_RANGE);
-    highlighter.setCustomRenderer(new CustomHighlighterRenderer() {
-      @Override
-      public void paint(@NotNull Editor editor, @NotNull RangeHighlighter highlighter, @NotNull Graphics g) {
-        g.setColor(color);
-        Point point = editor.logicalPositionToXY(editor.offsetToLogicalPosition(highlighter.getStartOffset()));
-        Point pointEnd = editor.logicalPositionToXY(editor.offsetToLogicalPosition(highlighter.getEndOffset()));
-        g.drawRect(point.x, point.y - 2, (pointEnd.x - point.x), editor.getLineHeight() + 1);
-      }
-    });
-    editor.getCaretModel().moveToOffset(startOffset);
-    highlighter.setGreedyToLeft(true);
-    highlighter.setGreedyToRight(true);
-  }
-
-/*
-  public static void drawAllWindows(Editor editor, TaskFile taskFile) {
-    editor.getMarkupModel().removeAllHighlighters();
-    for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
-      drawAnswerPlaceholder(editor, answerPlaceholder);
-    }
-    final Document document = editor.getDocument();
-    EditorActionManager.getInstance()
-      .setReadonlyFragmentModificationHandler(document, new TaskWindowDeleteHandler(editor));
-    createGuardedBlocks(editor, taskFile);
-    editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
-  }
-
-
-  *//**
-   * Marks symbols adjacent to task windows as read-only fragments
-   *//*
-  public static void createGuardedBlocks(@NotNull final Editor editor, TaskFile taskFile) {
-    final Document document = editor.getDocument();
-    if (document instanceof DocumentImpl) {
-      DocumentImpl documentImpl = (DocumentImpl)document;
-      List<RangeMarker> blocks = documentImpl.getGuardedBlocks();
-      for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
-        if (!answerPlaceholder.isValid(document)) {
-          return;
-        }
-        int start = answerPlaceholder.getRealStartOffset(document);
-        int end = start + answerPlaceholder.getLength();
-        if (start != 0) {
-          createGuardedBlock(editor, blocks, start - 1, start);
-        }
-        if (end != document.getTextLength()) {
-          createGuardedBlock(editor, blocks, end, end + 1);
-        }
-      }
-    }
-  }
-*/
-
-  public static void createGuardedBlock(Editor editor, List<RangeMarker> blocks, int start, int end) {
-    RangeHighlighter rh = editor.getMarkupModel()
-      .addRangeHighlighter(start, end, HighlighterLayer.LAST + 1, null, HighlighterTargetArea.EXACT_RANGE);
-    blocks.add(rh);
-  }
-
-
-  public static void createGuardedBlocks(@NotNull final Editor editor, TaskFile taskFile) {
-    for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
-      createGuardedBlocks(editor, answerPlaceholder);
-    }
-  }
-
-  public static void createGuardedBlocks(@NotNull final Editor editor, AnswerPlaceholder placeholder) {
-    Document document = editor.getDocument();
-    if (document instanceof DocumentImpl) {
-      DocumentImpl documentImpl = (DocumentImpl)document;
-      java.util.List<RangeMarker> blocks = documentImpl.getGuardedBlocks();
-      int start = placeholder.getRealStartOffset(document);
-      int end = start + placeholder.getPossibleAnswer().length();
-      if (start != 0) {
-        createGuardedBlock(editor, blocks, start - 1, start);
-      }
-      if (end != document.getTextLength()) {
-        createGuardedBlock(editor, blocks, end, end + 1);
-      }
-    }
-  }
-
-}
index eb9445ab289627380238489d16125420f1d3f857..26a8a9749f0dec66aa54262237de7b716161957e 100644 (file)
@@ -1,17 +1,16 @@
 package com.jetbrains.edu.coursecreator;
 
-import com.intellij.codeInsight.hint.HintManager;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
-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.fileEditor.FileDocumentManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.jetbrains.edu.EduAnswerPlaceholderPainter;
+import com.jetbrains.edu.EduTaskWindowDeleteHandler;
 import com.jetbrains.edu.courseFormat.Course;
 import com.jetbrains.edu.courseFormat.TaskFile;
 import org.jetbrains.annotations.NotNull;
@@ -47,10 +46,10 @@ public class CCEditorFactoryListener implements EditorFactoryListener {
     CCProjectService.addDocumentListener(editor.getDocument(), listener);
     editor.getDocument().addDocumentListener(listener);
     EditorActionManager.getInstance()
-      .setReadonlyFragmentModificationHandler(editor.getDocument(), new TaskWindowDeleteHandler(editor));
+      .setReadonlyFragmentModificationHandler(editor.getDocument(), new EduTaskWindowDeleteHandler(editor));
     service.drawTaskWindows(virtualFile, editor);
     editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
-    CCAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile);
+    EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile, false);
   }
 
   @Override
@@ -78,17 +77,4 @@ public class CCEditorFactoryListener implements EditorFactoryListener {
     }
   }
 
-  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, "Delete answer placeholder before editing its borders");
-    }
-  }
 }
index 2d950285b832bf22228d8fdb7d83a3b70f74a56f..38efb39339162616b647c949ef8a387493c6b1a5 100644 (file)
@@ -30,7 +30,9 @@ import com.intellij.openapi.util.io.FileUtilRt;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.psi.PsiDirectory;
+import com.intellij.ui.JBColor;
 import com.intellij.util.xmlb.XmlSerializerUtil;
+import com.jetbrains.edu.EduAnswerPlaceholderPainter;
 import com.jetbrains.edu.courseFormat.*;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -136,7 +138,7 @@ public class CCProjectService implements PersistentStateComponent<CCProjectServi
     }
     List<AnswerPlaceholder> answerPlaceholders = taskFile.getAnswerPlaceholders();
     for (AnswerPlaceholder answerPlaceholder : answerPlaceholders) {
-      CCAnswerPlaceholderPainter.drawHighlighter(answerPlaceholder, editor, false);
+      EduAnswerPlaceholderPainter.drawAnswerPlaceholder(editor, answerPlaceholder, false, JBColor.BLUE);
     }
   }
 
index 92f5a9574233e9eedd9efa1b2c469cbb42ea4430..f06bdf9ce0437d6acc437a53134689c7fe608d2c 100644 (file)
@@ -13,11 +13,12 @@ import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.psi.PsiDirectory;
 import com.intellij.psi.PsiDocumentManager;
 import com.intellij.psi.PsiFile;
+import com.intellij.ui.JBColor;
+import com.jetbrains.edu.EduAnswerPlaceholderPainter;
 import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.courseFormat.Lesson;
 import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
-import com.jetbrains.edu.coursecreator.CCAnswerPlaceholderPainter;
 import com.jetbrains.edu.coursecreator.CCProjectService;
 import com.jetbrains.edu.coursecreator.ui.CreateTaskWindowDialog;
 import org.jetbrains.annotations.NotNull;
@@ -93,8 +94,8 @@ public class CCAddAnswerPlaceholder extends DumbAwareAction {
     answerPlaceholder.setIndex(index);
     taskFile.addAnswerPlaceholder(answerPlaceholder);
     taskFile.sortAnswerPlaceholders();
-    CCAnswerPlaceholderPainter.drawHighlighter(answerPlaceholder, editor, false);
-    CCAnswerPlaceholderPainter.createGuardedBlocks(editor, answerPlaceholder);
+    EduAnswerPlaceholderPainter.drawAnswerPlaceholder(editor, answerPlaceholder, false, JBColor.BLUE);
+    EduAnswerPlaceholderPainter.createGuardedBlocks(editor, answerPlaceholder, false);
   }
 
   @Override
index b5ca452f53a14e34c7b79ee200d05c766968cbe7..e111a3feb973bbd2d704a5808849772400f0b25a 100644 (file)
@@ -5,9 +5,9 @@ import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.project.Project;
 import com.intellij.psi.PsiDocumentManager;
 import com.intellij.psi.PsiFile;
+import com.jetbrains.edu.EduAnswerPlaceholderPainter;
 import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.courseFormat.TaskFile;
-import com.jetbrains.edu.coursecreator.CCAnswerPlaceholderPainter;
 import com.jetbrains.edu.coursecreator.CCProjectService;
 import org.jetbrains.annotations.NotNull;
 
@@ -33,7 +33,7 @@ public class CCDeleteTaskWindow extends CCTaskWindowAction {
       final Editor editor = state.getEditor();
       editor.getMarkupModel().removeAllHighlighters();
       CCProjectService.getInstance(project).drawTaskWindows(psiFile.getVirtualFile(), editor);
-      CCAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile);
+      EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile, false);
     }
   }
 }
\ No newline at end of file
index d61cbcb99f0a3761208bcb5ce4c84185e354a2ff..3e02774ad20e66d95f952c2c769c2f8e2b0fd67b 100644 (file)
@@ -33,11 +33,12 @@ import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiDirectory;
 import com.intellij.psi.PsiFile;
+import com.intellij.ui.JBColor;
+import com.jetbrains.edu.EduAnswerPlaceholderPainter;
 import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.courseFormat.Course;
 import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
-import com.jetbrains.edu.coursecreator.CCAnswerPlaceholderPainter;
 import com.jetbrains.edu.coursecreator.CCProjectService;
 import org.jetbrains.annotations.NotNull;
 
@@ -133,7 +134,7 @@ public class CCShowPreview extends DumbAwareAction {
       }
     });
     for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
-      CCAnswerPlaceholderPainter.drawHighlighter(answerPlaceholder, createdEditor, true);
+      EduAnswerPlaceholderPainter.drawAnswerPlaceholder(createdEditor, answerPlaceholder, true, JBColor.BLUE);
     }
     JPanel header = new JPanel();
     header.setLayout(new BoxLayout(header, BoxLayout.Y_AXIS));
index 1bf31625ebef723143eb552dbd286801486a3476..26c92e0b314bf292691520f90a069c0bdd0cc196 100644 (file)
@@ -9,5 +9,6 @@
     <orderEntry type="sourceFolder" forTests="false" />
     <orderEntry type="module" module-name="platform-api" />
     <orderEntry type="library" name="gson" level="project" />
+    <orderEntry type="module" module-name="core-impl" />
   </component>
 </module>
\ No newline at end of file
index 029bb23b1351744a85ee00468553d1c85d5c615a..5c83f0c7de74fa41a989c179327121ccfc419662 100644 (file)
@@ -25,7 +25,7 @@ import com.intellij.openapi.vfs.VirtualFileAdapter;
 import com.intellij.openapi.vfs.VirtualFileEvent;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.openapi.wm.*;
-import com.jetbrains.edu.StudyNames;
+import com.jetbrains.edu.EduNames;
 import com.jetbrains.edu.courseFormat.Course;
 import com.jetbrains.edu.courseFormat.Lesson;
 import com.jetbrains.edu.courseFormat.Task;
@@ -171,14 +171,14 @@ public class StudyProjectComponent implements ProjectComponent {
       if (file.getName().equals(testHelper)) {
         copyFile(file, new File(myProject.getBasePath(), testHelper));
       }
-      if (file.getName().startsWith(StudyNames.LESSON)) {
+      if (file.getName().startsWith(EduNames.LESSON)) {
         final File[] tasks = file.listFiles();
         if (tasks == null) continue;
         for (File task : tasks) {
-          final File taskDescr = new File(task, StudyNames.TASK_HTML);
+          final File taskDescr = new File(task, EduNames.TASK_HTML);
           String testFileName = manager.getTestFileName();
           final File taskTests = new File(task, testFileName);
-          copyFile(taskDescr, new File(new File(new File(myProject.getBasePath(), file.getName()), task.getName()), StudyNames.TASK_HTML));
+          copyFile(taskDescr, new File(new File(new File(myProject.getBasePath(), file.getName()), task.getName()), EduNames.TASK_HTML));
           copyFile(taskTests, new File(new File(new File(myProject.getBasePath(), file.getName()), task.getName()),
                                        testFileName));
         }
@@ -287,11 +287,11 @@ public class StudyProjectComponent implements ProjectComponent {
       final VirtualFile createdFile = event.getFile();
       final VirtualFile taskDir = createdFile.getParent();
       final Course course = StudyTaskManager.getInstance(myProject).getCourse();
-      if (taskDir != null && taskDir.getName().contains(StudyNames.TASK_DIR)) {
-        int taskIndex = StudyUtils.getIndex(taskDir.getName(), StudyNames.TASK_DIR);
+      if (taskDir != null && taskDir.getName().contains(EduNames.TASK_DIR)) {
+        int taskIndex = StudyUtils.getIndex(taskDir.getName(), EduNames.TASK_DIR);
         final VirtualFile lessonDir = taskDir.getParent();
-        if (lessonDir != null && lessonDir.getName().contains(StudyNames.LESSON_DIR)) {
-          int lessonIndex = StudyUtils.getIndex(lessonDir.getName(), StudyNames.LESSON_DIR);
+        if (lessonDir != null && lessonDir.getName().contains(EduNames.LESSON_DIR)) {
+          int lessonIndex = StudyUtils.getIndex(lessonDir.getName(), EduNames.LESSON_DIR);
           if (course != null) {
             List<Lesson> lessons = course.getLessons();
             if (StudyUtils.indexIsValid(lessonIndex, lessons)) {
index e3dbd4df606439b41a45cedd95a73b10e34cc256..ae77498c7a8a299cc1d386fc5ec73bf26c09b769 100644 (file)
@@ -11,6 +11,9 @@ import com.intellij.openapi.actionSystem.Presentation;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.editor.actionSystem.EditorActionManager;
+import com.intellij.openapi.editor.colors.EditorColors;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.fileEditor.FileEditor;
 import com.intellij.openapi.fileEditor.FileEditorManager;
@@ -28,8 +31,11 @@ import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.openapi.wm.ToolWindowManager;
+import com.intellij.ui.JBColor;
 import com.intellij.util.ui.UIUtil;
-import com.jetbrains.edu.StudyNames;
+import com.jetbrains.edu.EduAnswerPlaceholderPainter;
+import com.jetbrains.edu.EduNames;
+import com.jetbrains.edu.EduTaskWindowDeleteHandler;
 import com.jetbrains.edu.courseFormat.*;
 import com.jetbrains.edu.learning.editor.StudyEditor;
 import com.jetbrains.edu.learning.run.StudyExecutor;
@@ -201,7 +207,7 @@ public class StudyUtils {
     int taskNum = task.getIndex() + 1;
     int lessonNum = task.getLesson().getIndex() + 1;
     assert course != null;
-    final String pathToResource = FileUtil.join(course.getCourseDirectory(), StudyNames.LESSON_DIR + lessonNum, StudyNames.TASK_DIR + taskNum);
+    final String pathToResource = FileUtil.join(course.getCourseDirectory(), EduNames.LESSON_DIR + lessonNum, EduNames.TASK_DIR + taskNum);
     final File resourceFile = new File(pathToResource, copyName);
     FileUtil.copy(new File(pathToResource, sourceName), resourceFile);
     return resourceFile;
@@ -299,16 +305,16 @@ public class StudyUtils {
       return null;
     }
     final String taskDirName = taskDir.getName();
-    if (taskDirName.contains(StudyNames.TASK_DIR)) {
+    if (taskDirName.contains(EduNames.TASK_DIR)) {
       final VirtualFile lessonDir = taskDir.getParent();
       if (lessonDir != null) {
-        int lessonIndex = getIndex(lessonDir.getName(), StudyNames.LESSON_DIR);
+        int lessonIndex = getIndex(lessonDir.getName(), EduNames.LESSON_DIR);
         List<Lesson> lessons = course.getLessons();
         if (!indexIsValid(lessonIndex, lessons)) {
           return null;
         }
         final Lesson lesson = lessons.get(lessonIndex);
-        int taskIndex = getIndex(taskDirName, StudyNames.TASK_DIR);
+        int taskIndex = getIndex(taskDirName, EduNames.TASK_DIR);
         final List<Task> tasks = lesson.getTaskList();
         if (!indexIsValid(taskIndex, tasks)) {
           return null;
@@ -319,4 +325,22 @@ public class StudyUtils {
     }
     return null;
   }
+
+
+  public static void drawAllWindows(Editor editor, TaskFile taskFile) {
+    editor.getMarkupModel().removeAllHighlighters();
+    final Project project = editor.getProject();
+    if (project == null) return;
+    final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
+    for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
+      final JBColor color = taskManager.getColor(answerPlaceholder);
+      EduAnswerPlaceholderPainter.drawAnswerPlaceholder(editor, answerPlaceholder, true, color);
+    }
+    final Document document = editor.getDocument();
+    EditorActionManager.getInstance()
+      .setReadonlyFragmentModificationHandler(document, new EduTaskWindowDeleteHandler(editor));
+    EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile, true);
+    editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
+  }
+
 }
index 0c96b37f658309e3e80f4158bd420b7d8bb6f5d6..912f65387b62456387965f969678a5b17b555b12 100644 (file)
@@ -33,7 +33,10 @@ import com.intellij.openapi.wm.ex.WindowManagerEx;
 import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
-import com.jetbrains.edu.learning.*;
+import com.jetbrains.edu.learning.StudyDocumentListener;
+import com.jetbrains.edu.learning.StudyState;
+import com.jetbrains.edu.learning.StudyTaskManager;
+import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.courseFormat.StudyStatus;
 import com.jetbrains.edu.learning.editor.StudyEditor;
 import com.jetbrains.edu.learning.navigation.StudyNavigator;
@@ -98,7 +101,7 @@ public class StudyCheckAction extends DumbAwareAction {
       FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
       if (fileEditor instanceof StudyEditor) {
         StudyEditor studyEditor = (StudyEditor)fileEditor;
-        StudyAnswerPlaceholderPainter.drawAllWindows(studyEditor.getEditor(), taskFile);
+        StudyUtils.drawAllWindows(studyEditor.getEditor(), taskFile);
       }
     }
   }
index 69438bc149d7665a01c455a3e7bf41d47b725931..26c136b480058207da1708188821c7a91505f8d1 100644 (file)
@@ -20,7 +20,7 @@ import com.intellij.ui.tabs.TabInfo;
 import com.intellij.ui.tabs.TabsListener;
 import com.intellij.ui.tabs.impl.JBEditorTabs;
 import com.intellij.util.PlatformIcons;
-import com.jetbrains.edu.StudyNames;
+import com.jetbrains.edu.EduNames;
 import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.StudyTaskManager;
@@ -62,7 +62,7 @@ public class StudyEditInputAction extends DumbAwareAction {
           if (newSelection.getIcon() != null) {
             int tabCount = tabbedPane.getTabCount();
             VirtualFile taskDir = openedFile.getParent();
-            VirtualFile testsDir = taskDir.findChild(StudyNames.USER_TESTS);
+            VirtualFile testsDir = taskDir.findChild(EduNames.USER_TESTS);
             assert testsDir != null;
             UserTest userTest = createUserTest(testsDir, currentTask, studyTaskManager);
             userTest.setEditable(true);
@@ -129,9 +129,9 @@ public class StudyEditInputAction extends DumbAwareAction {
     UserTest userTest = new UserTest();
     List<UserTest> userTests = studyTaskManager.getUserTests(currentTask);
     int testNum = userTests.size() + 1;
-    String inputName = StudyNames.USER_TEST_INPUT + testNum;
+    String inputName = EduNames.USER_TEST_INPUT + testNum;
     File inputFile = new File(testsDir.getPath(), inputName);
-    String outputName = StudyNames.USER_TEST_OUTPUT + testNum;
+    String outputName = EduNames.USER_TEST_OUTPUT + testNum;
     File outputFile = new File(testsDir.getPath(), outputName);
     userTest.setInput(inputFile.getPath());
     userTest.setOutput(outputFile.getPath());
@@ -141,7 +141,7 @@ public class StudyEditInputAction extends DumbAwareAction {
 
   private TabInfo addTestTab(int nameIndex, final StudyTestContentPanel contentPanel, @NotNull final Task currentTask, boolean toBeClosable) {
     TabInfo testTab = toBeClosable ? createClosableTab(contentPanel, currentTask) : new TabInfo(contentPanel);
-    return testTab.setText(StudyNames.TEST_TAB_NAME + String.valueOf(nameIndex));
+    return testTab.setText(EduNames.TEST_TAB_NAME + String.valueOf(nameIndex));
   }
 
   private TabInfo createClosableTab(StudyTestContentPanel contentPanel, Task currentTask) {
index fdcd8bc666ad978cb50960c0a3512005a30dd7f4..249be6706e65c78fd6ccd0a09de3c01da9ecab26 100644 (file)
@@ -20,12 +20,12 @@ import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.wm.IdeFocusManager;
 import com.intellij.problems.WolfTheProblemSolver;
-import com.jetbrains.edu.StudyNames;
+import com.jetbrains.edu.EduAnswerPlaceholderPainter;
+import com.jetbrains.edu.EduNames;
 import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.courseFormat.Course;
 import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
-import com.jetbrains.edu.learning.StudyAnswerPlaceholderPainter;
 import com.jetbrains.edu.learning.StudyState;
 import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
@@ -70,8 +70,8 @@ public class StudyRefreshTaskFileAction extends DumbAwareAction {
     }
     WolfTheProblemSolver.getInstance(project).clearProblems(studyState.getVirtualFile());
     taskFile.setHighlightErrors(false);
-    StudyAnswerPlaceholderPainter.drawAllWindows(editor, taskFile);
-    StudyAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile);
+    StudyUtils.drawAllWindows(editor, taskFile);
+    EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile, true);
     ApplicationManager.getApplication().invokeLater(new Runnable() {
       @Override
       public void run() {
@@ -123,8 +123,8 @@ public class StudyRefreshTaskFileAction extends DumbAwareAction {
     taskFile.setTrackChanges(false);
     clearDocument(document);
     Task task = taskFile.getTask();
-    String lessonDir = StudyNames.LESSON_DIR + String.valueOf(task.getLesson().getIndex() + 1);
-    String taskDir = StudyNames.TASK_DIR + String.valueOf(task.getIndex() + 1);
+    String lessonDir = EduNames.LESSON_DIR + String.valueOf(task.getLesson().getIndex() + 1);
+    String taskDir = EduNames.TASK_DIR + String.valueOf(task.getIndex() + 1);
     Course course = task.getLesson().getCourse();
     File resourceFile = new File(course.getCourseDirectory());
     if (!resourceFile.exists()) {
index 3fc949b366fa01c8d6bdc879352e84dd5fe6f553..82a2a187999e288b2a600467c76489ee87bd0ec7 100644 (file)
@@ -14,7 +14,7 @@ import com.intellij.openapi.wm.ToolWindow;
 import com.intellij.openapi.wm.ToolWindowId;
 import com.intellij.openapi.wm.ToolWindowManager;
 import com.intellij.util.ui.tree.TreeUtil;
-import com.jetbrains.edu.StudyNames;
+import com.jetbrains.edu.EduNames;
 import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.StudyState;
@@ -52,7 +52,7 @@ abstract public class StudyTaskNavigationAction extends DumbAwareAction {
       return;
     }
     VirtualFile projectDir = project.getBaseDir();
-    String lessonDirName = StudyNames.LESSON_DIR + String.valueOf(lessonIndex + 1);
+    String lessonDirName = EduNames.LESSON_DIR + String.valueOf(lessonIndex + 1);
     if (projectDir == null) {
       return;
     }
@@ -60,7 +60,7 @@ abstract public class StudyTaskNavigationAction extends DumbAwareAction {
     if (lessonDir == null) {
       return;
     }
-    String taskDirName = StudyNames.TASK_DIR + String.valueOf(nextTaskIndex + 1);
+    String taskDirName = EduNames.TASK_DIR + String.valueOf(nextTaskIndex + 1);
     VirtualFile taskDir = lessonDir.findChild(taskDirName);
     if (taskDir == null) {
       return;
index 5601bd00c3c15612e774c36af844784760ae9869..14837f9f82d58fdbb5762e593ab76623948c035d 100644 (file)
@@ -4,7 +4,7 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VirtualFile;
-import com.jetbrains.edu.StudyNames;
+import com.jetbrains.edu.EduNames;
 import com.jetbrains.edu.courseFormat.*;
 import com.jetbrains.edu.learning.StudyUtils;
 import org.jetbrains.annotations.NotNull;
@@ -50,7 +50,7 @@ public class StudyGenerator {
    */
   public static void createTask(@NotNull final Task task, @NotNull final VirtualFile lessonDir, @NotNull final File resourceRoot,
                                 @NotNull final Project project) throws IOException {
-    VirtualFile taskDir = lessonDir.createChildDirectory(project, StudyNames.TASK_DIR + Integer.toString(task.getIndex() + 1));
+    VirtualFile taskDir = lessonDir.createChildDirectory(project, EduNames.TASK_DIR + Integer.toString(task.getIndex() + 1));
     StudyUtils.markDirAsSourceRoot(taskDir, project);
     File newResourceRoot = new File(resourceRoot, taskDir.getName());
     int i = 0;
@@ -82,7 +82,7 @@ public class StudyGenerator {
    */
   public static void createLesson(@NotNull final Lesson lesson, @NotNull final VirtualFile courseDir, @NotNull final File resourceRoot,
                                   @NotNull final Project project) throws IOException {
-    String lessonDirName = StudyNames.LESSON_DIR + Integer.toString(lesson.getIndex() + 1);
+    String lessonDirName = EduNames.LESSON_DIR + Integer.toString(lesson.getIndex() + 1);
     VirtualFile lessonDir = courseDir.createChildDirectory(project, lessonDirName);
     final List<Task> taskList = lesson.getTaskList();
     for (int i = 0; i < taskList.size(); i++) {
@@ -108,11 +108,11 @@ public class StudyGenerator {
                   lesson.setIndex(i);
                   createLesson(lesson, baseDir, resourceRoot, project);
                 }
-                baseDir.createChildDirectory(project, StudyNames.SANDBOX_DIR);
+                baseDir.createChildDirectory(project, EduNames.SANDBOX_DIR);
                 File[] files = resourceRoot.listFiles(new FilenameFilter() {
                   @Override
                   public boolean accept(File dir, String name) {
-                    return !name.contains(StudyNames.LESSON_DIR) && !name.equals("course.json") && !name.equals("hints");
+                    return !name.contains(EduNames.LESSON_DIR) && !name.equals("course.json") && !name.equals("hints");
                   }
                 });
                 for (File file : files) {
index 65f568d7da5ea87608a237293b331b7c8b149fdf..cc9952c37616a3ff19cb7d261771d0c2fe333d68 100644 (file)
@@ -13,10 +13,12 @@ import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.problems.WolfTheProblemSolver;
+import com.intellij.ui.JBColor;
+import com.jetbrains.edu.EduAnswerPlaceholderPainter;
 import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.courseFormat.TaskFile;
-import com.jetbrains.edu.learning.StudyAnswerPlaceholderPainter;
 import com.jetbrains.edu.learning.StudyDocumentListener;
+import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.navigation.StudyNavigator;
 import org.jetbrains.annotations.NotNull;
@@ -44,10 +46,13 @@ public class StudyEditorFactoryListener implements EditorFactoryListener {
       final AnswerPlaceholder answerPlaceholder = myTaskFile.getAnswerPlaceholder(editor.getDocument(), pos);
       if (answerPlaceholder != null) {
         myTaskFile.setSelectedAnswerPlaceholder(answerPlaceholder);
-        StudyAnswerPlaceholderPainter.drawAnswerPlaceholder(editor, answerPlaceholder);
+        final Project project = editor.getProject();
+        assert project != null;
+        final JBColor color = StudyTaskManager.getInstance(project).getColor(answerPlaceholder);
+        EduAnswerPlaceholderPainter.drawAnswerPlaceholder(editor, answerPlaceholder, true, color);
       }
       else {
-        StudyAnswerPlaceholderPainter.drawAllWindows(editor, myTaskFile);
+        StudyUtils.drawAllWindows(editor, myTaskFile);
       }
     }
   }
@@ -76,7 +81,7 @@ public class StudyEditorFactoryListener implements EditorFactoryListener {
                   editor.addEditorMouseListener(new WindowSelectionListener(taskFile));
                   StudyEditor.addDocumentListener(document, new StudyDocumentListener(taskFile));
                   WolfTheProblemSolver.getInstance(project).clearProblems(openedFile);
-                  StudyAnswerPlaceholderPainter.drawAllWindows(editor, taskFile);
+                  StudyUtils.drawAllWindows(editor, taskFile);
                 }
               }
             }
index b4c9992bc79bc6c261adcd0bcdee02db88a32934..6b777bfefa9b5fd91bcaf46ec423b739d34da37d 100644 (file)
@@ -11,7 +11,7 @@ import com.intellij.psi.PsiDirectory;
 import com.intellij.psi.PsiElement;
 import com.intellij.ui.JBColor;
 import com.intellij.ui.SimpleTextAttributes;
-import com.jetbrains.edu.StudyNames;
+import com.jetbrains.edu.EduNames;
 import com.jetbrains.edu.courseFormat.Course;
 import com.jetbrains.edu.courseFormat.Lesson;
 import com.jetbrains.edu.courseFormat.Task;
@@ -53,7 +53,7 @@ public class StudyDirectoryNode extends PsiDirectoryNode {
       data.addText(" (" + valueName + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
       return;
     }
-    if (valueName.contains(StudyNames.TASK_DIR)) {
+    if (valueName.contains(EduNames.TASK_DIR)) {
       TaskFile file = null;
       for (PsiElement child : myValue.getChildren()) {
         VirtualFile virtualFile = child.getContainingFile().getVirtualFile();
@@ -67,16 +67,16 @@ public class StudyDirectoryNode extends PsiDirectoryNode {
         setStudyAttributes(task, data, task.getName());
       }
     }
-    if (valueName.contains(StudyNames.LESSON_DIR)) {
-      int lessonIndex = Integer.parseInt(valueName.substring(StudyNames.LESSON_DIR.length())) - 1;
+    if (valueName.contains(EduNames.LESSON_DIR)) {
+      int lessonIndex = Integer.parseInt(valueName.substring(EduNames.LESSON_DIR.length())) - 1;
       Lesson lesson = course.getLessons().get(lessonIndex);
       setStudyAttributes(lesson, data, lesson.getName());
     }
 
-    if (valueName.contains(StudyNames.SANDBOX_DIR)) {
+    if (valueName.contains(EduNames.SANDBOX_DIR)) {
       if (myValue.getParent() != null) {
-        if (!myValue.getParent().getName().contains(StudyNames.SANDBOX_DIR)) {
-          data.setPresentableText(StudyNames.SANDBOX_DIR);
+        if (!myValue.getParent().getName().contains(EduNames.SANDBOX_DIR)) {
+          data.setPresentableText(EduNames.SANDBOX_DIR);
           data.setIcon(InteractiveLearningIcons.Sandbox);
           return;
         }
@@ -88,11 +88,11 @@ public class StudyDirectoryNode extends PsiDirectoryNode {
   @Override
   public int getTypeSortWeight(boolean sortByType) {
     String name = myValue.getName();
-    if (name.contains(StudyNames.LESSON_DIR) || name.contains(StudyNames.TASK_DIR)) {
-      String logicalName = name.contains(StudyNames.LESSON_DIR) ? StudyNames.LESSON_DIR : StudyNames.TASK_DIR;
+    if (name.contains(EduNames.LESSON_DIR) || name.contains(EduNames.TASK_DIR)) {
+      String logicalName = name.contains(EduNames.LESSON_DIR) ? EduNames.LESSON_DIR : EduNames.TASK_DIR;
       return StudyUtils.getIndex(name, logicalName) + 1;
     }
-    return name.contains(StudyNames.SANDBOX_DIR) ? 0 : 3;
+    return name.contains(EduNames.SANDBOX_DIR) ? 0 : 3;
   }
 
   private void setStudyAttributes(Lesson lesson, PresentationData data, String additionalName) {
@@ -148,7 +148,7 @@ public class StudyDirectoryNode extends PsiDirectoryNode {
 
   @Override
   public void navigate(boolean requestFocus) {
-    if (myValue.getName().contains(StudyNames.TASK_DIR)) {
+    if (myValue.getName().contains(EduNames.TASK_DIR)) {
       TaskFile taskFile = null;
       VirtualFile virtualFile =  null;
       for (PsiElement child : myValue.getChildren()) {
@@ -191,7 +191,7 @@ public class StudyDirectoryNode extends PsiDirectoryNode {
 
   @Override
   public boolean expandOnDoubleClick() {
-    if (myValue.getName().contains(StudyNames.TASK_DIR)) {
+    if (myValue.getName().contains(EduNames.TASK_DIR)) {
       return false;
     }
     return super.expandOnDoubleClick();
index 246a8604edfa59d3558a5eae67df3bb784456ea2..f5198390635249945685d5b4736d601700dbfea2 100644 (file)
@@ -8,7 +8,7 @@ import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiDirectory;
-import com.jetbrains.edu.StudyNames;
+import com.jetbrains.edu.EduNames;
 import com.jetbrains.edu.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
@@ -33,7 +33,7 @@ public class StudyTreeStructureProvider implements TreeStructureProvider, DumbAw
       if (project != null) {
         if (node.getValue() instanceof PsiDirectory) {
           final PsiDirectory nodeValue = (PsiDirectory)node.getValue();
-          if (!nodeValue.getName().contains(StudyNames.USER_TESTS)) {
+          if (!nodeValue.getName().contains(EduNames.USER_TESTS)) {
             StudyDirectoryNode newNode = new StudyDirectoryNode(project, nodeValue, settings);
             nodes.add(newNode);
           }
@@ -51,7 +51,7 @@ public class StudyTreeStructureProvider implements TreeStructureProvider, DumbAw
             }
             final String parentName = parent.getName();
             if (parentName != null) {
-              if (parentName.equals(StudyNames.SANDBOX_DIR)) {
+              if (parentName.equals(EduNames.SANDBOX_DIR)) {
                 nodes.add(node);
               }
             }
index a39c7d13196e571567d494e02acd384b64bb2c17..31fa6dfd7833770326146cac6bacf38d6e0db13c 100644 (file)
@@ -10,7 +10,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.openapi.vfs.VirtualFile;
-import com.jetbrains.edu.StudyNames;
+import com.jetbrains.edu.EduNames;
 import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.StudyDocumentListener;
@@ -40,7 +40,7 @@ public class StudySmartChecker {
     try {
       final int index = placeholder.getIndex();
       final VirtualFile windowCopy =
-        answerFile.copy(project, answerFile.getParent(), answerFile.getNameWithoutExtension() + index + StudyNames.WINDOW_POSTFIX);
+        answerFile.copy(project, answerFile.getParent(), answerFile.getNameWithoutExtension() + index + EduNames.WINDOW_POSTFIX);
       final FileDocumentManager documentManager = FileDocumentManager.getInstance();
       final Document windowDocument = documentManager.getDocument(windowCopy);
       if (windowDocument != null) {
similarity index 57%
rename from python/educational/interactive-learning/src/com/jetbrains/edu/learning/StudyAnswerPlaceholderPainter.java
rename to python/educational/src/com/jetbrains/edu/EduAnswerPlaceholderPainter.java
index 5cfa40458c20e94d11d7660e4d21d04ab5b42f38..49921f2b37ebbb1988be9836fa194fa22b8f4cdc 100644 (file)
@@ -1,10 +1,8 @@
-package com.jetbrains.edu.learning;
+package com.jetbrains.edu;
 
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 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.colors.EditorColorsManager;
 import com.intellij.openapi.editor.colors.EditorColorsScheme;
 import com.intellij.openapi.editor.impl.DocumentImpl;
@@ -18,17 +16,15 @@ import org.jetbrains.annotations.NotNull;
 import java.awt.*;
 import java.util.List;
 
-public class StudyAnswerPlaceholderPainter {
-  private StudyAnswerPlaceholderPainter() {
+public class EduAnswerPlaceholderPainter {
+  private EduAnswerPlaceholderPainter() {
 
   }
 
-  /**
-   * Draw task window with color according to its status
-   */
-  public static void drawAnswerPlaceholder(@NotNull final Editor editor, AnswerPlaceholder answerPlaceholder) {
+  public static void drawAnswerPlaceholder(@NotNull final Editor editor, @NotNull final AnswerPlaceholder placeholder,
+                                           boolean useLength, @NotNull final JBColor color) {
     Document document = editor.getDocument();
-    if (!answerPlaceholder.isValid(document)) {
+    if (useLength && !placeholder.isValid(document)) {
       return;
     }
     EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
@@ -36,10 +32,13 @@ public class StudyAnswerPlaceholderPainter {
                                                                     EffectType.BOXED, Font.PLAIN);
     final Project project = editor.getProject();
     assert project != null;
-    final JBColor color = StudyTaskManager.getInstance(project).getColor(answerPlaceholder);
-    int startOffset = answerPlaceholder.getRealStartOffset(document);
+    int startOffset = placeholder.getRealStartOffset(document);
+    final int length = placeholder.getLength();
+    final int replacementLength = placeholder.getPossibleAnswerLength();
+    int highlighterLength = useLength ? length : replacementLength;
+    int endOffset = startOffset + highlighterLength;
     RangeHighlighter
-      highlighter = editor.getMarkupModel().addRangeHighlighter(startOffset, startOffset + answerPlaceholder.getLength(), HighlighterLayer.LAST + 1,
+      highlighter = editor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, HighlighterLayer.LAST + 1,
                                                                 defaultTestAttributes, HighlighterTargetArea.EXACT_RANGE);
     highlighter.setCustomRenderer(new CustomHighlighterRenderer() {
       @Override
@@ -55,49 +54,35 @@ public class StudyAnswerPlaceholderPainter {
     highlighter.setGreedyToRight(true);
   }
 
+  public static void createGuardedBlock(Editor editor, List<RangeMarker> blocks, int start, int end) {
+    RangeHighlighter rh = editor.getMarkupModel()
+      .addRangeHighlighter(start, end, HighlighterLayer.LAST + 1, null, HighlighterTargetArea.EXACT_RANGE);
+    blocks.add(rh);
+  }
 
-  public static void drawAllWindows(Editor editor, TaskFile taskFile) {
-    editor.getMarkupModel().removeAllHighlighters();
+
+  public static void createGuardedBlocks(@NotNull final Editor editor, TaskFile taskFile, boolean useLength) {
     for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
-      drawAnswerPlaceholder(editor, answerPlaceholder);
+      createGuardedBlocks(editor, answerPlaceholder, useLength);
     }
-    final Document document = editor.getDocument();
-    EditorActionManager.getInstance()
-      .setReadonlyFragmentModificationHandler(document, new TaskWindowDeleteHandler(editor));
-    createGuardedBlocks(editor, taskFile);
-    editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
   }
 
-
-  /**
-   * Marks symbols adjacent to task windows as read-only fragments
-   */
-  public static void createGuardedBlocks(@NotNull final Editor editor, TaskFile taskFile) {
-    final Document document = editor.getDocument();
+  public static void createGuardedBlocks(@NotNull final Editor editor, AnswerPlaceholder placeholder, boolean useLength) {
+    Document document = editor.getDocument();
     if (document instanceof DocumentImpl) {
       DocumentImpl documentImpl = (DocumentImpl)document;
       List<RangeMarker> blocks = documentImpl.getGuardedBlocks();
-      for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
-        if (!answerPlaceholder.isValid(document)) {
-          return;
-        }
-        int start = answerPlaceholder.getRealStartOffset(document);
-        int end = start + answerPlaceholder.getLength();
-        if (start != 0) {
-          createGuardedBlock(editor, blocks, start - 1, start);
-        }
-        if (end != document.getTextLength()) {
-          createGuardedBlock(editor, blocks, end, end + 1);
-        }
+      if (useLength && !placeholder.isValid(document)) return;
+      int start = placeholder.getRealStartOffset(document);
+      final int length = useLength ? placeholder.getLength() : placeholder.getPossibleAnswerLength();
+      int end = start + length;
+      if (start != 0) {
+        createGuardedBlock(editor, blocks, start - 1, start);
+      }
+      if (end != document.getTextLength()) {
+        createGuardedBlock(editor, blocks, end, end + 1);
       }
     }
   }
 
-  private static void createGuardedBlock(Editor editor, List<RangeMarker> blocks, int start, int end) {
-    RangeHighlighter rh = editor.getMarkupModel()
-      .addRangeHighlighter(start, end, HighlighterLayer.LAST + 1, null, HighlighterTargetArea.EXACT_RANGE);
-    blocks.add(rh);
-  }
-
-
 }
similarity index 96%
rename from python/educational/src/com/jetbrains/edu/StudyNames.java
rename to python/educational/src/com/jetbrains/edu/EduNames.java
index c725513b8696e88f1245042da4a02d5e9507b00c..765a4eb1ebde6d17cad3db82aac59e6f1de82a24 100644 (file)
@@ -18,7 +18,7 @@ package com.jetbrains.edu;
 import org.jetbrains.annotations.NonNls;
 
 @NonNls
-public class StudyNames {
+public class EduNames {
   public static final String TASK_HTML = "task.html";
   public static final String TASK_TESTS = "tests.py";
   public static final String LESSON = "lesson";
@@ -33,7 +33,7 @@ public class StudyNames {
   public static final String USER_TESTS = "userTests";
   public static final String SANDBOX_DIR = "Sandbox";
 
-  private StudyNames() {
+  private EduNames() {
   }
 
 }
similarity index 74%
rename from python/educational/interactive-learning/src/com/jetbrains/edu/learning/TaskWindowDeleteHandler.java
rename to python/educational/src/com/jetbrains/edu/EduTaskWindowDeleteHandler.java
index 3e3896d26c0c52ae9ec2b4c8e0cb1551aa3acff3..445a6fe7c8c5dfe7dde3387d07fa1aad861f6dad 100644 (file)
@@ -1,4 +1,4 @@
-package com.jetbrains.edu.learning;
+package com.jetbrains.edu;
 
 import com.intellij.codeInsight.hint.HintManager;
 import com.intellij.openapi.editor.Editor;
@@ -6,11 +6,11 @@ import com.intellij.openapi.editor.ReadOnlyFragmentModificationException;
 import com.intellij.openapi.editor.actionSystem.ReadonlyFragmentModificationHandler;
 import org.jetbrains.annotations.NotNull;
 
-public class TaskWindowDeleteHandler implements ReadonlyFragmentModificationHandler {
+public class EduTaskWindowDeleteHandler implements ReadonlyFragmentModificationHandler {
 
   private final Editor myEditor;
 
-  public TaskWindowDeleteHandler(@NotNull final Editor editor) {
+  public EduTaskWindowDeleteHandler(@NotNull final Editor editor) {
     myEditor = editor;
   }
 
index 7ba1b3e9d217ed176f5d6b08538e9d960bfd582b..7de80dc945944ca10efa4dfe66734e2cea0952e3 100644 (file)
@@ -3,7 +3,7 @@ package com.jetbrains.edu.courseFormat;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.xmlb.annotations.Transient;
-import com.jetbrains.edu.StudyNames;
+import com.jetbrains.edu.EduNames;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -97,8 +97,8 @@ public class Task {
 
   @Nullable
   public VirtualFile getTaskDir(Project project) {
-    String lessonDirName = StudyNames.LESSON_DIR + String.valueOf(myLesson.getIndex() + 1);
-    String taskDirName = StudyNames.TASK_DIR + String.valueOf(myIndex + 1);
+    String lessonDirName = EduNames.LESSON_DIR + String.valueOf(myLesson.getIndex() + 1);
+    String taskDirName = EduNames.TASK_DIR + String.valueOf(myIndex + 1);
     VirtualFile courseDir = project.getBaseDir();
     if (courseDir != null) {
       VirtualFile lessonDir = courseDir.findChild(lessonDirName);