Search in sources :

Example 11 with Course

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

the class CCTaskMoveHandlerDelegate method isTaskDir.

private static boolean isTaskDir(PsiDirectory sourceDirectory) {
    if (sourceDirectory == null) {
        return false;
    }
    Project project = sourceDirectory.getProject();
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null || !CCUtils.isCourseCreator(project)) {
        return false;
    }
    return EduUtils.getTask(sourceDirectory, course) != null;
}
Also used : Project(com.intellij.openapi.project.Project) Course(com.jetbrains.edu.learning.courseFormat.Course)

Example 12 with Course

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

the class CCPushLesson method update.

@Override
public void update(@NotNull AnActionEvent e) {
    e.getPresentation().setEnabledAndVisible(false);
    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.getCourseMode().equals(CCUtils.COURSE_MODE))
        return;
    PsiDirectory lessonDir = DirectoryChooserUtil.getOrChooseDirectory(view);
    if (lessonDir == null || !lessonDir.getName().contains("lesson")) {
        return;
    }
    final Lesson lesson = course.getLesson(lessonDir.getName());
    if (lesson != null && course.getId() > 0) {
        e.getPresentation().setEnabledAndVisible(true);
        if (lesson.getId() <= 0) {
            e.getPresentation().setText("Upload Lesson to Stepik");
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView) Course(com.jetbrains.edu.learning.courseFormat.Course) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson)

Example 13 with Course

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

the class CCPushTask method update.

@Override
public void update(@NotNull AnActionEvent e) {
    e.getPresentation().setEnabledAndVisible(false);
    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.getCourseMode().equals(CCUtils.COURSE_MODE))
        return;
    PsiDirectory taskDir = DirectoryChooserUtil.getOrChooseDirectory(view);
    if (taskDir == null || !taskDir.getName().contains(EduNames.TASK)) {
        return;
    }
    final PsiDirectory lessonDir = taskDir.getParentDirectory();
    if (lessonDir == null)
        return;
    final Lesson lesson = course.getLesson(lessonDir.getName());
    if (lesson != null && lesson.getId() > 0 && course.getId() > 0) {
        e.getPresentation().setEnabledAndVisible(true);
        final com.jetbrains.edu.learning.courseFormat.Task task = lesson.getTask(taskDir.getName());
        if (task.getStepId() <= 0) {
            e.getPresentation().setText("Upload Task to Stepik");
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView) Course(com.jetbrains.edu.learning.courseFormat.Course) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson)

Example 14 with Course

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

the class CCShowPreview method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = e.getProject();
    Module module = LangDataKeys.MODULE.getData(e.getDataContext());
    if (project == null || module == null) {
        return;
    }
    final PsiFile file = CommonDataKeys.PSI_FILE.getData(e.getDataContext());
    if (file == null) {
        return;
    }
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    VirtualFile virtualFile = file.getVirtualFile();
    TaskFile taskFile = StudyUtils.getTaskFile(project, virtualFile);
    if (taskFile == null) {
        return;
    }
    final PsiDirectory taskDir = file.getContainingDirectory();
    if (taskDir == null) {
        return;
    }
    PsiDirectory lessonDir = taskDir.getParentDirectory();
    if (lessonDir == null) {
        return;
    }
    if (taskFile.getActivePlaceholders().isEmpty()) {
        Messages.showInfoMessage("Preview is available for task files with answer placeholders only", "No Preview for This File");
        return;
    }
    VirtualFile generatedFilesFolder = CCUtils.getGeneratedFilesFolder(project, module);
    if (generatedFilesFolder == null) {
        return;
    }
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            Pair<VirtualFile, TaskFile> pair = EduUtils.createStudentFile(this, project, virtualFile, generatedFilesFolder, null, taskFile.getTask().getActiveSubtaskIndex());
            if (pair != null) {
                showPreviewDialog(project, pair.getFirst(), pair.getSecond());
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) Course(com.jetbrains.edu.learning.courseFormat.Course) Pair(com.intellij.openapi.util.Pair)

Example 15 with Course

use of com.jetbrains.edu.learning.courseFormat.Course 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)

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