EDU-322 Next Task: unnecessary jumping from Project Root to actual task position... appcode/163.534 pycharm/163.535
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Fri, 24 Jun 2016 12:00:17 +0000 (15:00 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Fri, 24 Jun 2016 12:00:17 +0000 (15:00 +0300)
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyTaskNavigationAction.java

index 363e73e37018d7e2027c15711f58363737a32850..efc81bc33be7f2c19289130776e6f2470a9db442 100644 (file)
@@ -8,7 +8,6 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.wm.ToolWindow;
 import com.intellij.openapi.wm.ToolWindowId;
 import com.intellij.openapi.wm.ToolWindowManager;
-import com.intellij.util.ui.tree.TreeUtil;
 import com.jetbrains.edu.learning.StudyState;
 import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.core.EduNames;
@@ -44,9 +43,6 @@ abstract public class StudyTaskNavigationAction extends StudyActionWithShortcut
     int nextTaskIndex = nextTask.getIndex();
     int lessonIndex = nextTask.getLesson().getIndex();
     Map<String, TaskFile> nextTaskFiles = nextTask.getTaskFiles();
-    if (nextTaskFiles.isEmpty()) {
-      return;
-    }
     VirtualFile projectDir = project.getBaseDir();
     String lessonDirName = EduNames.LESSON + String.valueOf(lessonIndex);
     if (projectDir == null) {
@@ -61,15 +57,26 @@ abstract public class StudyTaskNavigationAction extends StudyActionWithShortcut
     if (taskDir == null) {
       return;
     }
+    if (nextTaskFiles.isEmpty()) {
+      ProjectView.getInstance(project).select(taskDir, taskDir, false);
+      return;
+    }
 
     VirtualFile shouldBeActive = getFileToActivate(project, nextTaskFiles, taskDir);
     JTree tree = ProjectView.getInstance(project).getCurrentProjectViewPane().getTree();
-    TreePath path = TreeUtil.getFirstNodePath(tree);
-    tree.collapsePath(path);
+    TreePath path = tree.getSelectionPath();
+    if (path != null) {
+      TreePath oldSelectionPath = path.getParentPath();
+      if (oldSelectionPath != null) {
+        tree.collapsePath(oldSelectionPath);
+        tree.fireTreeCollapsed(oldSelectionPath);
+      }
+    }
     if (shouldBeActive != null) {
       ProjectView.getInstance(project).select(shouldBeActive, shouldBeActive, false);
       FileEditorManager.getInstance(project).openFile(shouldBeActive, true);
     }
+
     ToolWindow runToolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.RUN);
     if (runToolWindow != null) {
       runToolWindow.hide(null);
@@ -82,7 +89,7 @@ abstract public class StudyTaskNavigationAction extends StudyActionWithShortcut
     for (Map.Entry<String, TaskFile> entry : nextTaskFiles.entrySet()) {
       String name = entry.getKey();
       TaskFile taskFile = entry.getValue();
-      VirtualFile srcDir = taskDir.findChild("src");
+      VirtualFile srcDir = taskDir.findChild(EduNames.SRC);
       VirtualFile vf = srcDir == null ? taskDir.findChild(name) : srcDir.findChild(name);
       if (vf != null) {
         FileEditorManager.getInstance(project).openFile(vf, true);