return CCProjectService for migration from old versions
authorliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 21 Apr 2016 11:26:26 +0000 (14:26 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 21 Apr 2016 11:26:26 +0000 (14:26 +0300)
python/educational-core/course-creator/resources/META-INF/plugin.xml
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCProjectService.java

index ed0795f78ba35808bce2b7367838a00446080bb5..421b23fef48ed4412120cc60504f25376c110b55 100644 (file)
@@ -16,6 +16,7 @@
   <depends>com.jetbrains.edu.interactivelearning</depends>
 
   <extensions defaultExtensionNs="com.intellij">
+    <projectService serviceImplementation="com.jetbrains.edu.coursecreator.CCProjectService"/>
     <treeStructureProvider implementation="com.jetbrains.edu.coursecreator.projectView.CCTreeStructureProvider"/>
     <refactoring.elementListenerProvider implementation="com.jetbrains.edu.coursecreator.CCRefactoringElementListenerProvider"/>
     <refactoring.moveHandler implementation="com.jetbrains.edu.coursecreator.handlers.CCLessonMoveHandlerDelegate" order="first"/>
index ba98866926717401457e6b90b3d950c9ba97a6be..2ff6f8051033d6c55ef704697f2cc0fda3a2f349 100644 (file)
  */
 package com.jetbrains.edu.coursecreator;
 
-import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.components.PersistentStateComponent;
 import com.intellij.openapi.components.ServiceManager;
 import com.intellij.openapi.components.State;
 import com.intellij.openapi.components.Storage;
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.ui.JBColor;
 import com.intellij.util.xmlb.XmlSerializerUtil;
-import com.jetbrains.edu.learning.core.EduAnswerPlaceholderPainter;
-import com.jetbrains.edu.learning.core.EduDocumentListener;
-import com.jetbrains.edu.learning.core.EduNames;
-import com.jetbrains.edu.learning.core.EduUtils;
-import com.jetbrains.edu.learning.courseFormat.*;
+import com.jetbrains.edu.learning.courseFormat.Course;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 
 @State(name = "CCProjectService", storages = @Storage("course_service.xml"))
 public class CCProjectService implements PersistentStateComponent<CCProjectService> {
   private Course myCourse;
 
-  private static final Map<Document, EduDocumentListener> myDocumentListeners = new HashMap<Document, EduDocumentListener>();
-
-  @Nullable
-  public TaskFile getTaskFile(@NotNull final VirtualFile virtualFile) {
-    VirtualFile taskDir = virtualFile.getParent();
-    if (taskDir == null) {
-      return null;
-    }
-    String taskDirName = taskDir.getName();
-    if (!taskDirName.contains(EduNames.TASK)) {
-      return null;
-    }
-    VirtualFile lessonDir = taskDir.getParent();
-    if (lessonDir == null) {
-      return null;
-    }
-    String lessonDirName = lessonDir.getName();
-    if (!lessonDirName.contains(EduNames.LESSON)) {
-      return null;
-    }
-    Lesson lesson = myCourse.getLesson(lessonDirName);
-    if (lesson == null) {
-      return null;
-    }
-    Task task = lesson.getTask(taskDir.getName());
-    if (task == null) {
-      return null;
-    }
-    return task.getTaskFile(virtualFile.getName());
-  }
-
-  public void drawAnswerPlaceholders(@NotNull final VirtualFile virtualFile, @NotNull final Editor editor) {
-    TaskFile taskFile = getTaskFile(virtualFile);
-    if (taskFile == null) {
-      return;
-    }
-    List<AnswerPlaceholder> answerPlaceholders = taskFile.getAnswerPlaceholders();
-    for (AnswerPlaceholder answerPlaceholder : answerPlaceholders) {
-      EduAnswerPlaceholderPainter.drawAnswerPlaceholder(editor, answerPlaceholder, false, JBColor.BLUE);
-    }
-  }
-
-  public static void addDocumentListener(Document document, EduDocumentListener listener) {
-    myDocumentListeners.put(document, listener);
-  }
-
-  public static EduDocumentListener getListener(Document document) {
-    return myDocumentListeners.get(document);
-  }
-
-  public static void removeListener(Document document) {
-    myDocumentListeners.remove(document);
-  }
-
-  @Nullable
-  public Task getTask(VirtualFile file) {
-    if (myCourse == null || file == null) {
-      return null;
-    }
-    VirtualFile taskDir = file.getParent();
-    if (taskDir != null) {
-      String taskDirName = taskDir.getName();
-      if (taskDirName.contains(EduNames.TASK)) {
-        VirtualFile lessonDir = taskDir.getParent();
-        if (lessonDir != null) {
-          String lessonDirName = lessonDir.getName();
-          int lessonIndex = EduUtils.getIndex(lessonDirName, EduNames.LESSON);
-          List<Lesson> lessons = myCourse.getLessons();
-          if (!EduUtils.indexIsValid(lessonIndex, lessons)) {
-            return null;
-          }
-          Lesson lesson = lessons.get(lessonIndex);
-          int taskIndex = EduUtils.getIndex(taskDirName, EduNames.TASK);
-          List<Task> tasks = lesson.getTaskList();
-          if (!EduUtils.indexIsValid(taskIndex, tasks)) {
-            return null;
-          }
-          return tasks.get(taskIndex);
-        }
-      }
-    }
-    return null;
-  }
-
-  public boolean isTaskFile(VirtualFile file) {
-    Task task = getTask(file);
-    return task != null && task.isTaskFile(file.getName());
-  }
-
-  public static boolean setCCActionAvailable(@NotNull AnActionEvent e) {
-    final Project project = e.getProject();
-    if (project == null) {
-      return false;
-    }
-    if (getInstance(project).getCourse() == null) {
-      EduUtils.enableAction(e, false);
-      return false;
-    }
-    EduUtils.enableAction(e, true);
-    return true;
-  }
-
   public Course getCourse() {
     return myCourse;
   }
 
-  public void setCourse(@NotNull final Course course) {
+  public void setCourse(Course course) {
     myCourse = course;
   }