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);
}
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);
}
}
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);
}
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());
}
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);
}
Aggregations