fixed bug with empty task files, improved navigation to task
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Wed, 29 Oct 2014 16:21:45 +0000 (19:21 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Wed, 29 Oct 2014 16:21:45 +0000 (19:21 +0300)
python/edu/learn-python/src/com/jetbrains/python/edu/StudyDirectoryProjectGenerator.java
python/edu/learn-python/src/com/jetbrains/python/edu/projectView/StudyDirectoryNode.java

index a9630f6f730c51454b2eefe31facec703a507cdd..90a4b74521def806138b1ce3373f46864b9cf91b 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
+import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
 import com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl;
 import com.intellij.openapi.wm.ex.ToolWindowManagerAdapter;
 import com.intellij.openapi.wm.ex.ToolWindowManagerEx;
@@ -188,7 +189,6 @@ public class StudyDirectoryProjectGenerator extends PythonProjectGenerator imple
               final VirtualFile taskDir = firstTask.getTaskDir(myProject);
               if (taskDir == null) return;
               final Map<String, TaskFile> taskFiles = firstTask.getTaskFiles();
-
               VirtualFile activeVirtualFile = null;
               for (Map.Entry<String, TaskFile> entry : taskFiles.entrySet()) {
                 final String name = entry.getKey();
@@ -204,8 +204,16 @@ public class StudyDirectoryProjectGenerator extends PythonProjectGenerator imple
               if (activeVirtualFile != null) {
                 final PsiFile file = PsiManager.getInstance(myProject).findFile(activeVirtualFile);
                 ProjectView.getInstance(project).select(file, activeVirtualFile, true);
-                initialized[0] = true;
+              } else {
+                String first = StudyUtils.getFirst(taskFiles.keySet());
+                if (first != null) {
+                  NewVirtualFile firstFile = ((VirtualDirectoryImpl)taskDir).refreshAndFindChild(first);
+                  if (firstFile != null) {
+                    FileEditorManager.getInstance(project).openFile(firstFile, true);
+                  }
+                }
               }
+              initialized[0] = true;
             }
           }, ModalityState.current(), new Condition() {
             @Override
index bb23f5e918fcf58924446fe3666c6589c8810ebc..4bd8df9baee7c325ec01db93c69374a8aca30095 100644 (file)
@@ -19,7 +19,7 @@ import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
 import java.awt.*;
-import java.util.Set;
+import java.util.Map;
 
 public class StudyDirectoryNode extends PsiDirectoryNode {
   private final PsiDirectory myValue;
@@ -144,15 +144,24 @@ public class StudyDirectoryNode extends PsiDirectoryNode {
           FileEditorManager.getInstance(myProject).closeFile(openFile);
         }
         VirtualFile child = null;
-        Set<String> fileNames = task.getTaskFiles().keySet();
-        for (String name : fileNames) {
-           child = taskDir.findChild(name);
-          if (child != null) {
-            FileEditorManager.getInstance(myProject).openFile(child, true);
+        Map<String, TaskFile> taskFiles = task.getTaskFiles();
+        for (Map.Entry<String, TaskFile> entry: taskFiles.entrySet()) {
+          VirtualFile file = taskDir.findChild(entry.getKey());
+          if (file != null) {
+            FileEditorManager.getInstance(myProject).openFile(file, true);
+          }
+          if (!entry.getValue().getTaskWindows().isEmpty()) {
+            child = file;
           }
         }
         if (child != null) {
           ProjectView.getInstance(myProject).select(child, child, false);
+          FileEditorManager.getInstance(myProject).openFile(child, true);
+        } else {
+          VirtualFile[] children = taskDir.getChildren();
+          if (children.length > 0) {
+            ProjectView.getInstance(myProject).select(children[0], children[0], false);
+          }
         }
       }
     }