create resource files for created task files
[idea/community.git] / python / educational-core / course-creator / src / com / jetbrains / edu / coursecreator / actions / CCDeleteAnswerPlaceholder.java
1 package com.jetbrains.edu.coursecreator.actions;
2
3 import com.intellij.openapi.editor.Document;
4 import com.intellij.openapi.editor.Editor;
5 import com.intellij.openapi.project.Project;
6 import com.intellij.psi.PsiDocumentManager;
7 import com.intellij.psi.PsiFile;
8 import com.jetbrains.edu.learning.core.EduAnswerPlaceholderPainter;
9 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
10 import com.jetbrains.edu.learning.courseFormat.TaskFile;
11 import com.jetbrains.edu.coursecreator.CCProjectService;
12 import org.jetbrains.annotations.NotNull;
13
14 import java.util.List;
15
16 public class CCDeleteAnswerPlaceholder extends CCAnswerPlaceholderAction {
17
18   public CCDeleteAnswerPlaceholder() {
19     super("Delete Answer Placeholder","Delete answer placeholder", null);
20   }
21
22   @Override
23   protected void performAnswerPlaceholderAction(@NotNull CCState state) {
24     Project project = state.getProject();
25     PsiFile psiFile = state.getFile();
26     final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
27     if (document == null) return;
28     TaskFile taskFile = state.getTaskFile();
29     AnswerPlaceholder answerPlaceholder = state.getAnswerPlaceholder();
30     final List<AnswerPlaceholder> answerPlaceholders = taskFile.getAnswerPlaceholders();
31     if (answerPlaceholders.contains(answerPlaceholder)) {
32       answerPlaceholders.remove(answerPlaceholder);
33       final Editor editor = state.getEditor();
34       editor.getMarkupModel().removeAllHighlighters();
35       CCProjectService.getInstance(project).drawAnswerPlaceholders(psiFile.getVirtualFile(), editor);
36       EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile, false);
37     }
38   }
39 }