added ability to override check action appcode/144.1899 clion/144.1900 idea/144.1901
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Mon, 7 Dec 2015 14:44:43 +0000 (17:44 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Mon, 7 Dec 2015 14:44:43 +0000 (17:44 +0300)
python/edu/interactive-learning-python/src/com/jetbrains/edu/learning/PyStudyExecutor.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/StudyUtils.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyCheckAction.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudyExecutor.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/ui/StudyToolWindow.java

index b1d07e1c896463ff4b01de602267f9aa7f6595d3..998066dce2e79f9333175cf03d564f132deea480 100644 (file)
@@ -29,12 +29,14 @@ import com.intellij.openapi.ui.popup.BalloonBuilder;
 import com.intellij.openapi.ui.popup.JBPopupFactory;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.jetbrains.edu.courseFormat.Task;
+import com.jetbrains.edu.learning.actions.StudyCheckAction;
 import com.jetbrains.edu.learning.courseFormat.UserTest;
 import com.jetbrains.edu.learning.run.StudyExecutor;
 import com.jetbrains.edu.learning.run.StudyTestRunner;
 import com.jetbrains.python.run.PythonTracebackFilter;
 import com.jetbrains.python.sdk.PythonSdkType;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.event.HyperlinkEvent;
 import javax.swing.event.HyperlinkListener;
@@ -102,4 +104,9 @@ public class PyStudyExecutor implements StudyExecutor {
     StudyUtils.showCheckPopUp(project, balloon);
   }
 
+  @Nullable
+  @Override
+  public StudyCheckAction getCheckAction() {
+    return null;
+  }
 }
index 226d87a88168513ff5c7a2b2f273b0af955472f1..89cc18535d8db8719e400ae18319e78cef778694 100644 (file)
@@ -38,6 +38,7 @@ import com.jetbrains.edu.EduAnswerPlaceholderPainter;
 import com.jetbrains.edu.EduNames;
 import com.jetbrains.edu.EduUtils;
 import com.jetbrains.edu.courseFormat.*;
+import com.jetbrains.edu.learning.actions.StudyCheckAction;
 import com.jetbrains.edu.learning.editor.StudyEditor;
 import com.jetbrains.edu.learning.run.StudyExecutor;
 import com.jetbrains.edu.learning.run.StudyTestRunner;
@@ -173,6 +174,11 @@ public class StudyUtils {
     return StudyExecutor.INSTANCE.forLanguage(language).getExecutor(project, handler);
   }
 
+  public static StudyCheckAction getCheckAction(@NotNull final Course course) {
+    final Language language = course.getLanguageById();
+    return StudyExecutor.INSTANCE.forLanguage(language).getCheckAction();
+  }
+
   public static void setCommandLineParameters(@NotNull final GeneralCommandLine cmd,
                                               @NotNull final Project project,
                                               @NotNull final String filePath,
index 6cebf49729c6f1a92a7ce3816ed7c23573fb5f38..b3293735670aca9aad09428a2dd687c99ff98c3e 100644 (file)
@@ -37,10 +37,7 @@ import com.intellij.openapi.wm.ex.StatusBarEx;
 import com.intellij.openapi.wm.ex.WindowManagerEx;
 import com.jetbrains.edu.EduDocumentListener;
 import com.jetbrains.edu.EduUtils;
-import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
-import com.jetbrains.edu.courseFormat.StudyStatus;
-import com.jetbrains.edu.courseFormat.Task;
-import com.jetbrains.edu.courseFormat.TaskFile;
+import com.jetbrains.edu.courseFormat.*;
 import com.jetbrains.edu.learning.StudyState;
 import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
@@ -69,11 +66,17 @@ public class StudyCheckAction extends DumbAwareAction {
 
   boolean checkInProgress = false;
 
-  public StudyCheckAction() {
+  protected StudyCheckAction() {
     super("Check Task (" + KeymapUtil.getShortcutText(new KeyboardShortcut(KeyStroke.getKeyStroke(SHORTCUT), null)) + ")", "Check current task", InteractiveLearningIcons.Resolve);
   }
 
-  private static void flushWindows(@NotNull final Task task, @NotNull final VirtualFile taskDir) {
+
+  public static StudyCheckAction createCheckAction(final Course course) {
+    StudyCheckAction checkAction = StudyUtils.getCheckAction(course);
+    return checkAction != null ? checkAction : new StudyCheckAction();
+  }
+
+  protected static void flushWindows(@NotNull final Task task, @NotNull final VirtualFile taskDir) {
     for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
       String name = entry.getKey();
       TaskFile taskFile = entry.getValue();
@@ -102,7 +105,7 @@ public class StudyCheckAction extends DumbAwareAction {
   }
 
 
-  public void check(@NotNull final Project project) {
+  protected void check(@NotNull final Project project) {
     if (DumbService.isDumb(project)) {
       DumbService.getInstance(project).showDumbModeNotification("Check Action is not available while indexing is in progress");
       return;
@@ -185,7 +188,7 @@ public class StudyCheckAction extends DumbAwareAction {
   }
 
   @NotNull
-  private com.intellij.openapi.progress.Task.Backgroundable getCheckTask(final StudyState studyState,
+  protected com.intellij.openapi.progress.Task.Backgroundable getCheckTask(final StudyState studyState,
                                                                          final StudyTestRunner testRunner,
                                                                          final Process testProcess,
                                                                          @NotNull final String commandLine, @NotNull final Project project,
@@ -323,7 +326,7 @@ public class StudyCheckAction extends DumbAwareAction {
     StudyNavigator.navigateToFirstFailedAnswerPlaceholder(editor, taskFileToNavigate);
   }
 
-  private void runSmartTestProcess(@NotNull final VirtualFile taskDir,
+  protected void runSmartTestProcess(@NotNull final VirtualFile taskDir,
                                    @NotNull final StudyTestRunner testRunner,
                                    final String taskFileName,
                                    @NotNull final TaskFile taskFile,
@@ -386,7 +389,7 @@ public class StudyCheckAction extends DumbAwareAction {
     return copy;
   }
 
-  private static void showTestResultPopUp(final String text, Color color, @NotNull final Project project) {
+  protected static void showTestResultPopUp(final String text, Color color, @NotNull final Project project) {
     BalloonBuilder balloonBuilder =
       JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(text, null, color, null);
     final Balloon balloon = balloonBuilder.createBalloon();
index 5023281082572e8f5d8afa25cd886a0ec4908996..1aa9cacbe7f8e77a28a097f153e1dc189ffc49fb 100644 (file)
@@ -23,6 +23,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.jetbrains.edu.courseFormat.Task;
+import com.jetbrains.edu.learning.actions.StudyCheckAction;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -43,4 +44,12 @@ public interface StudyExecutor {
                                 @NotNull final Task currentTask);
 
   void showNoSdkNotification(@NotNull final Project project);
+
+  /**
+   * If this method returns null, StudyCheckAction will be used to check tasks
+   * @return language-specific check action or null
+   * @see StudyCheckAction
+   */
+  @Nullable
+  StudyCheckAction getCheckAction();
 }
index 3fe09bbf34b5a270d513689bdc431bdb68ac8ee7..5b597aabf2656a11f6d3ed5cb1d7c3f87d098eda 100644 (file)
@@ -37,6 +37,7 @@ import com.intellij.util.ui.UIUtil;
 import com.jetbrains.edu.EduNames;
 import com.jetbrains.edu.courseFormat.Task;
 import com.jetbrains.edu.courseFormat.TaskFile;
+import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.actions.*;
 import org.jetbrains.annotations.NotNull;
@@ -56,7 +57,7 @@ public class StudyToolWindow extends SimpleToolWindowPanel implements DataProvid
 
   public StudyToolWindow(final Project project) {
     super(true, true);
-    JPanel toolbarPanel = createToolbarPanel();
+    JPanel toolbarPanel = createToolbarPanel(project);
     setToolbar(toolbarPanel);
 
     final JTextPane taskTextPane = createTaskTextPane();
@@ -114,9 +115,9 @@ public class StudyToolWindow extends SimpleToolWindowPanel implements DataProvid
   public void dispose() {
   }
 
-  private static JPanel createToolbarPanel() {
+  private static JPanel createToolbarPanel(@NotNull final Project project) {
     final DefaultActionGroup group = new DefaultActionGroup();
-    group.add(new StudyCheckAction());
+    group.add(StudyCheckAction.createCheckAction(StudyTaskManager.getInstance(project).getCourse()));
     group.add(new StudyPreviousStudyTaskAction());
     group.add(new StudyNextStudyTaskAction());
     group.add(new StudyRefreshTaskFileAction());