07cd46cfdf200e8249564d2b0518d2c4007b9ee6
[idea/community.git] / python / educational-core / course-creator / src / com / jetbrains / edu / coursecreator / actions / CCHideFromStudent.java
1 package com.jetbrains.edu.coursecreator.actions;
2
3 import com.intellij.openapi.application.ApplicationManager;
4 import com.intellij.openapi.diagnostic.Logger;
5 import com.intellij.openapi.project.Project;
6 import com.intellij.openapi.vfs.VirtualFile;
7 import com.jetbrains.edu.learning.StudyUtils;
8 import com.jetbrains.edu.learning.courseFormat.Course;
9 import com.jetbrains.edu.learning.courseFormat.Task;
10 import com.jetbrains.edu.learning.courseFormat.TaskFile;
11
12 import java.io.IOException;
13 import java.util.Map;
14
15 public class CCHideFromStudent extends CCTaskFileActionBase {
16
17   private static final Logger LOG = Logger.getInstance(CCHideFromStudent.class);
18
19   @Override
20   protected void performAction(VirtualFile file, Task task, Course course, Project project) {
21     Map<String, TaskFile> taskFiles = task.getTaskFiles();
22     TaskFile taskFile = StudyUtils.getTaskFile(project, file);
23     if (taskFile == null) {
24       return;
25     }
26     String name = file.getName();
27     VirtualFile patternFile = StudyUtils.getPatternFile(taskFile, name);
28     ApplicationManager.getApplication().runWriteAction(() -> {
29       if (patternFile != null) {
30         try {
31           patternFile.delete(CCHideFromStudent.class);
32         }
33         catch (IOException e) {
34           LOG.info(e);
35         }
36       }
37     });
38     taskFiles.remove(name);
39   }
40
41   @Override
42   protected boolean isAvailable(Project project, VirtualFile file) {
43     return StudyUtils.getTaskFile(project, file) != null;
44   }
45 }