98bcba87c6c838603425b0c190db1e6b2bb4f844
[idea/community.git] / python / educational-core / course-creator / src / com / jetbrains / edu / coursecreator / handlers / CCTaskRenameHandler.java
1 package com.jetbrains.edu.coursecreator.handlers;
2
3 import com.intellij.ide.TitledHandler;
4 import com.intellij.openapi.project.Project;
5 import com.intellij.psi.PsiDirectory;
6 import com.jetbrains.edu.learning.core.EduNames;
7 import com.jetbrains.edu.learning.courseFormat.Course;
8 import com.jetbrains.edu.learning.courseFormat.Lesson;
9 import com.jetbrains.edu.learning.courseFormat.Task;
10 import org.jetbrains.annotations.NotNull;
11
12 public class CCTaskRenameHandler extends CCRenameHandler implements TitledHandler {
13   @Override
14   protected boolean isAvailable(String name) {
15     return name.contains(EduNames.TASK);
16   }
17
18   @Override
19   protected void rename(@NotNull Project project, @NotNull Course course, @NotNull PsiDirectory directory) {
20     PsiDirectory lessonDir = directory.getParent();
21     if (lessonDir == null || !lessonDir.getName().contains(EduNames.LESSON)) {
22       return;
23     }
24     Lesson lesson = course.getLesson(lessonDir.getName());
25     if (lesson == null) {
26       return;
27     }
28     String directoryName = directory.getName();
29     Task task = lesson.getTask(directoryName);
30     if (task != null) {
31       processRename(task, EduNames.TASK, project);
32     }
33   }
34
35   @Override
36   public String getActionTitle() {
37     return "Rename task";
38   }
39 }