reorganize answer placeholder actions
authorLiana.Bakradze <liana.bakradze@jetbrains.com>
Fri, 11 Nov 2016 11:18:08 +0000 (14:18 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 17 Nov 2016 14:08:43 +0000 (17:08 +0300)
python/educational-core/course-creator/resources/META-INF/plugin.xml
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCAnswerPlaceholderActionGroup.java [new file with mode: 0644]
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/placeholder/CCActivatePlaceholder.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/placeholder/CCAddAnswerPlaceholder.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/placeholder/CCDeactivatePlaceholder.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/placeholder/CCDeleteAllAnswerPlaceholdersAction.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/placeholder/CCDeleteAnswerPlaceholder.java [new file with mode: 0644]
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/placeholder/CCEditAnswerPlaceholder.java
python/educational-core/course-creator/testSrc/com/jetbrains/edu/coursecreator/actions/CCAnswerPlaceholderActionTest.java

index 2491e1cde81cb601624d4aef11eaa1e5f0744b13..05df2d0152e981a848ab01b506b4428537eac908 100644 (file)
       <add-to-group group-id="FileMenu" relative-to-action="FileMainSettingsGroup" anchor="before"/>
     </group>
 
-    <group id="AnswerPlaceholderGroup">
+    <action id="AddTaskWindow" class="com.jetbrains.edu.coursecreator.actions.placeholder.CCAddAnswerPlaceholder">
+      <add-to-group group-id="EditorPopupMenu" anchor="first"/>
+    </action>
+
+    <group id="AnswerPlaceholderGroup" popup="true" text="Answer Placeholder" class="com.jetbrains.edu.coursecreator.CCAnswerPlaceholderActionGroup">
       <action id="CC.HideFromPrevSubtasks" class="com.jetbrains.edu.coursecreator.actions.placeholder.CCHidePlaceholderFromPrevSubtasks"/>
       <action id="CC.MakeVisibleFromPrevSubtasks" class="com.jetbrains.edu.coursecreator.actions.placeholder.CCMakeVisibleForPrevSubtasks"/>
       <action id="CC.ActivatePlaceholder" class="com.jetbrains.edu.coursecreator.actions.placeholder.CCActivatePlaceholder"/>
       <action id="CC.DeactivatePlaceholder" class="com.jetbrains.edu.coursecreator.actions.placeholder.CCDeactivatePlaceholder" />
       <action id="EditAnswerPlaceholder" class="com.jetbrains.edu.coursecreator.actions.placeholder.CCEditAnswerPlaceholder"/>
-      <action id="AddTaskWindow" class="com.jetbrains.edu.coursecreator.actions.placeholder.CCAddAnswerPlaceholder"/>
+      <action id="DeleteAnswerPlaceholder" class="com.jetbrains.edu.coursecreator.actions.placeholder.CCDeleteAnswerPlaceholder" />
       <action id="DeleteAllPlaceholders" class="com.jetbrains.edu.coursecreator.actions.placeholder.CCDeleteAllAnswerPlaceholdersAction"/>
-      <separator/>
-      <add-to-group group-id="EditorPopupMenu" anchor="first"/>
+      <add-to-group group-id="EditorPopupMenu" anchor="after" relative-to-action="AddTaskWindow"/>
     </group>
 
     <action id="UnpackCourse" class="com.jetbrains.edu.coursecreator.actions.CCFromCourseArchive"/>
     <action id="GetCourse" class="com.jetbrains.edu.coursecreator.actions.CCGetCourseFromStepic"/>
-    <action class="com.jetbrains.edu.coursecreator.actions.CCNewSubtaskAction" id="CC.NewStep">
-      <add-to-group group-id="AnswerPlaceholderGroup" relative-to-action="DeleteAllPlaceholders" anchor="after"/>
-    </action>
+    <group id="CC.AddSubtaskGroup">
+      <action class="com.jetbrains.edu.coursecreator.actions.CCNewSubtaskAction" id="CC.NewStep"/>
+      <separator/>
+      <add-to-group group-id="EditorPopupMenu" relative-to-action="AnswerPlaceholderGroup" anchor="after"/>
+    </group>
   </actions>
 
 
diff --git a/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCAnswerPlaceholderActionGroup.java b/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCAnswerPlaceholderActionGroup.java
new file mode 100644 (file)
index 0000000..27e915e
--- /dev/null
@@ -0,0 +1,12 @@
+package com.jetbrains.edu.coursecreator;
+
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.DefaultActionGroup;
+import com.intellij.openapi.project.DumbAware;
+
+public class CCAnswerPlaceholderActionGroup extends DefaultActionGroup implements DumbAware {
+  @Override
+  public void update(AnActionEvent e) {
+    CCUtils.updateActionGroup(e);
+  }
+}
index cf45d2c02812a10a813209f042c2276e330257aa..e34d3246ec763c0569e96b9d651e7a5544828cd9 100644 (file)
@@ -7,7 +7,7 @@ import com.jetbrains.edu.learning.courseFormat.TaskFile;
 
 public class CCActivatePlaceholder extends CCSubtaskPlaceholderAction {
 
-  public static final String TITLE = "Activate Answer Placeholder";
+  public static final String TITLE = "Activate";
 
   protected CCActivatePlaceholder() {
     super(TITLE, TITLE);
index 2d6faf38ded845c761f8d5308f38ad4170380db8..d7220ff519190687523ace32894f45f1f0c3907a 100644 (file)
@@ -14,7 +14,6 @@ import com.intellij.ui.JBColor;
 import com.intellij.util.DocumentUtil;
 import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.core.EduAnswerPlaceholderPainter;
-import com.jetbrains.edu.learning.core.EduNames;
 import com.jetbrains.edu.learning.core.EduUtils;
 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo;
@@ -27,7 +26,7 @@ import java.util.List;
 public class CCAddAnswerPlaceholder extends CCAnswerPlaceholderAction {
 
   public CCAddAnswerPlaceholder() {
-    super("Add/Delete Answer Placeholder", "Add/Delete answer placeholder");
+    super("Add Answer Placeholder", "Add/Delete answer placeholder");
   }
 
 
@@ -116,30 +115,7 @@ public class CCAddAnswerPlaceholder extends CCAnswerPlaceholderAction {
 
   @Override
   protected void performAnswerPlaceholderAction(@NotNull CCState state) {
-    if (canAddPlaceholder(state)) {
-      addPlaceholder(state);
-      return;
-    }
-    if (canDeletePlaceholder(state)) {
-      deletePlaceholder(state);
-    }
-  }
-
-  private static void deletePlaceholder(@NotNull CCState state) {
-    Project project = state.getProject();
-    TaskFile taskFile = state.getTaskFile();
-    AnswerPlaceholder answerPlaceholder = state.getAnswerPlaceholder();
-    EduUtils.runUndoableAction(project, "Delete Answer Placeholder", new AddAction(answerPlaceholder, taskFile, state.getEditor()) {
-      @Override
-      public void undo() throws UnexpectedUndoException {
-        super.redo();
-      }
-
-      @Override
-      public void redo() throws UnexpectedUndoException {
-        super.undo();
-      }
-    });
+    addPlaceholder(state);
   }
 
   @Override
@@ -153,9 +129,8 @@ public class CCAddAnswerPlaceholder extends CCAnswerPlaceholderAction {
     }
 
     presentation.setVisible(true);
-    if (canAddPlaceholder(state) || canDeletePlaceholder(state)) {
+    if (canAddPlaceholder(state)) {
       presentation.setEnabled(true);
-      presentation.setText((state.getAnswerPlaceholder() == null ? "Add " : "Delete ") + EduNames.ANSWER_PLACEHOLDER);
     }
   }
 
@@ -173,13 +148,6 @@ public class CCAddAnswerPlaceholder extends CCAnswerPlaceholderAction {
     return taskFile.getAnswerPlaceholder(offset, taskFile.getAnswerPlaceholders()) == null;
   }
 
-  private static boolean canDeletePlaceholder(@NotNull CCState state) {
-    if (state.getEditor().getSelectionModel().hasSelection()) {
-      return false;
-    }
-    return state.getAnswerPlaceholder() != null;
-  }
-
   protected CCCreateAnswerPlaceholderDialog createDialog(Project project, AnswerPlaceholder answerPlaceholder) {
     String answerPlaceholderText = StringUtil.notNullize(answerPlaceholder.getTaskText());
     return new CCCreateAnswerPlaceholderDialog(project, answerPlaceholderText.isEmpty() ? "type here" : answerPlaceholderText,
index 79713d4c60cf63e1d76660b56a32a08b544223aa..75db3a889eaa48cb8c9f37598c79ffc6e6446221 100644 (file)
@@ -8,7 +8,7 @@ import java.util.Collections;
 
 public class CCDeactivatePlaceholder extends CCSubtaskPlaceholderAction {
 
-  public static final String TITLE = "Deactivate Answer Placeholder";
+  public static final String TITLE = "Deactivate";
 
   protected CCDeactivatePlaceholder() {
     super(TITLE, TITLE);
index 7decdd46bd42fbea9b4f7963e135e26d6a2c30da..4c232db34d02c42c41b57a46d5ea57f6223dbb0c 100644 (file)
@@ -16,7 +16,6 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.jetbrains.edu.coursecreator.CCUtils;
 import com.jetbrains.edu.learning.StudyUtils;
-import com.jetbrains.edu.learning.core.EduNames;
 import com.jetbrains.edu.learning.core.EduUtils;
 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.learning.courseFormat.TaskFile;
@@ -27,7 +26,7 @@ import java.util.List;
 
 public class CCDeleteAllAnswerPlaceholdersAction extends DumbAwareAction {
 
-  public static final String ACTION_NAME = "Delete All " + EduNames.ANSWER_PLACEHOLDER + "s";
+  public static final String ACTION_NAME = "Delete All";
 
   public CCDeleteAllAnswerPlaceholdersAction() {
     super(ACTION_NAME);
diff --git a/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/placeholder/CCDeleteAnswerPlaceholder.java b/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/placeholder/CCDeleteAnswerPlaceholder.java
new file mode 100644 (file)
index 0000000..559385f
--- /dev/null
@@ -0,0 +1,63 @@
+package com.jetbrains.edu.coursecreator.actions.placeholder;
+
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.Presentation;
+import com.intellij.openapi.command.undo.UnexpectedUndoException;
+import com.intellij.openapi.project.Project;
+import com.jetbrains.edu.learning.core.EduUtils;
+import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
+import com.jetbrains.edu.learning.courseFormat.TaskFile;
+import org.jetbrains.annotations.NotNull;
+
+public class CCDeleteAnswerPlaceholder extends CCAnswerPlaceholderAction {
+  public CCDeleteAnswerPlaceholder() {
+    super("Delete", "Delete answer placeholder");
+  }
+
+  @Override
+  protected void performAnswerPlaceholderAction(@NotNull CCState state) {
+    deletePlaceholder(state);
+  }
+
+  private static void deletePlaceholder(@NotNull CCState state) {
+    Project project = state.getProject();
+    TaskFile taskFile = state.getTaskFile();
+    AnswerPlaceholder answerPlaceholder = state.getAnswerPlaceholder();
+    EduUtils.runUndoableAction(project, "Delete Answer Placeholder", new CCAddAnswerPlaceholder.AddAction(answerPlaceholder, taskFile, state.getEditor()) {
+      @Override
+      public void undo() throws UnexpectedUndoException {
+        super.redo();
+      }
+
+      @Override
+      public void redo() throws UnexpectedUndoException {
+        super.undo();
+      }
+    });
+  }
+
+
+
+  private static boolean canDeletePlaceholder(@NotNull CCState state) {
+    if (state.getEditor().getSelectionModel().hasSelection()) {
+      return false;
+    }
+    return state.getAnswerPlaceholder() != null;
+  }
+
+  @Override
+  public void update(@NotNull AnActionEvent event) {
+    final Presentation presentation = event.getPresentation();
+    presentation.setEnabledAndVisible(false);
+
+    CCState state = getState(event);
+    if (state == null) {
+      return;
+    }
+
+    if (canDeletePlaceholder(state)) {
+      presentation.setEnabledAndVisible(true);
+    }
+  }
+
+}
index 85a2c91fa774dd62e80bb0739a5d450c4ca28613..11fac1e9b0187e44c0303ebdf7402d22512b292a 100644 (file)
@@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
 public class CCEditAnswerPlaceholder extends CCAnswerPlaceholderAction {
 
   public CCEditAnswerPlaceholder() {
-    super("Edit Answer Placeholder", "Edit answer placeholder");
+    super("Edit", "Edit answer placeholder");
   }
 
   @Override
index d7c9a8fbc5b8b242bae40c8b3787423573db418d..ba28df0f981777661f6c80a9bb66b3d758b6e3fa 100644 (file)
@@ -1,5 +1,6 @@
 package com.jetbrains.edu.coursecreator.actions;
 
+import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.Presentation;
 import com.intellij.openapi.command.undo.UndoManager;
 import com.intellij.openapi.fileEditor.FileEditorManager;
@@ -8,6 +9,7 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.jetbrains.edu.coursecreator.CCTestCase;
 import com.jetbrains.edu.coursecreator.CCTestsUtil;
 import com.jetbrains.edu.coursecreator.actions.placeholder.CCAddAnswerPlaceholder;
+import com.jetbrains.edu.coursecreator.actions.placeholder.CCDeleteAnswerPlaceholder;
 import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.learning.courseFormat.TaskFile;
@@ -40,11 +42,11 @@ public class CCAnswerPlaceholderActionTest extends CCTestCase {
   }
 
   public void testPlaceholderWithSelection() {
-    doTest("onePlaceholder");
+    doTest("onePlaceholder", new CCTestAction());
   }
 
   public void testPlaceholderWithoutSelection() {
-    doTest("withoutSelection");
+    doTest("withoutSelection", new CCTestAction());
   }
 
   public void testPlaceholderIntersection() {
@@ -54,12 +56,12 @@ public class CCAnswerPlaceholderActionTest extends CCTestCase {
   }
 
   public void testPlaceholderDeleted() {
-    doTest("deletePlaceholder");
+    doTest("deletePlaceholder", new CCDeleteAnswerPlaceholder());
   }
 
-  private void doTest(String name) {
+  private void doTest(String name, AnAction action) {
     VirtualFile virtualFile = configureByTaskFile(name + CCTestsUtil.BEFORE_POSTFIX);
-    myFixture.testAction(new CCTestAction());
+    myFixture.testAction(action);
     TaskFile taskFile = StudyUtils.getTaskFile(getProject(), virtualFile);
     checkByFile(taskFile, name + CCTestsUtil.AFTER_POSTFIX, false);
     checkHighlighters(taskFile, myFixture.getEditor().getMarkupModel());