Search in sources :

Example 41 with TaskFile

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

the class StudyStepicFormatTest method doStepOptionsCreationTest.

private static StepicWrappers.StepOptions doStepOptionsCreationTest(String fileName) throws IOException {
    String responseString = FileUtil.loadFile(new File(getTestDataPath(), fileName));
    StepicWrappers.StepSource stepSource = EduStepicClient.deserializeStepicResponse(StepicWrappers.StepContainer.class, responseString).steps.get(0);
    StepicWrappers.StepOptions options = stepSource.block.options;
    List<TaskFile> files = options.files;
    assertTrue("Wrong number of task files", files.size() == 1);
    List<AnswerPlaceholder> placeholders = files.get(0).getAnswerPlaceholders();
    assertTrue("Wrong number of placeholders", placeholders.size() == 1);
    Map<Integer, AnswerPlaceholderSubtaskInfo> infos = placeholders.get(0).getSubtaskInfos();
    assertNotNull(infos);
    assertEquals(Collections.singletonList("Type your name here."), infos.get(0).getHints());
    assertEquals("Liana", infos.get(0).getPossibleAnswer());
    return options;
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) AnswerPlaceholderSubtaskInfo(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) File(java.io.File)

Example 42 with TaskFile

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

the class PyCCCommandLineState method getCurrentTaskFilePath.

@Nullable
private String getCurrentTaskFilePath() {
    String textFile = null;
    for (Map.Entry<String, TaskFile> entry : myTask.getTaskFiles().entrySet()) {
        String path = getTaskFilePath(entry.getKey());
        if (!entry.getValue().getActivePlaceholders().isEmpty()) {
            return path;
        }
        VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(path);
        if (virtualFile == null) {
            continue;
        }
        if (TextEditorProvider.isTextFile(virtualFile)) {
            textFile = path;
        }
    }
    return textFile;
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable)

Example 43 with TaskFile

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

the class PyStudyCheckAction method getCheckTask.

@NotNull
private StudyCheckTask getCheckTask(@NotNull final Project project, final StudyState studyState, final StudyTestRunner testRunner, final Process testProcess, final String commandLine) {
    return new StudyCheckTask(project, studyState, myCheckInProgress, testProcess, commandLine) {

        @Override
        protected void onTaskFailed(@NotNull String message) {
            ApplicationManager.getApplication().invokeLater(() -> {
                if (myTaskDir == null)
                    return;
                myTask.setStatus(StudyStatus.Failed);
                for (Map.Entry<String, TaskFile> entry : myTask.getTaskFiles().entrySet()) {
                    final String name = entry.getKey();
                    final TaskFile taskFile = entry.getValue();
                    if (taskFile.getActivePlaceholders().size() < 2) {
                        continue;
                    }
                    final Course course = myTaskManger.getCourse();
                    if (course != null && EduNames.STUDY.equals(course.getCourseMode())) {
                        CommandProcessor.getInstance().runUndoTransparentAction(() -> ApplicationManager.getApplication().runWriteAction(() -> {
                            StudyCheckUtils.runSmartTestProcess(myTaskDir, testRunner, name, taskFile, project);
                        }));
                    }
                }
                final StudyToolWindow toolWindow = StudyUtils.getStudyToolWindow(project);
                if (toolWindow != null) {
                    final Course course = StudyTaskManager.getInstance(project).getCourse();
                    if (course != null) {
                        if (course.isAdaptive()) {
                            if (myTask.isChoiceTask()) {
                                StudyCheckUtils.showTestResultPopUp("Wrong answer", MessageType.ERROR.getPopupBackground(), project);
                            } else {
                                StudyCheckUtils.showTestResultPopUp("Wrong answer", MessageType.ERROR.getPopupBackground(), project);
                                StudyCheckUtils.showTestResultsToolWindow(project, message, false);
                            }
                            repaintChoicePanel(project, myTask);
                        } else {
                            StudyCheckUtils.showTestResultPopUp(message, MessageType.ERROR.getPopupBackground(), project);
                        }
                    }
                    StudyCheckUtils.navigateToFailedPlaceholder(myStudyState, myTask, myTaskDir, project);
                }
            });
        }
    };
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow) StudyCheckTask(com.jetbrains.edu.learning.checker.StudyCheckTask) Course(com.jetbrains.edu.learning.courseFormat.Course) NotNull(org.jetbrains.annotations.NotNull) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 44 with TaskFile

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

the class PyStudyCheckAction method getTaskVirtualFile.

@Nullable
private static VirtualFile getTaskVirtualFile(@NotNull final StudyState studyState, @NotNull final Task task, @NotNull final VirtualFile taskDir) {
    VirtualFile taskVirtualFile = studyState.getVirtualFile();
    for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
        String name = entry.getKey();
        TaskFile taskFile = entry.getValue();
        VirtualFile virtualFile = taskDir.findFileByRelativePath(name);
        if (virtualFile != null) {
            if (!taskFile.getActivePlaceholders().isEmpty()) {
                taskVirtualFile = virtualFile;
            }
        }
    }
    return taskVirtualFile;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable)

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