handle src dir inside task dir
authorLiana.Bakradze <liana.bakradze@jetbrains.com>
Tue, 25 Oct 2016 16:55:05 +0000 (19:55 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 17 Nov 2016 14:08:31 +0000 (17:08 +0300)
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/handlers/CCLessonRenameHandler.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/handlers/CCRenameHandler.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/handlers/CCTaskRenameHandler.java

index 0efe1110a8cac4d8de0582a605c3b81e9cef8612..ba817b6288611126896bbdb8ab3e23c4bed8f129 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;
@@ -10,8 +11,8 @@ import org.jetbrains.annotations.NotNull;
 
 public class CCLessonRenameHandler extends CCRenameHandler implements TitledHandler {
   @Override
-  protected boolean isAvailable(String name) {
-    return name.contains(EduNames.LESSON);
+  protected boolean isAvailable(VirtualFile dir) {
+    return dir.getName().contains(EduNames.LESSON);
   }
 
   @Override
index 9814a6631fe23c4d5ed1397ac4145defc18734b8..0be2ff5a9aa788b91dbe2ac8a356579360bc166a 100644 (file)
@@ -30,10 +30,10 @@ public abstract class CCRenameHandler implements RenameHandler {
       return false;
     }
     VirtualFile directory = ((PsiDirectory)element).getVirtualFile();
-    return isAvailable(directory.getName());
+    return isAvailable(directory);
   }
 
-  protected abstract boolean isAvailable(String name);
+  protected abstract boolean isAvailable(VirtualFile directory);
 
   @Override
   public boolean isRenaming(DataContext dataContext) {
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;