For #EDU-565 Recreate StudyCheckAction Make StudyToolbarAction extend DumbAwareAction
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Mon, 14 Mar 2016 13:06:46 +0000 (16:06 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Mon, 14 Mar 2016 14:03:00 +0000 (17:03 +0300)
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyCheckAction.java [new file with mode: 0644]
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
python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyCheckAction.java

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
new file mode 100644 (file)
index 0000000..be36957
--- /dev/null
@@ -0,0 +1,55 @@
+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.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 abstract class StudyCheckAction extends StudyToolbarAction {
+  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);
+  }
+
+  public abstract 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());
+    }
+  }
+
+  @Override
+  public String[] getShortcuts() {
+    return new String[] {SHORTCUT};
+  }
+}
index cc7742e9981bec56ae4451142c7eee539a082b21..1cd6548274f30d4092fd478c61c635045c0f3966 100644 (file)
@@ -6,6 +6,7 @@ import com.intellij.openapi.keymap.KeymapUtil;
 import com.jetbrains.edu.learning.courseFormat.Task;
 import com.jetbrains.edu.learning.navigation.StudyNavigator;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 
@@ -28,11 +29,13 @@ public class StudyNextStudyTaskAction extends StudyTaskNavigationAction {
     return StudyNavigator.nextTask(sourceTask);
   }
 
+  @NotNull
   @Override
   public String getActionId() {
     return ACTION_ID;
   }
 
+  @Nullable
   @Override
   public String[] getShortcuts() {
     return new String[]{SHORTCUT};
index 5380d96de17b02071601f3bb61427031f970b880..01fd8dcbceecfcc2225aaf42800ff4b47e88bf93 100644 (file)
@@ -4,6 +4,7 @@ import com.intellij.icons.AllIcons;
 import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
 import com.jetbrains.edu.learning.StudyUtils;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.List;
 
@@ -30,11 +31,13 @@ public class StudyNextWindowAction extends StudyWindowNavigationAction {
     return null;
   }
 
+  @NotNull
   @Override
   public String getActionId() {
     return ACTION_ID;
   }
 
+  @Nullable
   @Override
   public String[] getShortcuts() {
     return new String[]{SHORTCUT, SHORTCUT2};
index 717a287e894643362833f64d532090eef588ff1f..572d1c26b69df6cb33fc05c9b100a80e016df9e7 100644 (file)
@@ -32,11 +32,13 @@ public class StudyPrevWindowAction extends StudyWindowNavigationAction {
     return null;
   }
 
+  @NotNull
   @Override
   public String getActionId() {
     return ACTION_ID;
   }
 
+  @Nullable
   @Override
   public String[] getShortcuts() {
     return new String[]{SHORTCUT};
index 4ddfd57691becc0c992a115f7e922b7e7313c4c3..653f00fd4b7d0ac94c003f70d72a5626ee0e8065 100644 (file)
@@ -7,6 +7,7 @@ import com.jetbrains.edu.learning.courseFormat.Task;
 import com.jetbrains.edu.learning.navigation.StudyNavigator;
 import icons.InteractiveLearningIcons;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 
@@ -28,11 +29,13 @@ public class StudyPreviousStudyTaskAction extends StudyTaskNavigationAction {
     return StudyNavigator.previousTask(sourceTask);
   }
 
+  @NotNull
   @Override
   public String getActionId() {
     return ACTION_ID;
   }
 
+  @Nullable
   @Override
   public String[] getShortcuts() {
     return new String[]{SHORTCUT};
index 4fcf9fd0c3aeb5922d64ca9beb60afb9e9c64ec0..110feeee370f5c124c1c4c1c66a6d12e9058ebb2 100644 (file)
@@ -10,7 +10,6 @@ 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.project.DumbAware;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.ui.Messages;
@@ -30,10 +29,11 @@ import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.editor.StudyEditor;
 import com.jetbrains.edu.learning.navigation.StudyNavigator;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 
-public class StudyRefreshTaskFileAction extends StudyToolbarAction implements DumbAware {
+public class StudyRefreshTaskFileAction extends StudyToolbarAction {
   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());
@@ -164,11 +164,13 @@ public class StudyRefreshTaskFileAction extends StudyToolbarAction implements Du
     }
   }
 
+  @NotNull
   @Override
   public String getActionId() {
     return ACTION_ID;
   }
 
+  @Nullable
   @Override
   public String[] getShortcuts() {
     return new String[]{SHORTCUT};
index 13e540091a3eacdf7f0ac668590958d30b7b557c..25642dc0cf87f187388739f3a06344933622f27c 100644 (file)
@@ -7,7 +7,6 @@ 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.project.DumbAware;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.popup.JBPopup;
 import com.intellij.openapi.ui.popup.JBPopupFactory;
@@ -22,10 +21,11 @@ import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
 import icons.InteractiveLearningIcons;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 
-public class StudyShowHintAction extends StudyToolbarAction implements DumbAware {
+public class StudyShowHintAction extends StudyToolbarAction {
   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";
@@ -90,11 +90,13 @@ public class StudyShowHintAction extends StudyToolbarAction implements DumbAware
     StudyUtils.updateAction(e);
   }
 
+  @NotNull
   @Override
   public String getActionId() {
     return ACTION_ID;
   }
 
+  @Nullable
   @Override
   public String[] getShortcuts() {
     return new String[]{SHORTCUT};
index 5b041dff128c006b9ef8323aaf6594909a5c782c..580bc3557d64cd07d3c0b1eab75d2207e5c1831d 100644 (file)
@@ -3,7 +3,6 @@ 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.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.ui.popup.Balloon;
@@ -28,7 +27,7 @@ import javax.swing.tree.TreePath;
 import java.util.Map;
 
 
-abstract public class StudyTaskNavigationAction extends StudyToolbarAction implements DumbAware {
+abstract public class StudyTaskNavigationAction extends StudyToolbarAction {
   public StudyTaskNavigationAction(@Nullable String text, @Nullable String description, @Nullable Icon icon) {
     super(text, description, icon);
   }
index e4bd3d08c14b3bc8907bbb55d4a68dd925fb5062..a74e547984ef6bb0e86cb7e9491c1cf6767515e8 100644 (file)
@@ -1,16 +1,19 @@
 package com.jetbrains.edu.learning.actions;
 
-import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.project.DumbAwareAction;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 
-public abstract class StudyToolbarAction extends AnAction {
+public abstract class StudyToolbarAction extends DumbAwareAction {
   public StudyToolbarAction(@Nullable String text, @Nullable String description, @Nullable Icon icon) {
     super(text, description, icon);
   }
 
+  @NotNull
   public abstract String getActionId();
   
+  @Nullable
   public abstract String[] getShortcuts();  
 }
index 0188a46a2048961bd861927e291e1f20c69be497..43f5fc5645f4f6ef3916e8a5a7c3808ac857e2e1 100644 (file)
@@ -2,22 +2,16 @@ package com.jetbrains.edu.learning;
 
 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.keymap.KeymapUtil;
 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.util.Ref;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.wm.IdeFocusManager;
+import com.jetbrains.edu.learning.actions.StudyCheckAction;
 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.StudyTestRunner;
@@ -26,39 +20,16 @@ import com.jetbrains.edu.learning.courseFormat.StudyStatus;
 import com.jetbrains.edu.learning.courseFormat.Task;
 import com.jetbrains.edu.learning.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.editor.StudyEditor;
-import icons.InteractiveLearningIcons;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import javax.swing.*;
 import java.util.Map;
 
-public class PyStudyCheckAction extends StudyToolbarAction {
+public class PyStudyCheckAction extends StudyCheckAction {
   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
-  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) {
+  
+  public void check(@NotNull Project project) {
     ApplicationManager.getApplication().runWriteAction(() -> {
       CommandProcessor.getInstance().runUndoTransparentAction(() -> {
         final StudyEditor selectedEditor = StudyUtils.getSelectedStudyEditor(project);
@@ -161,25 +132,10 @@ public class PyStudyCheckAction extends StudyToolbarAction {
     }
     return taskVirtualFile;
   }
-
-
-
+  
+  @NotNull
   @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());
-    }
-  }
 }