use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.
the class CCTaskMoveHandlerDelegate method isTaskDir.
private static boolean isTaskDir(PsiDirectory sourceDirectory) {
if (sourceDirectory == null) {
return false;
}
Project project = sourceDirectory.getProject();
Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null || !CCUtils.isCourseCreator(project)) {
return false;
}
return EduUtils.getTask(sourceDirectory, course) != null;
}
use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.
the class CCPushLesson method update.
@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabledAndVisible(false);
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
final Project project = e.getData(CommonDataKeys.PROJECT);
if (view == null || project == null) {
return;
}
final Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return;
}
if (!course.getCourseMode().equals(CCUtils.COURSE_MODE))
return;
PsiDirectory lessonDir = DirectoryChooserUtil.getOrChooseDirectory(view);
if (lessonDir == null || !lessonDir.getName().contains("lesson")) {
return;
}
final Lesson lesson = course.getLesson(lessonDir.getName());
if (lesson != null && course.getId() > 0) {
e.getPresentation().setEnabledAndVisible(true);
if (lesson.getId() <= 0) {
e.getPresentation().setText("Upload Lesson to Stepik");
}
}
}
use of com.jetbrains.edu.learning.courseFormat.Course in project intellij-community by JetBrains.
the class CCPushTask method update.
@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabledAndVisible(false);
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
final Project project = e.getData(CommonDataKeys.PROJECT);
if (view == null || project == null) {
return;
}
final Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return;
}
if (!course.getCourseMode().equals(CCUtils.COURSE_MODE))
return;
PsiDirectory taskDir = DirectoryChooserUtil.getOrChooseDirectory(view);
if (taskDir == null || !taskDir.getName().contains(EduNames.TASK)) {
return;
}
final PsiDirectory lessonDir = taskDir.getParentDirectory();
if (lessonDir == null)
return;
final Lesson lesson = course.getLesson(lessonDir.getName());
if (lesson != null && lesson.getId() > 0 && course.getId() > 0) {
e.getPresentation().setEnabledAndVisible(true);
final com.jetbrains.edu.learning.courseFormat.Task task = lesson.getTask(taskDir.getName());
if (task.getStepId() <= 0) {
e.getPresentation().setText("Upload Task to Stepik");
}
}
}
use of com.jetbrains.edu.learning.courseFormat.Course 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.Course in project intellij-community by JetBrains.
the class CCTaskDirectoryNode method modifyChildNode.
@Nullable
@Override
public AbstractTreeNode modifyChildNode(AbstractTreeNode childNode) {
AbstractTreeNode node = super.modifyChildNode(childNode);
if (node != null) {
return node;
}
Object value = childNode.getValue();
if (value instanceof PsiElement) {
PsiElement psiElement = (PsiElement) value;
PsiFile psiFile = psiElement.getContainingFile();
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile == null) {
return null;
}
if (StudyUtils.isTaskDescriptionFile(virtualFile.getName())) {
return null;
}
Course course = StudyTaskManager.getInstance(myProject).getCourse();
if (course == null) {
return null;
}
StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
if (manager == null) {
return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings);
}
if (!CCUtils.isTestsFile(myProject, virtualFile)) {
return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings);
}
if (!myTask.hasSubtasks()) {
return new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings, getTestNodeName(manager, psiElement));
}
String testFileName = getTestNodeName(manager, psiElement);
return isActiveSubtaskTest(virtualFile) ? new CCStudentInvisibleFileNode(myProject, psiFile, myViewSettings, testFileName) : null;
}
return null;
}
Aggregations