EDU-602 Disable Fill Answer Placeholders action for course creator projects
authorliana.bakradze <liana.bakradze@jetbrains.com>
Mon, 25 Apr 2016 15:44:59 +0000 (17:44 +0200)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Mon, 25 Apr 2016 15:44:59 +0000 (17:44 +0200)
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyFillPlaceholdersAction.java

index 54c8e2c4ac08a2ef999413288d4ae26117f9bc57..73e0a9f20a9c2af09c0157725018ac395aa4d9ea 100644 (file)
@@ -2,11 +2,15 @@ package com.jetbrains.edu.learning.actions;
 
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.Presentation;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.command.CommandProcessor;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.project.Project;
+import com.jetbrains.edu.learning.StudyTaskManager;
+import com.jetbrains.edu.learning.core.EduNames;
 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
+import com.jetbrains.edu.learning.courseFormat.Course;
 import com.jetbrains.edu.learning.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.StudyState;
 import com.jetbrains.edu.learning.StudyUtils;
@@ -51,15 +55,23 @@ public class StudyFillPlaceholdersAction extends AnAction {
     StudyUtils.updateAction(e);
     final Project project = e.getProject();
     if (project != null) {
+
+      Course course = StudyTaskManager.getInstance(project).getCourse();
+      Presentation presentation = e.getPresentation();
+      if (course != null && !EduNames.STUDY.equals(course.getCourseMode())) {
+        presentation.setEnabled(false);
+        presentation.setVisible(true);
+        return;
+      }
       StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
       StudyState studyState = new StudyState(studyEditor);
       if (!studyState.isValid()) {
-        e.getPresentation().setEnabledAndVisible(false);
+        presentation.setEnabledAndVisible(false);
         return;
       }
       TaskFile taskFile = studyState.getTaskFile();
       if (taskFile.getAnswerPlaceholders().isEmpty()) {
-        e.getPresentation().setEnabledAndVisible(false);
+        presentation.setEnabledAndVisible(false);
       }
     }
   }