use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class CCVirtualFileListener method fileCreated.
@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
VirtualFile createdFile = event.getFile();
if (createdFile.isDirectory()) {
return;
}
if (createdFile.getPath().contains(CCUtils.GENERATED_FILES_FOLDER)) {
return;
}
Project project = ProjectUtil.guessProjectForFile(createdFile);
if (project == null) {
return;
}
if (project.getBasePath() != null && !FileUtil.isAncestor(project.getBasePath(), createdFile.getPath(), true)) {
return;
}
Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null || !CCUtils.isCourseCreator(project)) {
return;
}
TaskFile taskFile = StudyUtils.getTaskFile(project, createdFile);
if (taskFile != null) {
return;
}
String taskRelativePath = StudyUtils.pathRelativeToTask(createdFile);
CCLanguageManager manager = CCUtils.getStudyLanguageManager(course);
if (manager != null && manager.doNotPackFile(new File(createdFile.getPath()))) {
return;
}
if (CCUtils.isTestsFile(project, createdFile) || StudyUtils.isTaskDescriptionFile(createdFile.getName()) || taskRelativePath.contains(EduNames.WINDOW_POSTFIX) || taskRelativePath.contains(EduNames.WINDOWS_POSTFIX) || taskRelativePath.contains(EduNames.ANSWERS_POSTFIX)) {
return;
}
VirtualFile taskVF = StudyUtils.getTaskDir(createdFile);
if (taskVF == null) {
return;
}
Task task = StudyUtils.getTask(project, taskVF);
if (task == null) {
return;
}
CCUtils.createResourceFile(createdFile, course, taskVF);
task.addTaskFile(taskRelativePath, 1);
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class StudyEditorFactoryListener method editorCreated.
@Override
public void editorCreated(@NotNull final EditorFactoryEvent event) {
final Editor editor = event.getEditor();
final Project project = editor.getProject();
if (project == null) {
return;
}
final Document document = editor.getDocument();
final VirtualFile openedFile = FileDocumentManager.getInstance().getFile(document);
if (openedFile != null) {
final TaskFile taskFile = StudyUtils.getTaskFile(project, openedFile);
if (taskFile != null) {
WolfTheProblemSolver.getInstance(project).clearProblems(openedFile);
final ToolWindow studyToolWindow = ToolWindowManager.getInstance(project).getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW);
if (studyToolWindow != null) {
StudyUtils.updateToolWindows(project);
studyToolWindow.show(null);
}
Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return;
}
StudyEditor.addDocumentListener(document, new EduDocumentListener(taskFile, true));
if (!taskFile.getAnswerPlaceholders().isEmpty()) {
StudyNavigator.navigateToFirstAnswerPlaceholder(editor, taskFile);
boolean isStudyProject = EduNames.STUDY.equals(course.getCourseMode());
StudyUtils.drawAllAnswerPlaceholders(editor, taskFile);
if (isStudyProject) {
editor.addEditorMouseListener(new WindowSelectionListener(taskFile));
}
}
}
}
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class StudyRefreshAnswerPlaceholder method getAnswerPlaceholder.
@Nullable
private static AnswerPlaceholder getAnswerPlaceholder(AnActionEvent e) {
final Project project = e.getProject();
if (project == null) {
return null;
}
StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
final StudyState studyState = new StudyState(studyEditor);
if (studyEditor == null || !studyState.isValid()) {
return null;
}
final Editor editor = studyState.getEditor();
final TaskFile taskFile = studyState.getTaskFile();
return taskFile.getAnswerPlaceholder(editor.getCaretModel().getOffset());
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class StudyCheckUtils method drawAllPlaceholders.
public static void drawAllPlaceholders(@NotNull final Project project, @NotNull final Task task) {
VirtualFile taskDir = task.getTaskDir(project);
if (taskDir == null) {
return;
}
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) {
continue;
}
FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
if (fileEditor instanceof StudyEditor) {
StudyEditor studyEditor = (StudyEditor) fileEditor;
StudyUtils.drawAllAnswerPlaceholders(studyEditor.getEditor(), taskFile);
}
}
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class StudyCheckUtils method getCopyWithAnswers.
private static Pair<VirtualFile, TaskFile> getCopyWithAnswers(@NotNull final VirtualFile taskDir, @NotNull final VirtualFile file, @NotNull final TaskFile source) {
try {
VirtualFile answerFile = file.copy(taskDir, taskDir, file.getNameWithoutExtension() + EduNames.ANSWERS_POSTFIX + "." + file.getExtension());
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
final Document document = documentManager.getDocument(answerFile);
if (document != null) {
TaskFile answerTaskFile = source.getTask().copy().getTaskFile(StudyUtils.pathRelativeToTask(file));
if (answerTaskFile == null) {
return null;
}
EduDocumentListener listener = new EduDocumentListener(answerTaskFile);
document.addDocumentListener(listener);
for (AnswerPlaceholder answerPlaceholder : answerTaskFile.getActivePlaceholders()) {
final int start = answerPlaceholder.getOffset();
final int end = start + answerPlaceholder.getRealLength();
final String text = answerPlaceholder.getPossibleAnswer();
document.replaceString(start, end, text);
}
ApplicationManager.getApplication().runWriteAction(() -> documentManager.saveDocument(document));
return Pair.create(answerFile, answerTaskFile);
}
} catch (IOException e) {
LOG.error(e);
}
return null;
}
Aggregations