Add latex display support for task description panel
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Tue, 21 Jun 2016 16:14:20 +0000 (19:14 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Tue, 21 Jun 2016 16:20:39 +0000 (19:20 +0300)
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCPushLesson.java
python/educational-core/student/src/com/jetbrains/edu/learning/StudyUtils.java

index 4e3f7ecc74142171762fe6cf94c3d9e8733f591e..ee08eb530032dcaa07c032bd99bc61848f8fd6b9 100644 (file)
@@ -39,7 +39,7 @@ public class CCPushLesson extends DumbAwareAction {
       return;
     }
     final Lesson lesson = course.getLesson(lessonDir.getName());
-    if (lesson != null && lesson.id > 0) {
+    if (lesson != null && lesson.getId() > 0) {
       e.getPresentation().setEnabledAndVisible(true);
     }
   }
index d8d4276575bc83a84f00b347a39163a2df29cb8c..b85cad3d58bf154e7b20c0fe39ce3579e488cd05 100644 (file)
@@ -15,6 +15,7 @@ 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.impl.DocumentImpl;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.fileEditor.FileEditor;
@@ -24,7 +25,9 @@ import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectManager;
 import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.ui.popup.Balloon;
+import com.intellij.openapi.ui.popup.JBPopupFactory;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
@@ -76,6 +79,26 @@ public class StudyUtils {
 
   private static final Logger LOG = Logger.getInstance(StudyUtils.class.getName());
   private static final String EMPTY_TASK_TEXT = "Please, open any task to see task description";
+  private static final String ourPrefix = "<html><head><script type=\"text/x-mathjax-config\">\n" +
+                                          "            MathJax.Hub.Config({\n" +
+                                          "                tex2jax: {\n" +
+                                          "                    inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n" +
+                                          "                    displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ],\n" +
+                                          "                    processEscapes: true,\n" +
+                                          "                    processEnvironments: true\n" +
+                                          "                },\n" +
+                                          "                displayAlign: 'center',\n" +
+                                          "                \"HTML-CSS\": {\n" +
+                                          "                    styles: {'#mydiv': {\"font-size\": %s}},\n" +
+                                          "                    preferredFont: null,\n" +
+                                          "                    linebreaks: { automatic: true }\n" +
+                                          "                }\n" +
+                                          "            });\n" +
+                                          "</script><script type=\"text/javascript\"\n" +
+                                          " src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full\">\n" +
+                                          " </script></head><body><div id=\"mydiv\">";
+
+  private static final String ourPostfix = "</div></body></html>";
 
   public static void closeSilently(@Nullable final Closeable stream) {
     if (stream != null) {
@@ -452,11 +475,12 @@ public class StudyUtils {
       return text;
     }
     if (taskDirectory != null) {
+      final String prefix = String.format(ourPrefix, EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize());
       final String taskTextFileHtml = getTaskTextFromTaskName(taskDirectory, EduNames.TASK_HTML);
-      if (taskTextFileHtml != null) return taskTextFileHtml;
+      if (taskTextFileHtml != null) return prefix + taskTextFileHtml + ourPostfix;
       
       final String taskTextFileMd = getTaskTextFromTaskName(taskDirectory, EduNames.TASK_MD);
-      if (taskTextFileMd != null) return convertToHtml(taskTextFileMd);      
+      if (taskTextFileMd != null) return prefix + convertToHtml(taskTextFileMd) + ourPostfix;      
     }
     return null;
   }
@@ -694,4 +718,10 @@ public class StudyUtils {
     }
     return FileDocumentManager.getInstance().getDocument(taskFile);
   }
+
+  public static void showErrorPopupOnToolbar(@NotNull Project project) {
+    final Balloon balloon =
+      JBPopupFactory.getInstance().createHtmlTextBalloonBuilder("Couldn't post your reaction", MessageType.ERROR, null).createBalloon();
+    showCheckPopUp(project, balloon);
+  }
 }