コード例 #1
0
 @Override
 public void loadState(Element el) {
   myCourse = XmlSerializer.deserialize(el.getChild(COURSE_ELEMENT), Course.class);
   if (myCourse != null) {
     myCourse.init(true);
   }
 }
コード例 #2
0
 @Nullable
 public TaskFile getTaskFile(@NotNull final VirtualFile file) {
   if (myCourse == null) {
     return null;
   }
   final VirtualFile taskDir = file.getParent();
   if (taskDir == null) {
     return null;
   }
   final String taskDirName = taskDir.getName();
   if (taskDirName.contains(Task.TASK_DIR)) {
     final VirtualFile lessonDir = taskDir.getParent();
     if (lessonDir != null) {
       int lessonIndex = StudyUtils.getIndex(lessonDir.getName(), StudyNames.LESSON_DIR);
       List<Lesson> lessons = myCourse.getLessons();
       if (!StudyUtils.indexIsValid(lessonIndex, lessons)) {
         return null;
       }
       final Lesson lesson = lessons.get(lessonIndex);
       int taskIndex = StudyUtils.getIndex(taskDirName, Task.TASK_DIR);
       final List<Task> tasks = lesson.getTaskList();
       if (!StudyUtils.indexIsValid(taskIndex, tasks)) {
         return null;
       }
       final Task task = tasks.get(taskIndex);
       return task.getFile(file.getName());
     }
   }
   return null;
 }
コード例 #3
0
 @Override
 public void projectOpened() {
   if (myCourse != null && !myCourse.isUpToDate()) {
     myCourse.setUpToDate(true);
     updateCourse();
   }
   ApplicationManager.getApplication()
       .invokeLater(
           new DumbAwareRunnable() {
             @Override
             public void run() {
               ApplicationManager.getApplication()
                   .runWriteAction(
                       new DumbAwareRunnable() {
                         @Override
                         public void run() {
                           if (myCourse != null) {
                             moveFocusToEditor();
                             UISettings.getInstance().HIDE_TOOL_STRIPES = false;
                             UISettings.getInstance().fireUISettingsChanged();
                             final ToolWindowManager toolWindowManager =
                                 ToolWindowManager.getInstance(myProject);
                             registerToolWindow(toolWindowManager);
                             final ToolWindow studyToolWindow =
                                 toolWindowManager.getToolWindow(
                                     StudyToolWindowFactory.STUDY_TOOL_WINDOW);
                             if (studyToolWindow != null) {
                               StudyUtils.updateStudyToolWindow(myProject);
                               studyToolWindow.show(null);
                             }
                             registerShortcuts();
                           }
                         }
                       });
             }
           });
 }
コード例 #4
0
  private void updateCourse() {
    if (myCourse == null) {
      return;
    }
    final File resourceDirectory = new File(myCourse.getCourseDirectory());
    if (!resourceDirectory.exists()) {
      return;
    }
    final File[] files = resourceDirectory.listFiles();
    if (files == null) return;
    for (File file : files) {
      if (file.getName().equals(StudyNames.TEST_HELPER)) {
        copyFile(file, new File(myProject.getBasePath(), StudyNames.TEST_HELPER));
      }
      if (file.getName().startsWith(StudyNames.LESSON)) {
        final File[] tasks = file.listFiles();
        if (tasks == null) continue;
        for (File task : tasks) {
          final File taskDescr = new File(task, StudyNames.TASK_HTML);
          final File taskTests = new File(task, StudyNames.TASK_TESTS);
          copyFile(
              taskDescr,
              new File(
                  new File(new File(myProject.getBasePath(), file.getName()), task.getName()),
                  StudyNames.TASK_HTML));
          copyFile(
              taskTests,
              new File(
                  new File(new File(myProject.getBasePath(), file.getName()), task.getName()),
                  StudyNames.TASK_TESTS));
        }
      }
    }

    final Notification notification =
        new Notification(
            "Update.course",
            "Course update",
            "Current course is synchronized",
            NotificationType.INFORMATION);
    notification.notify(myProject);
  }