show invisible nodes in course creator project view
authorliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 7 Apr 2016 16:41:11 +0000 (19:41 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 7 Apr 2016 16:41:53 +0000 (19:41 +0300)
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/projectView/CCDirectoryNode.java [deleted file]
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/projectView/CCTreeStructureProvider.java
python/educational-core/student/src/com/jetbrains/edu/learning/projectView/StudyTreeStructureProvider.java

diff --git a/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/projectView/CCDirectoryNode.java b/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/projectView/CCDirectoryNode.java
deleted file mode 100644 (file)
index 551d344..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.jetbrains.edu.coursecreator.projectView;
-
-import com.intellij.ide.projectView.PresentationData;
-import com.intellij.ide.projectView.ViewSettings;
-import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode;
-import com.intellij.openapi.project.Project;
-import com.intellij.psi.PsiDirectory;
-import com.intellij.ui.SimpleTextAttributes;
-import com.jetbrains.edu.learning.core.EduNames;
-import com.jetbrains.edu.learning.core.EduUtils;
-import com.jetbrains.edu.learning.courseFormat.Course;
-import com.jetbrains.edu.learning.courseFormat.Lesson;
-import com.jetbrains.edu.learning.courseFormat.Task;
-import com.jetbrains.edu.coursecreator.CCProjectService;
-import icons.InteractiveLearningIcons;
-import org.jetbrains.annotations.NotNull;
-
-public class CCDirectoryNode extends PsiDirectoryNode {
-  private final PsiDirectory myValue;
-  private final Project myProject;
-
-  public CCDirectoryNode(@NotNull final Project project,
-                         PsiDirectory value,
-                         ViewSettings viewSettings) {
-    super(project, value, viewSettings);
-    myValue = value;
-    myProject = project;
-  }
-
-  @Override
-  protected void updateImpl(PresentationData data) {
-    String valueName = myValue.getName();
-    final CCProjectService service = CCProjectService.getInstance(myProject);
-    final Course course = service.getCourse();
-    if (course == null) return;
-    if (myProject.getBaseDir().equals(myValue.getVirtualFile())) {
-      data.clearText();
-      data.setIcon(InteractiveLearningIcons.Course);
-      data.addText(course.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
-      data.addText(" (" + valueName + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
-      return;
-    }
-    final Lesson lesson = course.getLesson(valueName);
-    if (lesson != null) {
-      data.clearText();
-      data.setIcon(InteractiveLearningIcons.Lesson);
-      data.addText(lesson.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
-      return;
-    }
-    else {
-      final PsiDirectory parentDir = myValue.getParentDirectory();
-      if (parentDir != null) {
-        final Lesson parentLesson = course.getLesson(parentDir.getName());
-        if (parentLesson != null) {
-          final Task task = parentLesson.getTask(valueName);
-          if (task != null) {
-            data.clearText();
-            data.setIcon(InteractiveLearningIcons.Task);
-            data.addText(task.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
-            return;
-          }
-        }
-      }
-    }
-    data.setPresentableText(valueName);
-  }
-
-  @Override
-  public int getTypeSortWeight(boolean sortByType) {
-    String name = myValue.getName();
-    if (name.startsWith(EduNames.LESSON) || name.startsWith(EduNames.TASK)) {
-      String logicalName = name.contains(EduNames.LESSON) ? EduNames.LESSON : EduNames.TASK;
-      int index = EduUtils.getIndex(name, logicalName) + 1;
-      return index != -1 ? index + 1: 0;
-    }
-    return 0;
-  }
-
-  @Override
-  public String getNavigateActionText(boolean focusEditor) {
-    return null;
-  }
-}
index d4f39fbefd2f6358c29b48286e522b58f2006228..2702e3d4cf56c2141e0a042b3550077367bbfbcb 100644 (file)
@@ -1,23 +1,22 @@
 package com.jetbrains.edu.coursecreator.projectView;
 
-import com.intellij.ide.projectView.TreeStructureProvider;
 import com.intellij.ide.projectView.ViewSettings;
 import com.intellij.ide.projectView.impl.nodes.PsiFileNode;
 import com.intellij.ide.util.treeView.AbstractTreeNode;
-import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.io.FileUtilRt;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiDirectory;
-import com.jetbrains.edu.learning.core.EduNames;
-import com.jetbrains.edu.coursecreator.CCProjectService;
 import com.jetbrains.edu.coursecreator.CCUtils;
+import com.jetbrains.edu.learning.StudyUtils;
+import com.jetbrains.edu.learning.core.EduNames;
+import com.jetbrains.edu.learning.projectView.StudyTreeStructureProvider;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
 
 import java.util.ArrayList;
 import java.util.Collection;
 
-public class CCTreeStructureProvider implements TreeStructureProvider, DumbAware {
+public class CCTreeStructureProvider extends StudyTreeStructureProvider {
   @NotNull
   @Override
   public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent,
@@ -26,18 +25,16 @@ public class CCTreeStructureProvider implements TreeStructureProvider, DumbAware
     if (!needModify(parent)) {
       return children;
     }
-    Collection<AbstractTreeNode> nodes = new ArrayList<AbstractTreeNode>();
+    Collection<AbstractTreeNode> modifiedChildren = new ArrayList(super.modify(parent, children, settings));
+
     for (AbstractTreeNode node : children) {
       Project project = node.getProject();
-      if (project != null) {
         if (node.getValue() instanceof PsiDirectory) {
           String name = ((PsiDirectory)node.getValue()).getName();
-          if (CCUtils.GENERATED_FILES_FOLDER.equals(name)) {
+          if ("zip".equals(FileUtilRt.getExtension(name))) {
+            modifiedChildren.add(node);
             continue;
           }
-          PsiDirectory directory = (PsiDirectory)node.getValue();
-          nodes.add(new CCDirectoryNode(project, directory, settings));
-          continue;
         }
         if (node instanceof PsiFileNode) {
           PsiFileNode fileNode = (PsiFileNode)node;
@@ -45,34 +42,19 @@ public class CCTreeStructureProvider implements TreeStructureProvider, DumbAware
           if (virtualFile == null) {
             continue;
           }
-          if (virtualFile.getName().contains(EduNames.WINDOWS_POSTFIX)) {
-            continue;
-          }
-
-          if (virtualFile.getParent().getName().contains(EduNames.TASK) && !CCProjectService.getInstance(project).isTaskFile(virtualFile)) {
-            nodes.add(new CCStudentInvisibleFileNode(project, ((PsiFileNode)node).getValue(), settings));
-            continue;
+          if (StudyUtils.getTaskFile(project, virtualFile) == null && !EduNames.TASK_HTML.equals(virtualFile.getName())) {
+            modifiedChildren.add(new CCStudentInvisibleFileNode(project, ((PsiFileNode)node).getValue(), settings));
           }
         }
-        nodes.add(node);
-      }
     }
-    return nodes;
+    return modifiedChildren;
   }
 
-  private static boolean needModify(@NotNull final AbstractTreeNode parent) {
+  protected boolean needModify(@NotNull final AbstractTreeNode parent) {
     Project project = parent.getProject();
-    if (project != null) {
-      if (CCProjectService.getInstance(project).getCourse() == null) {
-        return false;
-      }
+    if (project == null) {
+      return false;
     }
-    return true;
-  }
-
-  @Nullable
-  @Override
-  public Object getData(Collection<AbstractTreeNode> selected, String dataName) {
-    return null;
+    return CCUtils.isCourseCreator(project);
   }
 }
index 6fd47eaece843929f99930fc5d1f6f4867cc6f04..0a3a3e841feb7660da752f9e5e4f90ca3b13a62d 100644 (file)
@@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiDirectory;
 import com.jetbrains.edu.learning.core.EduNames;
+import com.jetbrains.edu.learning.courseFormat.Course;
 import com.jetbrains.edu.learning.courseFormat.TaskFile;
 import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
@@ -24,7 +25,7 @@ public class StudyTreeStructureProvider implements TreeStructureProvider, DumbAw
   public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent,
                                              @NotNull Collection<AbstractTreeNode> children,
                                              ViewSettings settings) {
-    if (!isCourseBasedProject(parent)) {
+    if (!needModify(parent)) {
       return children;
     }
     Collection<AbstractTreeNode> nodes = new ArrayList<>();
@@ -78,21 +79,23 @@ public class StudyTreeStructureProvider implements TreeStructureProvider, DumbAw
     if (!StudyTaskManager.getInstance(project).isInvisibleFile(virtualFile.getPath())) {
       String fileName = virtualFile.getName();
       if (!fileName.contains(EduNames.WINDOW_POSTFIX) && !fileName.contains(EduNames.WINDOWS_POSTFIX)
-          && !StudyUtils.isTestsFile(project, fileName) && !EduNames.TASK_HTML.equals(fileName) && !fileName.contains(".answer")) {
+          && !StudyUtils.isTestsFile(project, fileName) && !EduNames.TASK_HTML.equals(fileName)) {
         nodes.add(node);
       }
     }
   }
 
-  protected boolean isCourseBasedProject(@NotNull final AbstractTreeNode parent) {
+  protected boolean needModify(@NotNull final AbstractTreeNode parent) {
     final Project project = parent.getProject();
-    if (project != null) {
-      final StudyTaskManager studyTaskManager = StudyTaskManager.getInstance(project);
-      if (studyTaskManager.getCourse() == null) {
-        return false;
-      }
+    if (project == null) {
+      return false;
+    }
+    final StudyTaskManager studyTaskManager = StudyTaskManager.getInstance(project);
+    Course course = studyTaskManager.getCourse();
+    if (course == null) {
+      return false;
     }
-    return true;
+    return EduNames.STUDY.equals(course.getCourseMode());
   }
 
   @Nullable