f524329ad4feba6e9cb91af0a3dbd7685af68397
[idea/community.git] / python / educational-core / course-creator / src / com / jetbrains / edu / coursecreator / actions / CCEditAnswerPlaceholder.java
1 package com.jetbrains.edu.coursecreator.actions;
2
3 import com.intellij.openapi.actionSystem.AnActionEvent;
4 import com.intellij.openapi.actionSystem.Presentation;
5 import com.intellij.openapi.project.Project;
6 import com.intellij.psi.PsiDirectory;
7 import com.intellij.psi.PsiFile;
8 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
9 import com.jetbrains.edu.learning.ui.CCCreateAnswerPlaceholderDialog;
10 import org.jetbrains.annotations.NotNull;
11
12 public class CCEditAnswerPlaceholder extends CCAnswerPlaceholderAction {
13
14   public CCEditAnswerPlaceholder() {
15     super("Edit Answer Placeholder", "Edit answer placeholder");
16   }
17
18   @Override
19   protected void performAnswerPlaceholderAction(@NotNull CCState state) {
20     final Project project = state.getProject();
21     PsiFile file = state.getFile();
22     final PsiDirectory taskDir = file.getContainingDirectory();
23     final PsiDirectory lessonDir = taskDir.getParent();
24     if (lessonDir == null) return;
25     AnswerPlaceholder answerPlaceholder = state.getAnswerPlaceholder();
26     if (answerPlaceholder == null) {
27       return;
28     }
29     CCCreateAnswerPlaceholderDialog dlg = new CCCreateAnswerPlaceholderDialog(project, answerPlaceholder
30     );
31     dlg.setTitle("Edit Answer Placeholder");
32     dlg.show();
33   }
34
35   @Override
36   public void update(AnActionEvent e) {
37     Presentation presentation = e.getPresentation();
38     presentation.setEnabledAndVisible(false);
39     CCState state = getState(e);
40     if (state == null || state.getAnswerPlaceholder() == null) {
41       return;
42     }
43     presentation.setEnabledAndVisible(true);
44   }
45 }