check for project type
[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     if (!CCUtils.isCourseCreator(project)) {
20       return;
21     }
22     VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(event.getDataContext());
23     if (virtualFile == null) {
24       return;
25     }
26
27     TaskFile taskFile = StudyUtils.getTaskFile(project, virtualFile);
28     if (taskFile == null) {
29       return;
30     }
31
32     Task task = taskFile.getTask();
33     VirtualFile taskDir = StudyUtils.getTaskDir(virtualFile);
34     if (taskDir == null) {
35       return;
36     }
37     CCUtils.createResources(project, task, taskDir);
38   }
39 }