Merge remote-tracking branch 'origin/master'
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Tue, 27 Jan 2015 13:49:04 +0000 (16:49 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Tue, 27 Jan 2015 13:49:04 +0000 (16:49 +0300)
python/educational/interactive-learning/resources/META-INF/plugin.xml
python/educational/interactive-learning/src/com/jetbrains/edu/learning/StudyDocumentListener.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/StudyEditorFactoryListener.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/StudyHighlightErrorFilter.java [new file with mode: 0644]
python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyRefreshTaskFileAction.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/course/TaskFile.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/course/TaskWindow.java

index 8374db06e8ed36b266e240e53f9bddffe3fa9aa6..75c0bc02e9425f74254217381665daf52385de02 100644 (file)
@@ -70,5 +70,6 @@
     <applicationService serviceInterface="com.intellij.openapi.fileEditor.impl.EditorEmptyTextPainter"
         serviceImplementation="com.jetbrains.edu.learning.StudyInstructionPainter" overrides="true"/>
     <errorHandler implementation="com.intellij.diagnostic.ITNReporter"/>
+    <highlightErrorFilter implementation="com.jetbrains.edu.learning.StudyHighlightErrorFilter"/>
   </extensions>
 </idea-plugin>
\ No newline at end of file
index a7a2e0debeaa111e79598f11978fcb04e3773392..0f57cf9d139fdf3492b76b8acef849a46a4ed360 100644 (file)
@@ -31,6 +31,7 @@ public class StudyDocumentListener extends DocumentAdapter {
     if (!myTaskFile.isTrackChanges()) {
       return;
     }
+    myTaskFile.setHighlightErrors(true);
     Document document = e.getDocument();
     myTaskWindows.clear();
     for (TaskWindow taskWindow : myTaskFile.getTaskWindows()) {
index 78da60815e4abb781d63ce7496438f3739e1f4f5..f7e6bface1f35d7fe4b5ee75d90aaa5e39144cbd 100644 (file)
@@ -12,6 +12,7 @@ import com.intellij.openapi.editor.event.EditorMouseEvent;
 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.jetbrains.edu.learning.course.TaskFile;
 import com.jetbrains.edu.learning.course.TaskWindow;
 import com.jetbrains.edu.learning.editor.StudyEditor;
@@ -74,6 +75,7 @@ class StudyEditorFactoryListener implements EditorFactoryListener {
                   StudyDocumentListener listener = new StudyDocumentListener(taskFile);
                   StudyEditor.addDocumentListener(document, listener);
                   document.addDocumentListener(listener);
+                  WolfTheProblemSolver.getInstance(project).clearProblems(openedFile);
                   taskFile.drawAllWindows(editor);
                 }
               }
diff --git a/python/educational/interactive-learning/src/com/jetbrains/edu/learning/StudyHighlightErrorFilter.java b/python/educational/interactive-learning/src/com/jetbrains/edu/learning/StudyHighlightErrorFilter.java
new file mode 100644 (file)
index 0000000..f1fdbf4
--- /dev/null
@@ -0,0 +1,24 @@
+package com.jetbrains.edu.learning;
+
+import com.intellij.codeInsight.highlighting.HighlightErrorFilter;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiErrorElement;
+import com.intellij.psi.PsiFile;
+import com.jetbrains.edu.learning.course.TaskFile;
+import org.jetbrains.annotations.NotNull;
+
+public class StudyHighlightErrorFilter extends HighlightErrorFilter{
+  @Override
+  public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement element) {
+    PsiFile file = element.getContainingFile();
+    if (file == null) {
+      return true;
+    }
+    VirtualFile virtualFile = file.getVirtualFile();
+    if (virtualFile == null) {
+      return true;
+    }
+    TaskFile taskFile = StudyTaskManager.getInstance(element.getProject()).getTaskFile(virtualFile);
+    return taskFile == null || taskFile.isHighlightErrors();
+  }
+}
index c2ef5ab211a557a0db32993d1c4e5a17042781f5..e58e80eb55252b5cb799f7efca57386bb700248b 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.openapi.util.io.FileUtil;
 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.learning.StudyState;
 import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.course.*;
@@ -59,6 +60,8 @@ public class StudyRefreshTaskFileAction extends DumbAwareAction {
     if (!resetTaskFile(editor.getDocument(), project, taskFile, studyState.getVirtualFile().getName())) {
       return;
     }
+    WolfTheProblemSolver.getInstance(project).clearProblems(studyState.getVirtualFile());
+    taskFile.setHighlightErrors(false);
     taskFile.drawAllWindows(editor);
     taskFile.createGuardedBlocks(editor);
     ApplicationManager.getApplication().invokeLater(new Runnable() {
index 5e835e076ac52aadcbfd9d3995f218c80f61a396..ffc2d8c6feae76633f20e3b423a2dbe928a38e73 100644 (file)
@@ -37,6 +37,7 @@ public class TaskFile implements Stateful {
   public int myIndex = -1;
   private boolean myUserCreated = false;
   private boolean myTrackChanges = true;
+  private boolean myHighlightErrors = false;
 
   /**
    * @return if all the windows in task file are marked as resolved
@@ -262,4 +263,12 @@ public class TaskFile implements Stateful {
   public void setTrackChanges(boolean trackChanges) {
     myTrackChanges = trackChanges;
   }
+
+  public boolean isHighlightErrors() {
+    return myHighlightErrors;
+  }
+
+  public void setHighlightErrors(boolean highlightErrors) {
+    myHighlightErrors = highlightErrors;
+  }
 }
index 2cd4c4ce775968bc3a0f9dc1c7ed8c0eda5733ba..83598afe865a1ecd624f3286401fda2f6f32b281 100644 (file)
@@ -7,12 +7,9 @@ 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.colors.EditorColors;
 import com.intellij.openapi.editor.colors.EditorColorsManager;
-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.editor.colors.EditorColorsScheme;
+import com.intellij.openapi.editor.markup.*;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.TextRange;
@@ -23,6 +20,7 @@ import com.jetbrains.edu.learning.StudyTestRunner;
 import com.jetbrains.edu.learning.StudyUtils;
 import org.jetbrains.annotations.NotNull;
 
+import java.awt.*;
 import java.io.File;
 import java.io.IOException;
 
@@ -91,17 +89,24 @@ public class TaskWindow implements Comparable, Stateful {
     if (!isValid(document)) {
       return;
     }
-    TextAttributes defaultTestAttributes =
-      EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.LIVE_TEMPLATE_ATTRIBUTES);
-    JBColor color = getColor();
+    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
+    final TextAttributes defaultTestAttributes = new TextAttributes(scheme.getDefaultForeground(), scheme.getDefaultBackground(), null,
+                                                                    EffectType.BOXED, Font.PLAIN);
+    final JBColor color = getColor();
     int startOffset = document.getLineStartOffset(line) + start;
     RangeHighlighter
       rh = editor.getMarkupModel().addRangeHighlighter(startOffset, startOffset + length, HighlighterLayer.LAST + 1,
-                                                       new TextAttributes(defaultTestAttributes.getForegroundColor(),
-                                                                          defaultTestAttributes.getBackgroundColor(), color,
-                                                                          defaultTestAttributes.getEffectType(),
-                                                                          defaultTestAttributes.getFontType()),
+                                                       defaultTestAttributes,
                                                        HighlighterTargetArea.EXACT_RANGE);
+    rh.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);
+      }
+    });
     if (drawSelection) {
       editor.getSelectionModel().setSelection(startOffset, startOffset + length);
     }