reorganize answer placeholder actions
[idea/community.git] / python / educational-core / course-creator / src / com / jetbrains / edu / coursecreator / actions / placeholder / CCEditAnswerPlaceholder.java
1 package com.jetbrains.edu.coursecreator.actions.placeholder;
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", "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.getTaskText(), answerPlaceholder.getHints());
30     dlg.setTitle("Edit Answer Placeholder");
31     if (dlg.showAndGet()) {
32       answerPlaceholder.setTaskText(dlg.getTaskText());
33       answerPlaceholder.setHints(dlg.getHints());
34     }
35   }
36
37   @Override
38   public void update(AnActionEvent e) {
39     Presentation presentation = e.getPresentation();
40     presentation.setEnabledAndVisible(false);
41     CCState state = getState(e);
42     if (state == null || state.getAnswerPlaceholder() == null) {
43       return;
44     }
45     presentation.setEnabledAndVisible(true);
46   }
47 }