Search in sources :

Example 1 with StudyLanguageManager

use of com.jetbrains.edu.learning.StudyLanguageManager 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 2 with StudyLanguageManager

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

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

the class CCTaskDirectoryNode method modifyChildNode.

@Nullable
@Override
public AbstractTreeNode modifyChildNode(AbstractTreeNode childNode) {
    AbstractTreeNode node = super.modifyChildNode(childNode);
    if (node != null) {
        return node;
    }
    Object value = childNode.getValue();
    if (value instanceof PsiElement) {
        PsiElement psiElement = (PsiElement) value;
        PsiFile psiFile = psiElement.getContainingFile();
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile == null) {
            return null;
        }
        if (StudyUtils.isTaskDescriptionFile(virtualFile.getName())) {
            return null;
        }
        Course course = StudyTaskManager.getInstance(myProject).getCourse();
        if (course == null) {
            return null;
        }
        StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
        if (manager == null) {
            return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings);
        }
        if (!CCUtils.isTestsFile(myProject, virtualFile)) {
            return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings);
        }
        if (!myTask.hasSubtasks()) {
            return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings, getTestNodeName(manager, psiElement));
        }
        String testFileName = getTestNodeName(manager, psiElement);
        return isActiveSubtaskTest(virtualFile) ? new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings, testFileName) : null;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) Course(com.jetbrains.edu.learning.courseFormat.Course) PsiElement(com.intellij.psi.PsiElement) StudyLanguageManager(com.jetbrains.edu.learning.StudyLanguageManager) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with StudyLanguageManager

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

the class CCDirectoryNode method modifyChildNode.

@Nullable
@Override
public AbstractTreeNode modifyChildNode(AbstractTreeNode childNode) {
    final AbstractTreeNode node = super.modifyChildNode(childNode);
    if (node != null)
        return node;
    Object value = childNode.getValue();
    if (value instanceof PsiElement) {
        PsiFile psiFile = ((PsiElement) value).getContainingFile();
        VirtualFile virtualFile = psiFile.getVirtualFile();
        Course course = StudyTaskManager.getInstance(myProject).getCourse();
        if (course == null) {
            return null;
        }
        StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
        if (manager == null) {
            return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings);
        }
        if (!CCUtils.isTestsFile(myProject, virtualFile)) {
            return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) Course(com.jetbrains.edu.learning.courseFormat.Course) PsiElement(com.intellij.psi.PsiElement) StudyLanguageManager(com.jetbrains.edu.learning.StudyLanguageManager) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

StudyLanguageManager (com.jetbrains.edu.learning.StudyLanguageManager)4 Course (com.jetbrains.edu.learning.courseFormat.Course)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Nullable (org.jetbrains.annotations.Nullable)3 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 Editor (com.intellij.openapi.editor.Editor)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1