cleanup
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Mon, 20 Oct 2014 15:30:11 +0000 (19:30 +0400)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Mon, 20 Oct 2014 15:30:11 +0000 (19:30 +0400)
python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCEditorFactoryListener.java
python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectService.java
python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCDeleteTaskWindow.java

index 9974c2f3d4831a5d974e8f49bb59a26864b29ed1..74afc795b60a742a2ceff37b81b37fe63e92d307 100644 (file)
@@ -48,7 +48,7 @@ public class CCEditorFactoryListener implements EditorFactoryListener {
     editor.getDocument().addDocumentListener(listener);
     EditorActionManager.getInstance()
       .setReadonlyFragmentModificationHandler(editor.getDocument(), new TaskWindowDeleteHandler(editor));
-    CCProjectService.drawTaskWindows(virtualFile, editor, course);
+    CCProjectService.getInstance(project).drawTaskWindows(virtualFile, editor, course);
     editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
     taskFile.createGuardedBlocks(editor);
   }
index f38ae40471b78eedce71af87fe47636546b13ada..6d56fe6b596279859449075065d71f6352788813 100644 (file)
@@ -31,6 +31,7 @@ import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.util.xmlb.XmlSerializer;
 import org.jdom.Element;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.coursecreator.format.*;
 
 import java.io.File;
@@ -90,32 +91,37 @@ public class CCProjectService implements PersistentStateComponent<Element> {
     ProjectView.getInstance(project).refresh();
   }
 
-  public static void drawTaskWindows(@NotNull final VirtualFile virtualFile, @NotNull final Editor editor, @NotNull final Course course) {
+  @Nullable
+  public TaskFile getTaskFile(@NotNull final VirtualFile virtualFile) {
     VirtualFile taskDir = virtualFile.getParent();
     if (taskDir == null) {
-      return;
+      return null;
     }
     String taskDirName = taskDir.getName();
     if (!taskDirName.contains("task")) {
-      return;
+      return null;
     }
     VirtualFile lessonDir = taskDir.getParent();
     if (lessonDir == null) {
-      return;
+      return null;
     }
     String lessonDirName = lessonDir.getName();
     if (!lessonDirName.contains("lesson")) {
-      return;
+      return null;
     }
-    Lesson lesson = course.getLessonsMap().get(lessonDirName);
+    Lesson lesson = myCourse.getLessonsMap().get(lessonDirName);
     if (lesson == null) {
-      return;
+      return null;
     }
     Task task = lesson.getTask(taskDirName);
     if (task == null) {
-      return;
+      return null;
     }
-    TaskFile taskFile = task.getTaskFile(virtualFile.getName());
+    return task.getTaskFile(virtualFile.getName());
+  }
+
+  public void drawTaskWindows(@NotNull final VirtualFile virtualFile, @NotNull final Editor editor, @NotNull final Course course) {
+    TaskFile taskFile = getTaskFile(virtualFile);
     if (taskFile == null) {
       return;
     }
index 9257c2adf41c7dd04e7ba728e01cc7dad481845e..48ecf410999ac120e851db87463b591551419628 100644 (file)
@@ -60,7 +60,7 @@ public class CCDeleteTaskWindow extends DumbAwareAction {
       myTaskWindow.removeResources(project);
       taskWindows.remove(myTaskWindow);
       editor.getMarkupModel().removeAllHighlighters();
-      CCProjectService.drawTaskWindows(file.getVirtualFile(), editor, course);
+      CCProjectService.getInstance(project).drawTaskWindows(file.getVirtualFile(), editor, course);
       taskFile.createGuardedBlocks(editor);
       DaemonCodeAnalyzerImpl.getInstance(project).restart(file);
     }