show in project view only active subtask test
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Thu, 22 Sep 2016 12:42:48 +0000 (15:42 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 17 Nov 2016 14:05:04 +0000 (17:05 +0300)
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/projectView/CCStudentInvisibleFileNode.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/projectView/CCTreeStructureProvider.java

index 94376a13ae3dc2966fcc85c1fdfd7a491a5acd2a..e163eee2b238baa75f9052d39494234d05636ff3 100644 (file)
@@ -10,20 +10,29 @@ import com.intellij.ui.SimpleTextAttributes;
 /**
  * represents a file which is invisible for student in student mode
  */
-public class CCStudentInvisibleFileNode extends PsiFileNode{
+public class CCStudentInvisibleFileNode extends PsiFileNode {
+  private final String myName;
 
   public CCStudentInvisibleFileNode(Project project,
                                     PsiFile value,
                                     ViewSettings viewSettings) {
     super(project, value, viewSettings);
+    myName = value.getName();
+  }
+
+  public CCStudentInvisibleFileNode(Project project,
+                                    PsiFile value,
+                                    ViewSettings viewSettings,
+                                    String name) {
+    super(project, value, viewSettings);
+    myName = name;
   }
 
 
   @Override
   protected void updateImpl(PresentationData data) {
     super.updateImpl(data);
-    String text = data.getPresentableText();
     data.clearText();
-    data.addText(text, SimpleTextAttributes.GRAY_ATTRIBUTES);
+    data.addText(myName, SimpleTextAttributes.GRAY_ATTRIBUTES);
   }
 }
index 2a4249929538e051e329f907cd68d014fe1ed966..0b89eaea50521bab595f57b21c2e36e04c4f175d 100644 (file)
@@ -9,7 +9,12 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiDirectory;
 import com.intellij.psi.PsiFile;
 import com.jetbrains.edu.coursecreator.CCUtils;
+import com.jetbrains.edu.learning.StudyLanguageManager;
+import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
+import com.jetbrains.edu.learning.core.EduNames;
+import com.jetbrains.edu.learning.courseFormat.Course;
+import com.jetbrains.edu.learning.courseFormat.Task;
 import com.jetbrains.edu.learning.projectView.StudyTreeStructureProvider;
 import org.jetbrains.annotations.NotNull;
 
@@ -48,7 +53,10 @@ public class CCTreeStructureProvider extends StudyTreeStructureProvider {
           continue;
         }
         PsiFile psiFile = ((PsiFileNode)node).getValue();
-        modifiedChildren.add(new CCStudentInvisibleFileNode(project, psiFile, settings));
+        boolean handled = handleTests(project, virtualFile, psiFile, modifiedChildren, settings);
+        if (!handled) {
+          modifiedChildren.add(new CCStudentInvisibleFileNode(project, psiFile, settings));
+        }
       }
     }
     return modifiedChildren;
@@ -61,4 +69,51 @@ public class CCTreeStructureProvider extends StudyTreeStructureProvider {
     }
     return CCUtils.isCourseCreator(project);
   }
+
+  private static boolean handleTests(Project project,
+                                     VirtualFile virtualFile,
+                                     PsiFile psiFile,
+                                     Collection<AbstractTreeNode> modifiedChildren,
+                                     ViewSettings settings) {
+    Course course = StudyTaskManager.getInstance(project).getCourse();
+    if (course == null) {
+      return false;
+    }
+    if (!CCUtils.isTestsFile(project, virtualFile)) {
+      return false;
+    }
+    VirtualFile taskDir = StudyUtils.getTaskDir(virtualFile);
+    if (taskDir == null) {
+      return false;
+    }
+    Task task = StudyUtils.getTask(project, taskDir);
+    if (task == null) {
+      return false;
+    }
+    if (isActiveSubtaskTest(task, virtualFile)) {
+      StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
+      String testsFileName = manager != null ? manager.getTestFileName() : psiFile.getName();
+      modifiedChildren.add(new CCStudentInvisibleFileNode(project, psiFile, settings,
+                                                          testsFileName));
+    }
+    return true;
+  }
+
+  private static boolean isActiveSubtaskTest(Task task, VirtualFile virtualFile) {
+    if (!task.hasSubtasks()) {
+      return true;
+    }
+
+    boolean isSubtaskTestFile = virtualFile.getName().contains(EduNames.SUBTASK_MARKER);
+    if (task.getActiveSubtaskIndex() == 0) {
+      return !isSubtaskTestFile;
+    }
+    if (!isSubtaskTestFile) {
+      return false;
+    }
+    String nameWithoutExtension = virtualFile.getNameWithoutExtension();
+    int stepMarkerStart = nameWithoutExtension.indexOf(EduNames.SUBTASK_MARKER);
+    int stepIndex = Integer.valueOf(nameWithoutExtension.substring(EduNames.SUBTASK_MARKER.length() + stepMarkerStart));
+    return stepIndex == task.getActiveSubtaskIndex();
+  }
 }