Fix #EDU-565 The shortcut for "check task" doesn't work
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Mon, 14 Mar 2016 11:33:43 +0000 (14:33 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Mon, 14 Mar 2016 11:38:25 +0000 (14:38 +0300)
Create super class for all toolbar action, so they provide action id and action shortcut to be added

16 files changed:
python/educational-core/student/resources/META-INF/plugin.xml
python/educational-core/student/src/com/jetbrains/edu/learning/StudyInstructionPainter.java [deleted file]
python/educational-core/student/src/com/jetbrains/edu/learning/StudyProjectComponent.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyCheckAction.java [deleted file]
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyNextStudyTaskAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyNextWindowAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyPrevWindowAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyPreviousStudyTaskAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyRefreshTaskFileAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyShowHintAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyTaskNavigationAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyToolbarAction.java [new file with mode: 0644]
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyWindowNavigationAction.java
python/educational-python/student-python/resources/META-INF/plugin.xml
python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyCheckAction.java
python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyInstructionPainter.java [new file with mode: 0644]

index 823ec10abf07052f4c2bad3aeb917dbc7c833d69..a5b1080c1508b4985c932d327af9aef2a9cfa72c 100644 (file)
     <action id="Edu.NewScratchFile" class="com.intellij.ide.scratch.ScratchFileActions$NewFileAction" text="New Scratch File...">
       <add-to-group group-id="FileOpenGroup" relative-to-action="OpenFile" anchor="before"/>
     </action>
     <action id="Edu.NewScratchFile" class="com.intellij.ide.scratch.ScratchFileActions$NewFileAction" text="New Scratch File...">
       <add-to-group group-id="FileOpenGroup" relative-to-action="OpenFile" anchor="before"/>
     </action>
-
-    <action id="CheckAction" class="com.jetbrains.edu.learning.actions.StudyCheckAction"  text="Check Task"
-            description="Check current task">
-    </action>
     <action id="PrevWindowAction" class="com.jetbrains.edu.learning.actions.StudyPrevWindowAction" text="Previous Answer Placeholder"
             description="Navigate to the previous answer placeholder">
     </action>
     <action id="PrevWindowAction" class="com.jetbrains.edu.learning.actions.StudyPrevWindowAction" text="Previous Answer Placeholder"
             description="Navigate to the previous answer placeholder">
     </action>
@@ -96,7 +92,5 @@
     <extendWordSelectionHandler implementation="com.jetbrains.edu.learning.StudyAnswerPlaceholderExtendWordHandler"/>
     <renameHandler implementation="com.jetbrains.edu.learning.StudyRenameHandler"/>
     <refactoring.moveHandler implementation="com.jetbrains.edu.learning.StudyMoveDelegate" order="first"/>
     <extendWordSelectionHandler implementation="com.jetbrains.edu.learning.StudyAnswerPlaceholderExtendWordHandler"/>
     <renameHandler implementation="com.jetbrains.edu.learning.StudyRenameHandler"/>
     <refactoring.moveHandler implementation="com.jetbrains.edu.learning.StudyMoveDelegate" order="first"/>
-    <applicationService serviceInterface="com.intellij.openapi.fileEditor.impl.EditorEmptyTextPainter"
-                        serviceImplementation="com.jetbrains.edu.learning.StudyInstructionPainter" overrides="true"/>
   </extensions>
 </idea-plugin>
\ No newline at end of file
   </extensions>
 </idea-plugin>
\ No newline at end of file
diff --git a/python/educational-core/student/src/com/jetbrains/edu/learning/StudyInstructionPainter.java b/python/educational-core/student/src/com/jetbrains/edu/learning/StudyInstructionPainter.java
deleted file mode 100644 (file)
index dcd476a..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.jetbrains.edu.learning;
-
-import com.intellij.openapi.actionSystem.KeyboardShortcut;
-import com.intellij.openapi.fileEditor.impl.EditorEmptyTextPainter;
-import com.intellij.openapi.keymap.KeymapUtil;
-import com.intellij.util.PlatformUtils;
-import com.intellij.util.ui.UIUtil;
-import com.jetbrains.edu.learning.actions.*;
-import com.jetbrains.edu.learning.ui.StudyProgressToolWindowFactory;
-import org.jetbrains.annotations.NotNull;
-
-import javax.swing.*;
-
-public class StudyInstructionPainter extends EditorEmptyTextPainter {
-  private static final String separator = " / ";
-  @Override
-  protected void advertiseActions(@NotNull JComponent splitters, @NotNull UIUtil.TextPainter painter) {
-    if (PlatformUtils.isPyCharmEducational()) {
-      String shortcut = KeymapUtil.getShortcutText(new KeyboardShortcut(KeyStroke.getKeyStroke(StudyNextWindowAction.SHORTCUT2), null));
-      appendAction(painter, "Navigate to the next answer placeholder", shortcut);
-      appendAction(painter, "Navigate between answer placeholders", getActionShortcutText(StudyPrevWindowAction.ACTION_ID) + separator +
-                                                                    getActionShortcutText(StudyNextWindowAction.ACTION_ID));
-      appendAction(painter, "Navigate between tasks", getActionShortcutText(StudyPreviousStudyTaskAction.ACTION_ID) + separator +
-                                                      getActionShortcutText(StudyNextStudyTaskAction.ACTION_ID));
-      appendAction(painter, "Reset current task file", getActionShortcutText(StudyRefreshTaskFileAction.ACTION_ID));
-      appendAction(painter, "Check task", getActionShortcutText(StudyCheckAction.ACTION_ID));
-      appendAction(painter, "Get hint for the answer placeholder", getActionShortcutText(StudyShowHintAction.ACTION_ID));
-      appendLine(painter, "To see your progress open the '" + StudyProgressToolWindowFactory.ID + "' panel");
-    } else {
-      super.advertiseActions(splitters, painter);
-    }
-  }
-}
\ No newline at end of file
index 1dc14d36bb51c33d3501a7d2b8b1e21a837bd329..6a5747fa526e0d11dbcd85ab4a11a2431f262920 100644 (file)
@@ -31,9 +31,10 @@ import com.jetbrains.edu.courseFormat.Course;
 import com.jetbrains.edu.courseFormat.Lesson;
 import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
 import com.jetbrains.edu.courseFormat.Lesson;
 import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
-import com.jetbrains.edu.learning.actions.*;
+import com.jetbrains.edu.learning.actions.StudyToolbarAction;
 import com.jetbrains.edu.learning.editor.StudyEditorFactoryListener;
 import com.jetbrains.edu.learning.ui.StudyProgressToolWindowFactory;
 import com.jetbrains.edu.learning.editor.StudyEditorFactoryListener;
 import com.jetbrains.edu.learning.ui.StudyProgressToolWindowFactory;
+import com.jetbrains.edu.learning.ui.StudyToolWindow;
 import com.jetbrains.edu.learning.ui.StudyToolWindowFactory;
 import javafx.application.Platform;
 import org.jetbrains.annotations.NotNull;
 import com.jetbrains.edu.learning.ui.StudyToolWindowFactory;
 import javafx.application.Platform;
 import org.jetbrains.annotations.NotNull;
@@ -109,13 +110,22 @@ public class StudyProjectComponent implements ProjectComponent {
   }
 
   private void registerShortcuts() {
   }
 
   private void registerShortcuts() {
-    addShortcut(StudyNextWindowAction.ACTION_ID, new String[]{StudyNextWindowAction.SHORTCUT, StudyNextWindowAction.SHORTCUT2});
-    addShortcut(StudyPrevWindowAction.ACTION_ID, new String[]{StudyPrevWindowAction.SHORTCUT});
-    addShortcut(StudyShowHintAction.ACTION_ID, new String[]{StudyShowHintAction.SHORTCUT});
-    addShortcut(StudyCheckAction.ACTION_ID, new String[]{StudyCheckAction.SHORTCUT});
-    addShortcut(StudyNextStudyTaskAction.ACTION_ID, new String[]{StudyNextStudyTaskAction.SHORTCUT});
-    addShortcut(StudyPreviousStudyTaskAction.ACTION_ID, new String[]{StudyPreviousStudyTaskAction.SHORTCUT});
-    addShortcut(StudyRefreshTaskFileAction.ACTION_ID, new String[]{StudyRefreshTaskFileAction.SHORTCUT});
+    StudyToolWindow window = StudyUtils.getStudyToolWindow(myProject);
+    if (window != null) {
+      List<AnAction> actionsOnToolbar = window.getActions(true);
+      if (actionsOnToolbar != null) {
+        for (AnAction action : actionsOnToolbar) {
+          if (action instanceof StudyToolbarAction) {
+            String id = ((StudyToolbarAction)action).getActionId();
+            String[] shortcuts = ((StudyToolbarAction)action).getShortcuts();
+            addShortcut(id, shortcuts);
+          }
+        }
+      }
+      else {
+        LOG.warn("Actions on toolbar are nulls");
+      }
+    }
   }
 
   private void registerToolWindows(@NotNull final ToolWindowManager toolWindowManager) {
   }
 
   private void registerToolWindows(@NotNull final ToolWindowManager toolWindowManager) {
diff --git a/python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyCheckAction.java b/python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyCheckAction.java
deleted file mode 100644 (file)
index 5fb4088..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.jetbrains.edu.learning.actions;
-
-import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.KeyboardShortcut;
-import com.intellij.openapi.actionSystem.Presentation;
-import com.intellij.openapi.keymap.KeymapUtil;
-import com.intellij.openapi.project.DumbAwareAction;
-import com.intellij.openapi.project.DumbService;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.MessageType;
-import com.intellij.openapi.util.Ref;
-import com.jetbrains.edu.learning.StudyUtils;
-import com.jetbrains.edu.learning.checker.StudyCheckUtils;
-import icons.InteractiveLearningIcons;
-import org.jetbrains.annotations.NotNull;
-
-import javax.swing.*;
-
-
-public class StudyCheckAction extends DumbAwareAction {
-
-  public static final String ACTION_ID = "CheckAction";
-  public static final String SHORTCUT = "ctrl alt pressed ENTER";
-
-  protected Ref<Boolean> myCheckInProgress = new Ref<>(false);
-
-  public StudyCheckAction() {
-    super("Check Task (" + KeymapUtil.getShortcutText(new KeyboardShortcut(KeyStroke.getKeyStroke(SHORTCUT), null)) + ")", "Check current task", InteractiveLearningIcons.Resolve);
-  }
-
-  protected void check(@NotNull final Project project) {}
-
-  @Override
-  public void actionPerformed(@NotNull AnActionEvent e) {
-    Project project = e.getProject();
-    if (project == null) {
-      return;
-    }
-    if (DumbService.isDumb(project)) {
-      StudyCheckUtils.showTestResultPopUp("Checking is not available while indexing is in progress", MessageType.WARNING.getPopupBackground(), project);
-      return;
-    }
-    check(project);
-  }
-
-  @Override
-  public void update(AnActionEvent e) {
-    final Presentation presentation = e.getPresentation();
-    StudyUtils.updateAction(e);
-    if (presentation.isEnabled()) {
-      presentation.setEnabled(!myCheckInProgress.get());
-    }
-  }
-}
index d76308bac77409c128303e6139300e9a8cb48c32..39d2d816fc0b00fb4a175958726983b75c725142 100644 (file)
@@ -27,4 +27,14 @@ public class StudyNextStudyTaskAction extends StudyTaskNavigationAction {
   protected Task getTargetTask(@NotNull final Task sourceTask) {
     return StudyNavigator.nextTask(sourceTask);
   }
   protected Task getTargetTask(@NotNull final Task sourceTask) {
     return StudyNavigator.nextTask(sourceTask);
   }
+
+  @Override
+  public String getActionId() {
+    return ACTION_ID;
+  }
+
+  @Override
+  public String[] getShortcuts() {
+    return new String[]{SHORTCUT};
+  }
 }
\ No newline at end of file
 }
\ No newline at end of file
index a509f57b6bc3afe95f0742860012580a703ec302..9c280447b144e0794f29d81fb236d9990636e916 100644 (file)
@@ -29,4 +29,14 @@ public class StudyNextWindowAction extends StudyWindowNavigationAction {
     }
     return null;
   }
     }
     return null;
   }
+
+  @Override
+  public String getActionId() {
+    return ACTION_ID;
+  }
+
+  @Override
+  public String[] getShortcuts() {
+    return new String[]{SHORTCUT, SHORTCUT2};
+  }
 }
 }
index bbdaabd885fe05f649fd292d5eb7ad6f2bd581d3..b8422ea04582fbeb76e729d5711d1586a14b91be 100644 (file)
@@ -31,4 +31,14 @@ public class StudyPrevWindowAction extends StudyWindowNavigationAction {
     }
     return null;
   }
     }
     return null;
   }
+
+  @Override
+  public String getActionId() {
+    return ACTION_ID;
+  }
+
+  @Override
+  public String[] getShortcuts() {
+    return new String[]{SHORTCUT};
+  }
 }
 }
index 0c3d5b4088ce3533e206dff38ecbe1c42bf795ef..d0fa769a957343788705bb3e312d732ae38c54ab 100644 (file)
@@ -27,4 +27,14 @@ public class StudyPreviousStudyTaskAction extends StudyTaskNavigationAction {
   protected Task getTargetTask(@NotNull final Task sourceTask) {
     return StudyNavigator.previousTask(sourceTask);
   }
   protected Task getTargetTask(@NotNull final Task sourceTask) {
     return StudyNavigator.previousTask(sourceTask);
   }
+
+  @Override
+  public String getActionId() {
+    return ACTION_ID;
+  }
+
+  @Override
+  public String[] getShortcuts() {
+    return new String[]{SHORTCUT};
+  }
 }
\ No newline at end of file
 }
\ No newline at end of file
index 0cb33f2d04e9ec75d6c7c6a0a11cea8ab0a4caf3..af98aba2c2235e990a2987961f793bfaf282c8e4 100644 (file)
@@ -10,7 +10,7 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.keymap.KeymapUtil;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.keymap.KeymapUtil;
-import com.intellij.openapi.project.DumbAwareAction;
+import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.ui.Messages;
@@ -33,7 +33,7 @@ import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
 
 
 import javax.swing.*;
 
-public class StudyRefreshTaskFileAction extends DumbAwareAction {
+public class StudyRefreshTaskFileAction extends StudyToolbarAction implements DumbAware {
   public static final String ACTION_ID = "RefreshTaskAction";
   public static final String SHORTCUT = "ctrl shift pressed X";
   private static final Logger LOG = Logger.getInstance(StudyRefreshTaskFileAction.class.getName());
   public static final String ACTION_ID = "RefreshTaskAction";
   public static final String SHORTCUT = "ctrl shift pressed X";
   private static final Logger LOG = Logger.getInstance(StudyRefreshTaskFileAction.class.getName());
@@ -163,4 +163,14 @@ public class StudyRefreshTaskFileAction extends DumbAwareAction {
       }
     }
   }
       }
     }
   }
+
+  @Override
+  public String getActionId() {
+    return ACTION_ID;
+  }
+
+  @Override
+  public String[] getShortcuts() {
+    return new String[]{SHORTCUT};
+  }
 }
 }
index 5d69a3869e02dea7bd4baaf989176c1db2e9cebf..e4b75db4d1fc0c1b0eb8c9d55a6e8f3d67eed2ac 100644 (file)
@@ -7,7 +7,7 @@ import com.intellij.openapi.actionSystem.KeyboardShortcut;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.LogicalPosition;
 import com.intellij.openapi.keymap.KeymapUtil;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.LogicalPosition;
 import com.intellij.openapi.keymap.KeymapUtil;
-import com.intellij.openapi.project.DumbAwareAction;
+import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.popup.JBPopup;
 import com.intellij.openapi.ui.popup.JBPopupFactory;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.popup.JBPopup;
 import com.intellij.openapi.ui.popup.JBPopupFactory;
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
 
 
 import javax.swing.*;
 
-public class StudyShowHintAction extends DumbAwareAction {
+public class StudyShowHintAction extends StudyToolbarAction implements DumbAware {
   public static final String ACTION_ID = "ShowHintAction";
   public static final String SHORTCUT = "ctrl pressed 7";
   private static final String ourWarningMessage = "Put the caret in the answer placeholder to get hint";
   public static final String ACTION_ID = "ShowHintAction";
   public static final String SHORTCUT = "ctrl pressed 7";
   private static final String ourWarningMessage = "Put the caret in the answer placeholder to get hint";
@@ -89,4 +89,14 @@ public class StudyShowHintAction extends DumbAwareAction {
   public void update(@NotNull AnActionEvent e) {
     StudyUtils.updateAction(e);
   }
   public void update(@NotNull AnActionEvent e) {
     StudyUtils.updateAction(e);
   }
+
+  @Override
+  public String getActionId() {
+    return ACTION_ID;
+  }
+
+  @Override
+  public String[] getShortcuts() {
+    return new String[]{SHORTCUT};
+  }
 }
 }
index b4e8d16905f055a753d842e30221e8f567efd967..37c81f0afbc2a602e55cb67b16be58e8b3a0e05e 100644 (file)
@@ -3,7 +3,7 @@ package com.jetbrains.edu.learning.actions;
 import com.intellij.ide.projectView.ProjectView;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.fileEditor.FileEditorManager;
 import com.intellij.ide.projectView.ProjectView;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.fileEditor.FileEditorManager;
-import com.intellij.openapi.project.DumbAwareAction;
+import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.ui.popup.Balloon;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.ui.popup.Balloon;
@@ -28,7 +28,7 @@ import javax.swing.tree.TreePath;
 import java.util.Map;
 
 
 import java.util.Map;
 
 
-abstract public class StudyTaskNavigationAction extends DumbAwareAction {
+abstract public class StudyTaskNavigationAction extends StudyToolbarAction implements DumbAware {
   public StudyTaskNavigationAction(@Nullable String text, @Nullable String description, @Nullable Icon icon) {
     super(text, description, icon);
   }
   public StudyTaskNavigationAction(@Nullable String text, @Nullable String description, @Nullable Icon icon) {
     super(text, description, icon);
   }
diff --git a/python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyToolbarAction.java b/python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyToolbarAction.java
new file mode 100644 (file)
index 0000000..e4bd3d0
--- /dev/null
@@ -0,0 +1,16 @@
+package com.jetbrains.edu.learning.actions;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+
+public abstract class StudyToolbarAction extends AnAction {
+  public StudyToolbarAction(@Nullable String text, @Nullable String description, @Nullable Icon icon) {
+    super(text, description, icon);
+  }
+
+  public abstract String getActionId();
+  
+  public abstract String[] getShortcuts();  
+}
index 7c79d3b01060cef3f5aff7580ebbd933c92ff266..880830fabcd6a32272e2737b52df31f7bf737f2c 100644 (file)
@@ -4,7 +4,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.LogicalPosition;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.LogicalPosition;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
-import com.intellij.openapi.project.DumbAwareAction;
+import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
@@ -16,7 +16,7 @@ import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 
 
 import javax.swing.*;
 
-abstract public class StudyWindowNavigationAction extends DumbAwareAction {
+abstract public class StudyWindowNavigationAction extends StudyToolbarAction implements DumbAware {
 
   protected StudyWindowNavigationAction(String actionId, String description, Icon icon) {
     super(actionId, description, icon);
 
   protected StudyWindowNavigationAction(String actionId, String description, Icon icon) {
     super(actionId, description, icon);
index 9b0cac5df651ceff35b06d61b3e1b939a1ab8c7a..ac033acb3fd50fd03359225635aad324112ab5da 100644 (file)
@@ -23,6 +23,8 @@
 
   <extensions defaultExtensionNs="com.intellij">
     <directoryProjectGenerator implementation="com.jetbrains.edu.learning.PyStudyDirectoryProjectGenerator"/>
 
   <extensions defaultExtensionNs="com.intellij">
     <directoryProjectGenerator implementation="com.jetbrains.edu.learning.PyStudyDirectoryProjectGenerator"/>
+    <applicationService serviceInterface="com.intellij.openapi.fileEditor.impl.EditorEmptyTextPainter"
+                        serviceImplementation="com.jetbrains.edu.learning.PyStudyInstructionPainter" overrides="true"/>
   </extensions>
   <extensions defaultExtensionNs="Pythonid">
     <inspectionExtension implementation="com.jetbrains.edu.learning.highlighting.PyStudyInspectionExtension"/>
   </extensions>
   <extensions defaultExtensionNs="Pythonid">
     <inspectionExtension implementation="com.jetbrains.edu.learning.highlighting.PyStudyInspectionExtension"/>
@@ -42,6 +44,8 @@
     <action id="StudyWatchTutorial" class="com.jetbrains.edu.learning.actions.PyStudyWatchTutorialAction">
       <add-to-group group-id="HelpMenu" anchor="before" relative-to-action="HelpTopics"/>
     </action>
     <action id="StudyWatchTutorial" class="com.jetbrains.edu.learning.actions.PyStudyWatchTutorialAction">
       <add-to-group group-id="HelpMenu" anchor="before" relative-to-action="HelpTopics"/>
     </action>
+    <action class="com.jetbrains.edu.learning.PyStudyCheckAction" id="PyCheckAction"
+            />
   </actions>
 
   <project-components>
   </actions>
 
   <project-components>
index 47ac0f993254b74a46c913c7632f41de92d25936..9ce243e6aa5c43c622083c35995e9861eab77d9a 100644 (file)
@@ -2,33 +2,62 @@ package com.jetbrains.edu.learning;
 
 import com.intellij.execution.ExecutionException;
 import com.intellij.openapi.actionSystem.ActionManager;
 
 import com.intellij.execution.ExecutionException;
 import com.intellij.openapi.actionSystem.ActionManager;
+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;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.command.CommandProcessor;
 import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.keymap.KeymapUtil;
 import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.progress.ProgressManager;
+import com.intellij.openapi.project.DumbService;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.MessageType;
+import com.intellij.openapi.util.Ref;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.wm.IdeFocusManager;
 import com.jetbrains.edu.courseFormat.StudyStatus;
 import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.wm.IdeFocusManager;
 import com.jetbrains.edu.courseFormat.StudyStatus;
 import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
-import com.jetbrains.edu.learning.actions.StudyCheckAction;
 import com.jetbrains.edu.learning.actions.StudyRunAction;
 import com.jetbrains.edu.learning.actions.StudyRunAction;
+import com.jetbrains.edu.learning.actions.StudyToolbarAction;
 import com.jetbrains.edu.learning.checker.StudyCheckTask;
 import com.jetbrains.edu.learning.checker.StudyCheckUtils;
 import com.jetbrains.edu.learning.checker.StudyCheckTask;
 import com.jetbrains.edu.learning.checker.StudyCheckUtils;
+import com.jetbrains.edu.learning.checker.StudyTestRunner;
 import com.jetbrains.edu.learning.checker.StudyTestsOutputParser;
 import com.jetbrains.edu.learning.editor.StudyEditor;
 import com.jetbrains.edu.learning.checker.StudyTestsOutputParser;
 import com.jetbrains.edu.learning.editor.StudyEditor;
-import com.jetbrains.edu.learning.checker.StudyTestRunner;
+import icons.InteractiveLearningIcons;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import javax.swing.*;
 import java.util.Map;
 
 import java.util.Map;
 
-public class PyStudyCheckAction extends StudyCheckAction {
+public class PyStudyCheckAction extends StudyToolbarAction {
   private static final Logger LOG = Logger.getInstance(PyStudyCheckAction.class);
 
   private static final Logger LOG = Logger.getInstance(PyStudyCheckAction.class);
 
+  public static final String ACTION_ID = "PyCheckAction";
+  public static final String SHORTCUT = "ctrl alt pressed ENTER";
+
+  protected Ref<Boolean> myCheckInProgress = new Ref<>(false);
+
+  public PyStudyCheckAction() {
+    super("Check Task (" + KeymapUtil.getShortcutText(new KeyboardShortcut(KeyStroke.getKeyStroke(SHORTCUT), null)) + ")", "Check current task", InteractiveLearningIcons.Resolve);
+  }
+
   @Override
   @Override
+  public void actionPerformed(@NotNull AnActionEvent e) {
+    Project project = e.getProject();
+    if (project == null) {
+      return;
+    }
+    if (DumbService.isDumb(project)) {
+      StudyCheckUtils.showTestResultPopUp("Checking is not available while indexing is in progress", MessageType.WARNING.getPopupBackground(), project);
+      return;
+    }
+    check(project);
+  }
+  
   protected void check(@NotNull Project project) {
     ApplicationManager.getApplication().runWriteAction(() -> {
       CommandProcessor.getInstance().runUndoTransparentAction(() -> {
   protected void check(@NotNull Project project) {
     ApplicationManager.getApplication().runWriteAction(() -> {
       CommandProcessor.getInstance().runUndoTransparentAction(() -> {
@@ -132,4 +161,25 @@ public class PyStudyCheckAction extends StudyCheckAction {
     }
     return taskVirtualFile;
   }
     }
     return taskVirtualFile;
   }
+
+
+
+  @Override
+  public String getActionId() {
+    return ACTION_ID;
+  }
+
+  @Override
+  public String[] getShortcuts() {
+    return new String[]{SHORTCUT};
+  }
+
+  @Override
+  public void update(AnActionEvent e) {
+    final Presentation presentation = e.getPresentation();
+    StudyUtils.updateAction(e);
+    if (presentation.isEnabled()) {
+      presentation.setEnabled(!myCheckInProgress.get());
+    }
+  }
 }
 }
diff --git a/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyInstructionPainter.java b/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyInstructionPainter.java
new file mode 100644 (file)
index 0000000..c8dc443
--- /dev/null
@@ -0,0 +1,28 @@
+package com.jetbrains.edu.learning;
+
+import com.intellij.openapi.actionSystem.KeyboardShortcut;
+import com.intellij.openapi.fileEditor.impl.EditorEmptyTextPainter;
+import com.intellij.openapi.keymap.KeymapUtil;
+import com.intellij.util.ui.UIUtil;
+import com.jetbrains.edu.learning.actions.*;
+import com.jetbrains.edu.learning.ui.StudyProgressToolWindowFactory;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.*;
+
+public class PyStudyInstructionPainter extends EditorEmptyTextPainter {
+  private static final String separator = " / ";
+  @Override
+  protected void advertiseActions(@NotNull JComponent splitters, @NotNull UIUtil.TextPainter painter) {
+    String shortcut = KeymapUtil.getShortcutText(new KeyboardShortcut(KeyStroke.getKeyStroke(StudyNextWindowAction.SHORTCUT2), null));
+    appendAction(painter, "Navigate to the next answer placeholder", shortcut);
+    appendAction(painter, "Navigate between answer placeholders", getActionShortcutText(StudyPrevWindowAction.ACTION_ID) + separator +
+                                                                  getActionShortcutText(StudyNextWindowAction.ACTION_ID));
+    appendAction(painter, "Navigate between tasks", getActionShortcutText(StudyPreviousStudyTaskAction.ACTION_ID) + separator +
+                                                    getActionShortcutText(StudyNextStudyTaskAction.ACTION_ID));
+    appendAction(painter, "Reset current task file", getActionShortcutText(StudyRefreshTaskFileAction.ACTION_ID));
+    appendAction(painter, "Check task", getActionShortcutText(PyStudyCheckAction.ACTION_ID));
+    appendAction(painter, "Get hint for the answer placeholder", getActionShortcutText(StudyShowHintAction.ACTION_ID));
+    appendLine(painter, "To see your progress open the '" + StudyProgressToolWindowFactory.ID + "' panel");
+  }
+}
\ No newline at end of file