synchronize courses after update for custom projects
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Tue, 23 Dec 2014 11:51:40 +0000 (14:51 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Tue, 23 Dec 2014 11:51:40 +0000 (14:51 +0300)
python/edu/learn-python/src/com/jetbrains/python/edu/StudyInitialConfigurator.java
python/edu/learn-python/src/com/jetbrains/python/edu/StudyTaskManager.java
python/edu/learn-python/src/com/jetbrains/python/edu/course/Course.java

index aa2d2eb112171dc7c003685d8f6588929b6de1c0..0b2648c4180c1b04ca7e11dc447b39bfd502de43 100644 (file)
@@ -2,7 +2,6 @@ package com.jetbrains.python.edu;
 
 import com.intellij.codeInsight.CodeInsightSettings;
 import com.intellij.ide.RecentProjectsManager;
-import com.intellij.ide.impl.ProjectUtil;
 import com.intellij.ide.ui.UISettings;
 import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.openapi.application.PathManager;
@@ -24,8 +23,6 @@ public class StudyInitialConfigurator {
   @NonNls private static final String CONFIGURED_V1 = "StudyPyCharm.InitialConfiguration";
   @NonNls private static final String CONFIGURED_V11 = "StudyPyCharm.InitialConfiguration1.1";
 
-  public static boolean UPDATE_PROJECT = false;
-
   /**
    * @noinspection UnusedParameters
    */
@@ -60,11 +57,6 @@ public class StudyInitialConfigurator {
           LOG.warn("Couldn't copy bundled courses " + e);
         }
       }
-      final File projectDir = new File(ProjectUtil.getBaseDir(), "PythonIntroduction");
-      if (projectDir.exists()) {
-        //noinspection AssignmentToStaticFieldFromInstanceMethod
-        UPDATE_PROJECT = true;
-      }
     }
   }
 
index adb8f56c5a3cf673db9adb979ae107a7f0cf82cd..f76d2934fb62ff070ef993e18607363d5e3fdd90 100644 (file)
@@ -1,7 +1,6 @@
 package com.jetbrains.python.edu;
 
 import com.intellij.ide.BrowserUtil;
-import com.intellij.ide.impl.ProjectUtil;
 import com.intellij.ide.ui.UISettings;
 import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.notification.Notification;
@@ -11,7 +10,6 @@ import com.intellij.notification.Notifications;
 import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.actionSystem.ex.AnActionListener;
 import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.PathManager;
 import com.intellij.openapi.components.*;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.EditorFactory;
@@ -23,7 +21,9 @@ import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.DumbAwareRunnable;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.startup.StartupManager;
-import com.intellij.openapi.ui.popup.*;
+import com.intellij.openapi.ui.popup.Balloon;
+import com.intellij.openapi.ui.popup.JBPopupAdapter;
+import com.intellij.openapi.ui.popup.LightweightWindowEvent;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileAdapter;
@@ -114,10 +114,8 @@ public class StudyTaskManager implements ProjectComponent, PersistentStateCompon
 
   @Override
   public void projectOpened() {
-    final File pythonIntroduction = new File(ProjectUtil.getBaseDir(), "PythonIntroduction");
-    if (StudyInitialConfigurator.UPDATE_PROJECT && myProject.getBasePath().equals(pythonIntroduction.getAbsolutePath())) {
-      //noinspection AssignmentToStaticFieldFromInstanceMethod
-      StudyInitialConfigurator.UPDATE_PROJECT = false;
+    if (myCourse != null && !myCourse.isUpToDate()) {
+      myCourse.setUpToDate(true);
       updateCourse();
     }
     ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() {
@@ -245,8 +243,17 @@ public class StudyTaskManager implements ProjectComponent, PersistentStateCompon
   }
 
   private void updateCourse() {
-    final File userCourseDir = new File(PathManager.getConfigPath(), StudyNames.COURSES);
-    final File courseDir = new File(userCourseDir, StudyNames.INTRODUCTION_COURSE);
+    if (myCourse == null) {
+      return;
+    }
+    File resourceFile = new File(myCourse.getResourcePath());
+    if (!resourceFile.exists()) {
+      return;
+    }
+    final File courseDir = resourceFile.getParentFile();
+    if (!courseDir.exists()) {
+      return;
+    }
     final File[] files = courseDir.listFiles();
     if (files == null) return;
     for (File lesson : files) {
index a16b3405f37524dfb7b8d6327715e15676f5f2f1..5bbc40a10671acc4fe06d771d5002b1cef1b5559 100644 (file)
@@ -24,6 +24,7 @@ public class Course {
   public String author;
   public static final String COURSE_DIR = "course";
   public static final String HINTS_DIR = "hints";
+  private boolean myUpToDate = false;
 
 
   public List<Lesson> getLessons() {
@@ -103,4 +104,12 @@ public class Course {
   public String getDescription() {
     return description;
   }
+
+  public boolean isUpToDate() {
+    return myUpToDate;
+  }
+
+  public void setUpToDate(boolean upToDate) {
+    myUpToDate = upToDate;
+  }
 }