945026bd1ff9aa13cff76250db0d73cd1cbcd885
[idea/community.git] / python / educational-core / course-creator / src / com / jetbrains / edu / coursecreator / CCStudyActionListener.java
1 package com.jetbrains.edu.coursecreator;
2
3 import com.intellij.openapi.actionSystem.AnActionEvent;
4 import com.intellij.openapi.actionSystem.CommonDataKeys;
5 import com.intellij.openapi.project.Project;
6 import com.intellij.openapi.vfs.VirtualFile;
7 import com.jetbrains.edu.learning.StudyActionListener;
8 import com.jetbrains.edu.learning.StudyUtils;
9 import com.jetbrains.edu.learning.courseFormat.Task;
10 import com.jetbrains.edu.learning.courseFormat.TaskFile;
11
12 public class CCStudyActionListener implements StudyActionListener {
13   @Override
14   public void beforeCheck(AnActionEvent event) {
15     Project project = event.getProject();
16     if (project == null) {
17       return;
18     }
19     VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(event.getDataContext());
20     if (virtualFile == null) {
21       return;
22     }
23
24     TaskFile taskFile = StudyUtils.getTaskFile(project, virtualFile);
25     if (taskFile == null) {
26       return;
27     }
28
29     Task task = taskFile.getTask();
30     VirtualFile taskDir = StudyUtils.getTaskDir(virtualFile);
31     if (taskDir == null) {
32       return;
33     }
34     CCUtils.createResources(project, task, taskDir);
35   }
36 }