use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class CCGetCourseFromStepic method createCourse.
private static void createCourse(Project project, String courseId) {
final VirtualFile baseDir = project.getBaseDir();
final CourseInfo info = CCStepicConnector.getCourseInfo(courseId);
if (info == null)
return;
final Course course = EduStepicConnector.getCourse(project, info);
if (course != null) {
flushCourse(course);
final File courseDirectory = StudyUtils.getCourseDirectory(course);
ApplicationManager.getApplication().invokeAndWait(() -> ApplicationManager.getApplication().runWriteAction(() -> {
final VirtualFile[] children = baseDir.getChildren();
for (VirtualFile child : children) {
StudyUtils.deleteFile(child);
}
StudyGenerator.createCourse(course, baseDir, courseDirectory, project);
}));
StudyTaskManager.getInstance(project).setCourse(course);
File courseDir = new File(OUR_COURSES_DIR, course.getName() + "-" + project.getName());
course.setCourseDirectory(courseDir.getPath());
course.setCourseMode(CCUtils.COURSE_MODE);
project.getBaseDir().refresh(false, true);
int index = 1;
int taskIndex = 1;
for (Lesson lesson : course.getLessons()) {
final VirtualFile lessonDir = project.getBaseDir().findChild(EduNames.LESSON + String.valueOf(index));
lesson.setIndex(index);
if (lessonDir == null)
continue;
for (Task task : lesson.getTaskList()) {
final VirtualFile taskDir = lessonDir.findChild(EduNames.TASK + String.valueOf(taskIndex));
task.setIndex(taskIndex);
task.setLesson(lesson);
if (taskDir == null)
continue;
for (final Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
ApplicationManager.getApplication().invokeAndWait(() -> ApplicationManager.getApplication().runWriteAction(() -> createAnswerFile(project, taskDir, entry)));
}
taskIndex += 1;
}
index += 1;
taskIndex = 1;
}
course.initCourse(true);
ApplicationManager.getApplication().invokeAndWait(() -> StudyUtils.registerStudyToolWindow(course, project));
}
VirtualFileManager.getInstance().refreshWithoutFileWatcher(true);
ProjectView.getInstance(project).refresh();
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class CCHideFromStudent method performAction.
@Override
protected void performAction(VirtualFile file, Task task, Course course, Project project) {
TaskFile taskFile = StudyUtils.getTaskFile(project, file);
if (taskFile == null) {
return;
}
EduUtils.runUndoableAction(project, ACTION_NAME, new HideTaskFile(project, course, file, task, taskFile));
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile 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());
}
}
});
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class CCAddAnswerPlaceholder method canAddPlaceholder.
private static boolean canAddPlaceholder(@NotNull CCState state) {
Editor editor = state.getEditor();
SelectionModel selectionModel = editor.getSelectionModel();
TaskFile taskFile = state.getTaskFile();
if (selectionModel.hasSelection()) {
int start = selectionModel.getSelectionStart();
int end = selectionModel.getSelectionEnd();
return !arePlaceholdersIntersect(taskFile, start, end);
}
int offset = editor.getCaretModel().getOffset();
return StudyUtils.getAnswerPlaceholder(offset, taskFile.getAnswerPlaceholders()) == null;
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class CCAnswerPlaceholderAction method getState.
@Nullable
protected CCState getState(@NotNull AnActionEvent e) {
final Project project = e.getProject();
if (project == null || !CCUtils.isCourseCreator(project)) {
return null;
}
final PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(e.getDataContext());
if (psiFile == null) {
return null;
}
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile == null) {
return null;
}
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
if (editor == null) {
return null;
}
TaskFile taskFile = StudyUtils.getTaskFile(project, virtualFile);
if (taskFile == null) {
return null;
}
AnswerPlaceholder answerPlaceholder = StudyUtils.getAnswerPlaceholder(editor.getCaretModel().getOffset(), getPlaceholders(taskFile));
return new CCState(taskFile, answerPlaceholder, psiFile, editor, project);
}
Aggregations