EDU-600 Disable Refresh Task File/Answer Placeholder for course creator projects
authorliana.bakradze <liana.bakradze@jetbrains.com>
Mon, 25 Apr 2016 14:51:07 +0000 (16:51 +0200)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Mon, 25 Apr 2016 14:51:07 +0000 (16:51 +0200)
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyRefreshAnswerPlaceholder.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyRefreshTaskFileAction.java

index 7daa54735398c499dfc9c9064f846a9cf916a73b..7fbd271f1db18395e653fd9eb13e5cb8e3c0d751 100644 (file)
@@ -2,6 +2,7 @@ package com.jetbrains.edu.learning.actions;
 
 import com.intellij.icons.AllIcons;
 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;
@@ -11,7 +12,10 @@ import com.intellij.openapi.project.DumbAwareAction;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.TextRange;
 import com.jetbrains.edu.learning.StudyActionListener;
+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;
@@ -66,8 +70,24 @@ public class StudyRefreshAnswerPlaceholder extends DumbAwareAction {
 
   @Override
   public void update(AnActionEvent e) {
+    Presentation presentation = e.getPresentation();
+    presentation.setEnabledAndVisible(false);
+    Project project = e.getProject();
+    if (project == null) {
+      return;
+    }
+    Course course = StudyTaskManager.getInstance(project).getCourse();
+    if (course == null) {
+      return;
+    }
+
+    if (!EduNames.STUDY.equals(course.getCourseMode())) {
+      presentation.setVisible(true);
+      return;
+    }
+
     if (getAnswerPlaceholder(e) == null) {
-      e.getPresentation().setEnabledAndVisible(false);
+      presentation.setEnabledAndVisible(false);
     }
   }
 
index 3c8057c75deab9956aa1ccbdcb58d8d141983ab6..13eac8fc18acd8094cd93652df23a64ed96779b4 100644 (file)
@@ -4,6 +4,7 @@ import com.intellij.icons.AllIcons;
 import com.intellij.ide.projectView.ProjectView;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.KeyboardShortcut;
+import com.intellij.openapi.actionSystem.Presentation;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.command.CommandProcessor;
 import com.intellij.openapi.diagnostic.Logger;
@@ -25,7 +26,9 @@ import com.jetbrains.edu.learning.StudyState;
 import com.jetbrains.edu.learning.StudyTaskManager;
 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.courseFormat.AnswerPlaceholder;
+import com.jetbrains.edu.learning.courseFormat.Course;
 import com.jetbrains.edu.learning.courseFormat.StudyStatus;
 import com.jetbrains.edu.learning.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.editor.StudyEditor;
@@ -164,8 +167,19 @@ public class StudyRefreshTaskFileAction extends StudyActionWithShortcut {
     if (project != null) {
       StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
       StudyState studyState = new StudyState(studyEditor);
+      Presentation presentation = event.getPresentation();
       if (!studyState.isValid()) {
-        event.getPresentation().setEnabled(false);
+        presentation.setEnabled(false);
+        return;
+      }
+
+      Course course = StudyTaskManager.getInstance(project).getCourse();
+      if (course == null) {
+        return;
+      }
+      if (!EduNames.STUDY.equals(course.getCourseMode())) {
+        presentation.setVisible(true);
+        presentation.setEnabled(false);
       }
     }
   }