isolate UI for better testability
[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.getTaskText(), answerPlaceholder.getHints());
30     dlg.setTitle("Edit Answer Placeholder");
31     dlg.show();
32   }
33
34   @Override
35   public void update(AnActionEvent e) {
36     Presentation presentation = e.getPresentation();
37     presentation.setEnabledAndVisible(false);
38     CCState state = getState(e);
39     if (state == null || state.getAnswerPlaceholder() == null) {
40       return;
41     }
42     presentation.setEnabledAndVisible(true);
43   }
44 }