delete subtask
[idea/community.git] / python / educational-core / course-creator / src / com / jetbrains / edu / coursecreator / CCUtils.java
index cf5af7a8398d6e8c229653b56329b8a0032d02f2..ea697bdc1ded757c336925b8be4840bac33438ea 100644 (file)
@@ -26,6 +26,7 @@ import com.intellij.util.Function;
 import com.jetbrains.edu.coursecreator.settings.CCSettings;
 import com.jetbrains.edu.learning.StudyTaskManager;
 import com.jetbrains.edu.learning.StudyUtils;
+import com.jetbrains.edu.learning.core.EduNames;
 import com.jetbrains.edu.learning.core.EduUtils;
 import com.jetbrains.edu.learning.courseFormat.Course;
 import com.jetbrains.edu.learning.courseFormat.StudyItem;
@@ -47,6 +48,28 @@ public class CCUtils {
   public static final String GENERATED_FILES_FOLDER = ".coursecreator";
   public static final String COURSE_MODE = "Course Creator";
 
+  public static int getSubtaskIndex(Project project, VirtualFile file) {
+    String fileName = file.getName();
+    String name = FileUtil.getNameWithoutExtension(fileName);
+    boolean canBeSubtaskFile = isTestsFile(project, file) || StudyUtils.isTaskDescriptionFile(fileName);
+    if (!canBeSubtaskFile) {
+      return -1;
+    }
+    if (!name.contains(EduNames.SUBTASK_MARKER)) {
+      return 0;
+    }
+    int markerIndex = name.indexOf(EduNames.SUBTASK_MARKER);
+    String index = name.substring(markerIndex + EduNames.SUBTASK_MARKER.length());
+    if (index.isEmpty()) {
+      return -1;
+    }
+    try {
+      return Integer.valueOf(index);
+    } catch (NumberFormatException e) {
+      return -1;
+    }
+  }
+
   @Nullable
   public static CCLanguageManager getStudyLanguageManager(@NotNull final Course course) {
     Language language = Language.findLanguageByID(course.getLanguageID());