EDU-595 Disable task navigation actions if no task to navigate to
authorliana.bakradze <liana.bakradze@jetbrains.com>
Tue, 26 Apr 2016 13:12:19 +0000 (15:12 +0200)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Tue, 26 Apr 2016 13:14:22 +0000 (15:14 +0200)
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyNextStudyTaskAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyPreviousStudyTaskAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyTaskNavigationAction.java

index 1cd6548274f30d4092fd478c61c635045c0f3966..1177caa53fcc5fb50ddf760c76b3b546fff7ddef 100644 (file)
@@ -19,11 +19,6 @@ public class StudyNextStudyTaskAction extends StudyTaskNavigationAction {
     super("Next Task (" + KeymapUtil.getShortcutText(new KeyboardShortcut(KeyStroke.getKeyStroke(SHORTCUT), null)) + ")", "Navigate to the next task", AllIcons.Actions.Forward);
   }
 
-  @Override
-  protected String getNavigationFinishedMessage() {
-    return "It's the last task";
-  }
-
   @Override
   protected Task getTargetTask(@NotNull final Task sourceTask) {
     return StudyNavigator.nextTask(sourceTask);
index 653f00fd4b7d0ac94c003f70d72a5626ee0e8065..f9b339af6dff47aad63dde6bd41ea13cb5e8213c 100644 (file)
@@ -19,11 +19,6 @@ public class StudyPreviousStudyTaskAction extends StudyTaskNavigationAction {
   public static final String ACTION_ID = "PreviousTaskAction";
   public static final String SHORTCUT = "ctrl pressed COMMA";
 
-  @Override
-  protected String getNavigationFinishedMessage() {
-    return "It's already the first task";
-  }
-
   @Override
   protected Task getTargetTask(@NotNull final Task sourceTask) {
     return StudyNavigator.previousTask(sourceTask);
index 308a423d68f6833a4b309cf56afee0d9eeff2e08..363e73e37018d7e2027c15711f58363737a32850 100644 (file)
@@ -4,20 +4,16 @@ import com.intellij.ide.projectView.ProjectView;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.fileEditor.FileEditorManager;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.MessageType;
-import com.intellij.openapi.ui.popup.Balloon;
-import com.intellij.openapi.ui.popup.BalloonBuilder;
-import com.intellij.openapi.ui.popup.JBPopupFactory;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.wm.ToolWindow;
 import com.intellij.openapi.wm.ToolWindowId;
 import com.intellij.openapi.wm.ToolWindowManager;
 import com.intellij.util.ui.tree.TreeUtil;
+import com.jetbrains.edu.learning.StudyState;
+import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.core.EduNames;
 import com.jetbrains.edu.learning.courseFormat.Task;
 import com.jetbrains.edu.learning.courseFormat.TaskFile;
-import com.jetbrains.edu.learning.StudyState;
-import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.editor.StudyEditor;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -40,11 +36,6 @@ abstract public class StudyTaskNavigationAction extends StudyActionWithShortcut
     }
     Task nextTask = getTargetTask(studyState.getTask());
     if (nextTask == null) {
-      BalloonBuilder balloonBuilder =
-        JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(getNavigationFinishedMessage(), MessageType.INFO, null);
-      Balloon balloon = balloonBuilder.createBalloon();
-      assert studyEditor != null;
-      balloon.show(StudyUtils.computeLocation(studyEditor.getEditor()), Balloon.Position.above);
       return;
     }
     for (VirtualFile file : FileEditorManager.getInstance(project).getOpenFiles()) {
@@ -122,12 +113,22 @@ abstract public class StudyTaskNavigationAction extends StudyActionWithShortcut
     navigateTask(project);
   }
 
-  protected abstract String getNavigationFinishedMessage();
-
   protected abstract Task getTargetTask(@NotNull final Task sourceTask);
 
   @Override
   public void update(AnActionEvent e) {
     StudyUtils.updateAction(e);
+    Project project = e.getProject();
+    if (project == null) {
+      return;
+    }
+    StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
+    StudyState studyState = new StudyState(studyEditor);
+    if (!studyState.isValid()) {
+      return;
+    }
+    if (getTargetTask(studyState.getTask()) == null) {
+      e.getPresentation().setEnabled(false);
+    }
   }
 }