Search in sources :

Example 1 with TaskFile

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

the class CCStudyActionListener method beforeCheck.

@Override
public void beforeCheck(AnActionEvent event) {
    Project project = event.getProject();
    if (project == null) {
        return;
    }
    if (!CCUtils.isCourseCreator(project)) {
        return;
    }
    VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(event.getDataContext());
    if (virtualFile == null) {
        return;
    }
    TaskFile taskFile = StudyUtils.getTaskFile(project, virtualFile);
    if (taskFile == null) {
        return;
    }
    Task task = taskFile.getTask();
    VirtualFile taskDir = StudyUtils.getTaskDir(virtualFile);
    if (taskDir == null) {
        return;
    }
    CCUtils.updateResources(project, task, taskDir);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) Task(com.jetbrains.edu.learning.courseFormat.Task)

Example 2 with TaskFile

use of com.jetbrains.edu.learning.courseFormat.TaskFile 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 3 with TaskFile

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

the class StudyTabTitleProvider method getEditorTabTitle.

@Nullable
@Override
public String getEditorTabTitle(Project project, VirtualFile file) {
    TaskFile taskFile = StudyUtils.getTaskFile(project, file);
    if (taskFile == null) {
        return null;
    }
    String title = new UniqueNameEditorTabTitleProvider().getEditorTabTitle(project, file);
    if (title == null) {
        return null;
    }
    String[] split = title.split(Pattern.quote(File.separator));
    for (int i = 0; i < split.length; i++) {
        String part = split[i];
        Task task = taskFile.getTask();
        VirtualFile taskDir = task.getTaskDir(project);
        if (taskDir != null && part.equals(taskDir.getName())) {
            split[i] = task.getName();
            continue;
        }
        Lesson lesson = task.getLesson();
        int lessonIndex = lesson.getIndex();
        if (part.equals(EduNames.LESSON + lessonIndex)) {
            split[i] = lesson.getName();
        }
    }
    return StringUtil.join(split, File.separator);
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.jetbrains.edu.learning.courseFormat.Task) UniqueNameEditorTabTitleProvider(com.intellij.openapi.fileEditor.impl.UniqueNameEditorTabTitleProvider) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with TaskFile

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

the class CCAnswerPlaceholderActionTest method doTest.

private void doTest(String name, AnAction action) {
    VirtualFile virtualFile = configureByTaskFile(name + CCTestsUtil.BEFORE_POSTFIX);
    myFixture.testAction(action);
    TaskFile taskFile = StudyUtils.getTaskFile(getProject(), virtualFile);
    checkByFile(taskFile, name + CCTestsUtil.AFTER_POSTFIX, false);
    checkHighlighters(taskFile, myFixture.getEditor().getMarkupModel());
    UndoManager.getInstance(getProject()).undo(FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile));
    checkByFile(taskFile, name + CCTestsUtil.BEFORE_POSTFIX, false);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile)

Example 5 with TaskFile

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

the class CCTaskFileActionTest method testAddTaskFile.

public void testAddTaskFile() {
    VirtualFile virtualFile = copyFileToTask("nonTaskFile.txt");
    myFixture.configureFromExistingVirtualFile(virtualFile);
    launchAction(virtualFile, new CCAddAsTaskFile());
    TaskFile taskFile = StudyUtils.getTaskFile(getProject(), virtualFile);
    assertNotNull(taskFile);
    FileEditor fileEditor = FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile);
    UndoManager.getInstance(getProject()).undo(fileEditor);
    assertNull(StudyUtils.getTaskFile(getProject(), virtualFile));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Aggregations

TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)30 Project (com.intellij.openapi.project.Project)14 Editor (com.intellij.openapi.editor.Editor)11 AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)11 Map (java.util.Map)10 Course (com.jetbrains.edu.learning.courseFormat.Course)9 Task (com.jetbrains.edu.learning.courseFormat.Task)8 Document (com.intellij.openapi.editor.Document)7 PsiFile (com.intellij.psi.PsiFile)7 StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)7 File (java.io.File)6 Nullable (org.jetbrains.annotations.Nullable)6 FileEditor (com.intellij.openapi.fileEditor.FileEditor)5 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)4 Lesson (com.jetbrains.edu.learning.courseFormat.Lesson)4 Presentation (com.intellij.openapi.actionSystem.Presentation)3 EduDocumentListener (com.jetbrains.edu.learning.core.EduDocumentListener)3 AnswerPlaceholderSubtaskInfo (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo)3 ExecutionException (com.intellij.execution.ExecutionException)2