Search in sources :

Example 36 with TaskFile

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

the class StudyCheckUtils method navigateToFailedPlaceholder.

public static void navigateToFailedPlaceholder(@NotNull final StudyState studyState, @NotNull final Task task, @NotNull final VirtualFile taskDir, @NotNull final Project project) {
    TaskFile selectedTaskFile = studyState.getTaskFile();
    Editor editor = studyState.getEditor();
    TaskFile taskFileToNavigate = selectedTaskFile;
    VirtualFile fileToNavigate = studyState.getVirtualFile();
    final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
    if (!taskManager.hasFailedAnswerPlaceholders(selectedTaskFile)) {
        for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
            String name = entry.getKey();
            TaskFile taskFile = entry.getValue();
            if (taskManager.hasFailedAnswerPlaceholders(taskFile)) {
                taskFileToNavigate = taskFile;
                VirtualFile virtualFile = taskDir.findFileByRelativePath(name);
                if (virtualFile == null) {
                    continue;
                }
                FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
                if (fileEditor instanceof StudyEditor) {
                    StudyEditor studyEditor = (StudyEditor) fileEditor;
                    editor = studyEditor.getEditor();
                }
                fileToNavigate = virtualFile;
                break;
            }
        }
    }
    if (fileToNavigate != null) {
        FileEditorManager.getInstance(project).openFile(fileToNavigate, true);
    }
    final Editor editorToNavigate = editor;
    ApplicationManager.getApplication().invokeLater(() -> IdeFocusManager.getInstance(project).requestFocus(editorToNavigate.getContentComponent(), true));
    StudyNavigator.navigateToFirstFailedAnswerPlaceholder(editor, taskFileToNavigate);
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StudyTaskManager(com.jetbrains.edu.learning.StudyTaskManager) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Map(java.util.Map)

Example 37 with TaskFile

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

the class StudyCheckUtils method runSmartTestProcess.

public static void runSmartTestProcess(@NotNull final VirtualFile taskDir, @NotNull final StudyTestRunner testRunner, @NotNull final String taskFileName, @NotNull final TaskFile taskFile, @NotNull final Project project) {
    final VirtualFile virtualFile = taskDir.findFileByRelativePath(taskFileName);
    if (virtualFile == null) {
        return;
    }
    Pair<VirtualFile, TaskFile> pair = getCopyWithAnswers(taskDir, virtualFile, taskFile);
    if (pair == null) {
        return;
    }
    VirtualFile answerFile = pair.getFirst();
    TaskFile answerTaskFile = pair.getSecond();
    try {
        for (final AnswerPlaceholder answerPlaceholder : answerTaskFile.getActivePlaceholders()) {
            final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
            if (document == null) {
                continue;
            }
            StudySmartChecker.smartCheck(answerPlaceholder, project, answerFile, answerTaskFile, taskFile, testRunner, virtualFile, document);
        }
    } finally {
        StudyUtils.deleteFile(answerFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) Document(com.intellij.openapi.editor.Document)

Example 38 with TaskFile

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

the class CCAddAnswerPlaceholder method addPlaceholder.

private void addPlaceholder(@NotNull CCState state) {
    Editor editor = state.getEditor();
    Project project = state.getProject();
    Document document = editor.getDocument();
    FileDocumentManager.getInstance().saveDocument(document);
    final SelectionModel model = editor.getSelectionModel();
    final int offset = model.hasSelection() ? model.getSelectionStart() : editor.getCaretModel().getOffset();
    TaskFile taskFile = state.getTaskFile();
    int subtaskIndex = state.getTaskFile().getTask().getActiveSubtaskIndex();
    final AnswerPlaceholder answerPlaceholder = new AnswerPlaceholder();
    AnswerPlaceholderSubtaskInfo info = new AnswerPlaceholderSubtaskInfo();
    answerPlaceholder.getSubtaskInfos().put(subtaskIndex, info);
    int index = taskFile.getAnswerPlaceholders().size();
    answerPlaceholder.setIndex(index);
    answerPlaceholder.setTaskFile(taskFile);
    taskFile.sortAnswerPlaceholders();
    answerPlaceholder.setOffset(offset);
    answerPlaceholder.setUseLength(false);
    String defaultPlaceholderText = "type here";
    CCCreateAnswerPlaceholderDialog dlg = createDialog(project, answerPlaceholder);
    if (!dlg.showAndGet()) {
        return;
    }
    String answerPlaceholderText = dlg.getTaskText();
    answerPlaceholder.setPossibleAnswer(model.hasSelection() ? model.getSelectedText() : defaultPlaceholderText);
    answerPlaceholder.setTaskText(StringUtil.notNullize(answerPlaceholderText));
    answerPlaceholder.setLength(StringUtil.notNullize(answerPlaceholderText).length());
    answerPlaceholder.setHints(dlg.getHints());
    if (!model.hasSelection()) {
        DocumentUtil.writeInRunUndoTransparentAction(() -> document.insertString(offset, defaultPlaceholderText));
    }
    answerPlaceholder.setPossibleAnswer(model.hasSelection() ? model.getSelectedText() : defaultPlaceholderText);
    AddAction action = new AddAction(answerPlaceholder, taskFile, editor);
    EduUtils.runUndoableAction(project, "Add Answer Placeholder", action);
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) AnswerPlaceholderSubtaskInfo(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo) SelectionModel(com.intellij.openapi.editor.SelectionModel) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document)

Example 39 with TaskFile

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

the class CCTaskFileActionTest method testHideTaskFile.

public void testHideTaskFile() {
    VirtualFile virtualFile = configureByTaskFile("taskFile.txt");
    launchAction(virtualFile, new CCHideFromStudent());
    assertNull(StudyUtils.getTaskFile(getProject(), virtualFile));
    UndoManager.getInstance(getProject()).undo(FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile));
    TaskFile taskFile = StudyUtils.getTaskFile(getProject(), virtualFile);
    assertNotNull(taskFile);
    checkHighlighters(taskFile, myFixture.getEditor().getMarkupModel());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile)

Example 40 with TaskFile

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

the class StudyAnswerPlaceholderExtendWordHandler method getAnswerPlaceholder.

@Nullable
private static AnswerPlaceholder getAnswerPlaceholder(PsiElement e, int offset) {
    PsiFile file = e.getContainingFile();
    if (file == null) {
        return null;
    }
    VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null) {
        return null;
    }
    TaskFile taskFile = StudyUtils.getTaskFile(e.getProject(), virtualFile);
    if (taskFile == null) {
        return null;
    }
    Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
    if (document == null) {
        return null;
    }
    Editor editor = FileEditorManager.getInstance(e.getProject()).getSelectedTextEditor();
    return editor == null ? null : taskFile.getAnswerPlaceholder(offset);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) Editor(com.intellij.openapi.editor.Editor) 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