handle src dir inside task dir
[idea/community.git] / python / educational-core / course-creator / src / com / jetbrains / edu / coursecreator / handlers / CCTaskRenameHandler.java
index 98bcba87c6c838603425b0c190db1e6b2bb4f844..6075fb5167f713adb69a40b3c2576b9720e1ed52 100644 (file)
@@ -2,6 +2,7 @@ package com.jetbrains.edu.coursecreator.handlers;
 
 import com.intellij.ide.TitledHandler;
 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;
@@ -11,12 +12,25 @@ import org.jetbrains.annotations.NotNull;
 
 public class CCTaskRenameHandler extends CCRenameHandler implements TitledHandler {
   @Override
-  protected boolean isAvailable(String name) {
-    return name.contains(EduNames.TASK);
+  protected boolean isAvailable(VirtualFile dir) {
+    if (dir.getName().contains(EduNames.TASK)) {
+      return true;
+    }
+    VirtualFile parent = dir.getParent();
+    if (parent != null && parent.getName().contains(EduNames.TASK)) {
+      return true;
+    }
+    return false;
   }
 
   @Override
   protected void rename(@NotNull Project project, @NotNull Course course, @NotNull PsiDirectory directory) {
+    if (directory.getName().equals(EduNames.SRC)) {
+      directory = directory.getParent();
+      if (directory == null) {
+        return;
+      }
+    }
     PsiDirectory lessonDir = directory.getParent();
     if (lessonDir == null || !lessonDir.getName().contains(EduNames.LESSON)) {
       return;