Search in sources :

Example 1 with Course

use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.

the class CCProjectComponent method migrateIfNeeded.

public void migrateIfNeeded() {
    Course studyCourse = StudyTaskManager.getInstance(myProject).getCourse();
    if (studyCourse == null) {
        Course oldCourse = CCProjectService.getInstance(myProject).getCourse();
        if (oldCourse == null) {
            return;
        }
        StudyTaskManager.getInstance(myProject).setCourse(oldCourse);
        CCProjectService.getInstance(myProject).setCourse(null);
        oldCourse.initCourse(true);
        oldCourse.setCourseMode(CCUtils.COURSE_MODE);
        File coursesDir = new File(PathManager.getConfigPath(), "courses");
        File courseDir = new File(coursesDir, oldCourse.getName() + "-" + myProject.getName());
        oldCourse.setCourseDirectory(courseDir.getPath());
        StudyUtils.registerStudyToolWindow(oldCourse, myProject);
        transformFiles(oldCourse, myProject);
    }
}
Also used : Course(com.jetbrains.edu.learning.courseFormat.Course) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) File(java.io.File)

Example 2 with Course

use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.

the class CCSubtaskChangeListener method subtaskChanged.

@Override
public void subtaskChanged(@NotNull Project project, @NotNull Task task, int oldSubtaskNumber, int newSubtaskNumber) {
    VirtualFile taskDir = task.getTaskDir(project);
    if (taskDir == null) {
        return;
    }
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
    if (manager == null) {
        return;
    }
    String testFileName = manager.getTestFileName();
    if (newSubtaskNumber != 0) {
        String nameWithoutExtension = FileUtil.getNameWithoutExtension(testFileName);
        String extension = FileUtilRt.getExtension(testFileName);
        testFileName = nameWithoutExtension + EduNames.SUBTASK_MARKER + newSubtaskNumber + "." + extension;
    }
    VirtualFile newTestFile = taskDir.findChild(testFileName);
    if (newTestFile == null) {
        return;
    }
    FileEditorManager editorManager = FileEditorManager.getInstance(project);
    List<VirtualFile> testFiles = ContainerUtil.filter(taskDir.getChildren(), file -> CCUtils.isTestsFile(project, file) && editorManager.isFileOpen(file));
    if (testFiles.isEmpty()) {
        return;
    }
    Editor selectedTextEditor = editorManager.getSelectedTextEditor();
    for (VirtualFile testFile : testFiles) {
        editorManager.closeFile(testFile);
    }
    editorManager.openFile(newTestFile, true);
    if (selectedTextEditor != null) {
        reopenSelectedEditor(editorManager, selectedTextEditor);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Course(com.jetbrains.edu.learning.courseFormat.Course) Editor(com.intellij.openapi.editor.Editor) StudyLanguageManager(com.jetbrains.edu.learning.StudyLanguageManager)

Example 3 with Course

use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.

the class CCTestsTabTitleProvider method getEditorTabTitle.

@Nullable
@Override
public String getEditorTabTitle(Project project, VirtualFile file) {
    if (!CCUtils.isCourseCreator(project)) {
        return null;
    }
    if (!CCUtils.isTestsFile(project, file)) {
        return null;
    }
    Course course = StudyTaskManager.getInstance(project).getCourse();
    assert course != null;
    StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
    if (manager == null) {
        return null;
    }
    return manager.getTestFileName();
}
Also used : Course(com.jetbrains.edu.learning.courseFormat.Course) StudyLanguageManager(com.jetbrains.edu.learning.StudyLanguageManager) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with Course

use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.

the class CCVirtualFileListener method fileDeleted.

@Override
public void fileDeleted(@NotNull VirtualFileEvent event) {
    VirtualFile removedFile = event.getFile();
    String path = removedFile.getPath();
    if (path.contains(CCUtils.GENERATED_FILES_FOLDER)) {
        return;
    }
    Project project = ProjectUtil.guessProjectForFile(removedFile);
    if (project == null) {
        return;
    }
    if (project.getBasePath() != null && !FileUtil.isAncestor(project.getBasePath(), removedFile.getPath(), true)) {
        return;
    }
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null || path.contains(FileUtil.toSystemIndependentName(course.getCourseDirectory()))) {
        return;
    }
    final TaskFile taskFile = StudyUtils.getTaskFile(project, removedFile);
    if (taskFile != null) {
        deleteTaskFile(removedFile, taskFile);
        return;
    }
    if (removedFile.getName().contains(EduNames.TASK)) {
        deleteTask(course, removedFile);
    }
    if (removedFile.getName().contains(EduNames.LESSON)) {
        deleteLesson(course, removedFile, project);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) Course(com.jetbrains.edu.learning.courseFormat.Course)

Example 5 with Course

use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.

the class CCChangeCourseInfo method actionPerformed.

@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());
    setupLanguageLevels(course, panel);
    DialogBuilder builder = createChangeInfoDialog(project, panel);
    if (builder.showAndGet()) {
        course.setAuthorsAsString(panel.getAuthors());
        course.setName(panel.getName());
        course.setDescription(panel.getDescription());
        setVersion(course, panel);
        ProjectView.getInstance(project).refresh();
        ProjectInspectionProfileManager.getInstance(project).fireProfileChanged();
    }
}
Also used : Project(com.intellij.openapi.project.Project) Course(com.jetbrains.edu.learning.courseFormat.Course) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) CCNewProjectPanel(com.jetbrains.edu.coursecreator.ui.CCNewProjectPanel)

Aggregations

Course (com.jetbrains.edu.learning.courseFormat.Course)51 Project (com.intellij.openapi.project.Project)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)12 PsiDirectory (com.intellij.psi.PsiDirectory)11 Lesson (com.jetbrains.edu.learning.courseFormat.Lesson)10 File (java.io.File)10 IdeView (com.intellij.ide.IdeView)8 Nullable (org.jetbrains.annotations.Nullable)6 Presentation (com.intellij.openapi.actionSystem.Presentation)5 PsiFile (com.intellij.psi.PsiFile)5 Task (com.jetbrains.edu.learning.courseFormat.Task)5 NotNull (org.jetbrains.annotations.NotNull)5 Editor (com.intellij.openapi.editor.Editor)4 PsiElement (com.intellij.psi.PsiElement)4 List (java.util.List)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)3 ApplicationManager (com.intellij.openapi.application.ApplicationManager)3 Module (com.intellij.openapi.module.Module)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3