rename edit answer placeholder action and fix action update
authorliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 7 Apr 2016 10:01:21 +0000 (13:01 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 7 Apr 2016 10:01:21 +0000 (13:01 +0300)
python/educational-core/course-creator/resources/META-INF/plugin.xml
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCEditAnswerPlaceholder.java [moved from python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCShowAnswerPlaceholderDetails.java with 62% similarity]

index 971a70b3b76c8c931ba1a775c2f5099919b9edf8..2e95149ee8a6f47c84325536433a782534948e38 100644 (file)
@@ -59,6 +59,7 @@
     <action id="AddTaskFile" class="com.jetbrains.edu.coursecreator.actions.CCAddAsTaskFile" text="Add As Task File">
       <add-to-group group-id="ProjectViewPopupMenu" anchor="first"/>
     </action>
+
     <group id="CCProjectViewGroup">
       <action id="DeleteAllPlaceholders" class="com.jetbrains.edu.coursecreator.actions.CCDeleteAllAnswerPlaceholdersAction"/>
       <separator/>
     </group>
 
     <group id="AnswerPlaceholderGroup">
+      <action id="EditAnswerPlaceholder" class="com.jetbrains.edu.coursecreator.actions.CCEditAnswerPlaceholder"/>
       <action id="AddTaskWindow" class="com.jetbrains.edu.coursecreator.actions.CCAddAnswerPlaceholder"/>
       <reference ref="DeleteAllPlaceholders"/>
       <separator/>
       <add-to-group group-id="EditorPopupMenu" anchor="first"/>
     </group>
+
     <action id="ShowTaskWindowDetails" class="com.jetbrains.edu.coursecreator.actions.CCShowAnswerPlaceholderDetails">
       <add-to-group group-id="EditorPopupMenu" anchor="before" relative-to-action="CopyReference"/>
     </action>
@@ -1,5 +1,7 @@
 package com.jetbrains.edu.coursecreator.actions;
 
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.Presentation;
 import com.intellij.openapi.project.Project;
 import com.intellij.psi.PsiDirectory;
 import com.intellij.psi.PsiFile;
@@ -7,9 +9,9 @@ import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.coursecreator.ui.CCCreateAnswerPlaceholderDialog;
 import org.jetbrains.annotations.NotNull;
 
-public class CCShowAnswerPlaceholderDetails extends CCAnswerPlaceholderAction {
+public class CCEditAnswerPlaceholder extends CCAnswerPlaceholderAction {
 
-  public CCShowAnswerPlaceholderDetails() {
+  public CCEditAnswerPlaceholder() {
     super("Edit Answer Placeholder", "Edit answer placeholder", null);
   }
 
@@ -21,9 +23,23 @@ public class CCShowAnswerPlaceholderDetails extends CCAnswerPlaceholderAction {
     final PsiDirectory lessonDir = taskDir.getParent();
     if (lessonDir == null) return;
     AnswerPlaceholder answerPlaceholder = state.getAnswerPlaceholder();
+    if (answerPlaceholder == null) {
+      return;
+    }
     CCCreateAnswerPlaceholderDialog dlg = new CCCreateAnswerPlaceholderDialog(project, answerPlaceholder
     );
     dlg.setTitle("Edit Answer Placeholder");
     dlg.show();
   }
+
+  @Override
+  public void update(AnActionEvent e) {
+    Presentation presentation = e.getPresentation();
+    presentation.setEnabledAndVisible(false);
+    CCState state = getState(e);
+    if (state == null || state.getAnswerPlaceholder() == null) {
+      return;
+    }
+    presentation.setEnabledAndVisible(true);
+  }
 }
\ No newline at end of file