EDU-192 Actions from "course creator" plugin should be invisible in educational projects
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Thu, 25 Sep 2014 14:45:29 +0000 (18:45 +0400)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Thu, 25 Sep 2014 14:45:29 +0000 (18:45 +0400)
python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCProjectService.java
python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCAddTaskWindow.java
python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCCreateCourseArchive.java
python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCCreateLesson.java
python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCCreateTask.java
python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCCreateTaskFile.java
python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCRename.java
python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCShowPreview.java

index 1e755a162f728c752b6ef11314550bcaca2b7d0a..f38ae40471b78eedce71af87fe47636546b13ada 100644 (file)
@@ -16,6 +16,8 @@
 package org.jetbrains.plugins.coursecreator;
 
 import com.intellij.ide.projectView.ProjectView;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.Presentation;
 import com.intellij.openapi.components.PersistentStateComponent;
 import com.intellij.openapi.components.ServiceManager;
 import com.intellij.openapi.components.State;
@@ -183,4 +185,20 @@ public class CCProjectService implements PersistentStateComponent<Element> {
     int nameEnd = name.indexOf(".answer");
     return name.substring(0, nameEnd) + ".py";
   }
+
+  public static boolean setCCActionAvailable(@NotNull AnActionEvent e) {
+    final Presentation presentation = e.getPresentation();
+    final Project project = e.getProject();
+    if (project == null) {
+      return false;
+    }
+    if (getInstance(project).getCourse() == null) {
+      presentation.setVisible(false);
+      presentation.setEnabled(false);
+      return false;
+    }
+    presentation.setEnabled(true);
+    presentation.setVisible(true);
+    return true;
+  }
 }
index 212932f522dc63926c974050174f1322fada59bb..476b2481d7ab65648287ebcccc5fe2c945651b77 100644 (file)
@@ -66,6 +66,9 @@ public class CCAddTaskWindow extends DumbAwareAction {
 
   @Override
   public void update(@NotNull AnActionEvent event) {
+    if (!CCProjectService.setCCActionAvailable(event)) {
+      return;
+    }
     final Presentation presentation = event.getPresentation();
     final Project project = event.getData(CommonDataKeys.PROJECT);
     if (project == null) {
index 8fa9541c538bf3a68f6549b23b4c0c7d274cf314..3c45c251d8ce959e6ecd5d42153824671db65150 100644 (file)
@@ -47,6 +47,11 @@ public class CCCreateCourseArchive extends DumbAwareAction {
     super("Generate course archive", "Generate course archive", AllIcons.FileTypes.Archive);
   }
 
+  @Override
+  public void update(@NotNull AnActionEvent e) {
+    CCProjectService.setCCActionAvailable(e);
+  }
+
   @Override
   public void actionPerformed(AnActionEvent e) {
     final Project project = e.getData(CommonDataKeys.PROJECT);
index 5337ca383c11813a083f5531133f2195603c7f7c..bd7cb83ecc9911e2871a5f8da90da89f1b6c1bff 100644 (file)
@@ -13,6 +13,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.psi.PsiDirectory;
 import com.intellij.util.PlatformIcons;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.coursecreator.CCProjectService;
 import org.jetbrains.plugins.coursecreator.format.Course;
 import org.jetbrains.plugins.coursecreator.format.Lesson;
@@ -54,7 +55,10 @@ public class CCCreateLesson extends DumbAwareAction {
   }
 
   @Override
-  public void update(AnActionEvent event) {
+  public void update(@NotNull AnActionEvent event) {
+    if (!CCProjectService.setCCActionAvailable(event)) {
+      return;
+    }
     final Presentation presentation = event.getPresentation();
     final Project project = event.getData(CommonDataKeys.PROJECT);
     if (project == null) {
index 5ec8461b0007d2d8dbe82c0e9017c5b1581a9fd3..c194b8ba01b667612df3dce6f6ea567b009c8a69 100644 (file)
@@ -85,6 +85,9 @@ public class CCCreateTask extends DumbAwareAction {
 
   @Override
   public void update(@NotNull AnActionEvent event) {
+    if (!CCProjectService.setCCActionAvailable(event)) {
+      return;
+    }
     final Presentation presentation = event.getPresentation();
     final Project project = event.getData(CommonDataKeys.PROJECT);
     if (project == null) {
index 39f6991625e6d3bc76d420cb50f903729fd043c6..c4f396ad02e480e06c003dd00b2009d785061665 100644 (file)
@@ -17,6 +17,7 @@ import com.intellij.openapi.ui.Messages;
 import com.intellij.psi.PsiDirectory;
 import com.intellij.psi.PsiElement;
 import icons.PythonPsiApiIcons;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.coursecreator.CCProjectService;
 import org.jetbrains.plugins.coursecreator.format.Course;
 import org.jetbrains.plugins.coursecreator.format.Lesson;
@@ -74,7 +75,10 @@ public class CCCreateTaskFile extends DumbAwareAction {
   }
 
   @Override
-  public void update(AnActionEvent event) {
+  public void update(@NotNull AnActionEvent event) {
+    if (!CCProjectService.setCCActionAvailable(event)) {
+      return;
+    }
     final Presentation presentation = event.getPresentation();
     final Project project = event.getData(CommonDataKeys.PROJECT);
     if (project == null) {
index 321a86a5ba3528e61b1fa048e7acc044ee5d8a92..dbaee7590277d7e904f4965ac8085a72f7b9f541 100644 (file)
@@ -39,6 +39,9 @@ public abstract class CCRename extends DumbAwareAction {
 
   @Override
   public void update(@NotNull AnActionEvent event) {
+    if (!CCProjectService.setCCActionAvailable(event)) {
+      return;
+    }
     final Presentation presentation = event.getPresentation();
     final Project project = event.getData(CommonDataKeys.PROJECT);
     if (project == null) {
index b685af86126f0669d08f818dc5a63467f805b5fb..3d08f31461e959f45b9b5605caa458295b71459c 100644 (file)
@@ -41,6 +41,9 @@ public class CCShowPreview extends DumbAwareAction {
 
   @Override
   public void update(@NotNull AnActionEvent e) {
+    if (!CCProjectService.setCCActionAvailable(e)) {
+      return;
+    }
     Presentation presentation = e.getPresentation();
     presentation.setEnabled(false);
     presentation.setVisible(false);