@Override
 public void actionPerformed(@NotNull AnActionEvent e) {
   final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
   final Project project = e.getData(CommonDataKeys.PROJECT);
   if (view == null || project == null) {
     return;
   }
   final Course course = StudyTaskManager.getInstance(project).getCourse();
   if (course == null) {
     return;
   }
   if (course.getId() > 0) {
     ProgressManager.getInstance()
         .run(
             new Task.Modal(project, "Updating Course", true) {
               @Override
               public void run(@NotNull ProgressIndicator indicator) {
                 for (Lesson lesson : course.getLessons()) {
                   if (lesson.getId() > 0) {
                     CCStepicConnector.updateLesson(project, lesson, indicator);
                   } else {
                     final CourseInfo info = CourseInfo.fromCourse(course);
                     final int lessonId = CCStepicConnector.postLesson(project, lesson, indicator);
                     final List<Integer> sections = info.getSections();
                     final Integer sectionId = sections.get(sections.size() - 1);
                     CCStepicConnector.postUnit(lessonId, lesson.getIndex(), sectionId);
                   }
                 }
               }
             });
   } else {
     CCStepicConnector.postCourseWithProgress(project, course);
   }
   EduUsagesCollector.courseUploaded();
 }
 protected boolean isCourseBasedProject(@NotNull final AbstractTreeNode parent) {
   final Project project = parent.getProject();
   if (project != null) {
     final StudyTaskManager studyTaskManager = StudyTaskManager.getInstance(project);
     if (studyTaskManager.getCourse() == null) {
       return false;
     }
   }
   return true;
 }
示例#3
0
 @Override
 public void createToolWindowContent(
     @NotNull final Project project, @NotNull final ToolWindow toolWindow) {
   toolWindow.setIcon(InteractiveLearningIcons.TaskDescription);
   StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
   final Course course = taskManager.getCourse();
   if (course != null) {
     final StudyToolWindow studyToolWindow;
     if (StudyUtils.hasJavaFx() && StudyTaskManager.getInstance(project).shouldUseJavaFx()) {
       studyToolWindow = new StudyJavaFxToolWindow();
     } else {
       studyToolWindow = new StudySwingToolWindow();
     }
     studyToolWindow.init(project);
     final ContentManager contentManager = toolWindow.getContentManager();
     final Content content =
         contentManager.getFactory().createContent(studyToolWindow, null, false);
     contentManager.addContent(content);
     Disposer.register(project, studyToolWindow);
   }
 }
 @Override
 public void update(@NotNull AnActionEvent e) {
   Presentation presentation = e.getPresentation();
   Project project = e.getProject();
   presentation.setEnabledAndVisible(project != null && CCUtils.isCourseCreator(project));
   if (project != null) {
     final Course course = StudyTaskManager.getInstance(project).getCourse();
     if (course != null) {
       final int id = course.getId();
       if (id > 0) {
         presentation.setText("Update Course on Stepik");
       }
     }
   }
 }
  public static void navigateToFailedPlaceholder(
      @NotNull final StudyState studyState,
      @NotNull final Task task,
      @NotNull final VirtualFile taskDir,
      @NotNull final Project project) {
    TaskFile selectedTaskFile = studyState.getTaskFile();
    Editor editor = studyState.getEditor();
    TaskFile taskFileToNavigate = selectedTaskFile;
    VirtualFile fileToNavigate = studyState.getVirtualFile();
    final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
    if (!taskManager.hasFailedAnswerPlaceholders(selectedTaskFile)) {
      for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
        String name = entry.getKey();
        TaskFile taskFile = entry.getValue();
        if (taskManager.hasFailedAnswerPlaceholders(taskFile)) {
          taskFileToNavigate = taskFile;
          VirtualFile virtualFile = taskDir.findChild(name);
          if (virtualFile == null) {
            continue;
          }
          FileEditor fileEditor =
              FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
          if (fileEditor instanceof StudyEditor) {
            StudyEditor studyEditor = (StudyEditor) fileEditor;
            editor = studyEditor.getEditor();
          }
          fileToNavigate = virtualFile;
          break;
        }
      }
    }
    if (fileToNavigate != null) {
      FileEditorManager.getInstance(project).openFile(fileToNavigate, true);
    }
    final Editor editorToNavigate = editor;
    ApplicationManager.getApplication()
        .invokeLater(
            () ->
                IdeFocusManager.getInstance(project)
                    .requestFocus(editorToNavigate.getContentComponent(), true));

    StudyNavigator.navigateToFirstFailedAnswerPlaceholder(editor, taskFileToNavigate);
  }
  @NotNull
  private static Course getCourse(
      @NotNull Project project,
      @NotNull String name,
      @NotNull String[] authors,
      @NotNull String description) {
    final Course course = new Course();
    course.setName(name);
    course.setAuthors(authors);
    course.setDescription(description);
    course.setLanguage(PythonLanguage.getInstance().getID());
    course.setCourseMode(CCUtils.COURSE_MODE);

    File coursesDir = new File(PathManager.getConfigPath(), "courses");
    File courseDir = new File(coursesDir, name + "-" + project.getName());
    course.setCourseDirectory(courseDir.getPath());

    StudyTaskManager.getInstance(project).setCourse(course);
    StudyProjectComponent.getInstance(project).registerStudyToolWindow(course);
    return course;
  }
 @Override
 public void setCommandLineParameters(
     @NotNull final GeneralCommandLine cmd,
     @NotNull final Project project,
     @NotNull final String filePath,
     @NotNull final String sdkPath,
     @NotNull final Task currentTask) {
   final List<UserTest> userTests =
       StudyTaskManager.getInstance(project).getUserTests(currentTask);
   if (!userTests.isEmpty()) {
     StudyLanguageManager manager =
         StudyUtils.getLanguageManager(currentTask.getLesson().getCourse());
     if (manager != null) {
       cmd.addParameter(
           new File(project.getBaseDir().getPath(), manager.getUserTester()).getPath());
       cmd.addParameter(sdkPath);
       cmd.addParameter(filePath);
     }
   } else {
     cmd.addParameter(filePath);
   }
 }
  @Override
  public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    presentation.setEnabledAndVisible(false);
    Project project = e.getProject();
    if (project == null) {
      return;
    }
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
      return;
    }

    if (!EduNames.STUDY.equals(course.getCourseMode())) {
      presentation.setVisible(true);
      return;
    }

    if (getAnswerPlaceholder(e) == null) {
      presentation.setEnabledAndVisible(false);
      return;
    }
    presentation.setEnabledAndVisible(true);
  }
  @Override
  public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    if (project == null) {
      return;
    }
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
      return;
    }

    CCNewProjectPanel panel =
        new CCNewProjectPanel(
            course.getName(),
            Course.getAuthorsString(course.getAuthors()),
            course.getDescription());
    DialogBuilder builder = createChangeInfoDialog(project, panel);
    if (builder.showAndGet()) {
      course.setAuthors(panel.getAuthors());
      course.setName(panel.getName());
      course.setDescription(panel.getDescription());
      ProjectView.getInstance(project).refresh();
    }
  }