package com.jetbrains.edu.coursecreator;

import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.vfs.VirtualFileManager;
import org.jetbrains.annotations.NotNull;

public class CCProjectComponent implements ProjectComponent {
  private final  CCVirtualFileListener myTaskFileLifeListener = new CCVirtualFileListener();

  public void initComponent() {
    VirtualFileManager.getInstance().addVirtualFileListener(myTaskFileLifeListener);
  }

  public void disposeComponent() {
  }

  @NotNull
  public String getComponentName() {
    return "CCProjectComponent";
  }

  public void projectOpened() {
    VirtualFileManager.getInstance().addVirtualFileListener(myTaskFileLifeListener);
  }

  public void projectClosed() {
    VirtualFileManager.getInstance().removeVirtualFileListener(myTaskFileLifeListener);
  }
}

@@ -35,16 +35,69 @@
 eator;%0A%0A
+import com.intellij.openapi.application.PathManager;%0A
 import c
@@ -127,16 +127,24 @@
 ponents.
+Abstract
 ProjectC
@@ -185,30 +185,239 @@
 api.
-vfs.VirtualFileManager
+project.Project;%0Aimport com.intellij.openapi.vfs.VirtualFileManager;%0Aimport com.jetbrains.edu.learning.StudyProjectComponent;%0Aimport com.jetbrains.edu.learning.StudyTaskManager;%0Aimport com.jetbrains.edu.learning.courseFormat.Course
 ;%0Aim
@@ -457,16 +457,38 @@
 tNull;%0A%0A
+import java.io.File;%0A%0A
 public c
@@ -515,19 +515,24 @@
 ent 
-implement
+extend
 s 
+Abstract
 Proj
@@ -562,17 +562,16 @@
 e final 
- 
 CCVirtua
@@ -637,16 +637,151 @@
 tener();
+%0A  private final Project myProject;%0A%0A  protected CCProjectComponent(Project project) %7B%0A    super(project);%0A    myProject = project;%0A  %7D
 %0A%0A  publ
@@ -914,28 +914,650 @@
 oid 
-disposeComponent() %7B
+migrateIfNeeded() %7B%0A    Course studyCourse = StudyTaskManager.getInstance(myProject).getCourse();%0A    Course course = CCProjectService.getInstance(myProject).getCourse();%0A    if (studyCourse == null && course != null) %7B%0A      course.setCourseMode(CCUtils.COURSE_MODE);%0A      File coursesDir = new File(PathManager.getConfigPath(), %22courses%22);%0A      File courseDir = new File(coursesDir, course.getName() + %22-%22 + myProject.getName());%0A      course.setCourseDirectory(courseDir.getPath());%0A      StudyTaskManager.getInstance(myProject).setCourse(course);%0A      StudyProjectComponent.getInstance(myProject).registerStudyToolWindow(course);%0A    %7D
 %0A  %7D
@@ -1672,24 +1672,47 @@
 tOpened() %7B%0A
+    migrateIfNeeded();%0A
     VirtualF

move course to another service for old projects