+
+ private void updateInfoIndexes() {
+ for (TaskFile taskFile : myTask.getTaskFiles().values()) {
+ for (AnswerPlaceholder placeholder : taskFile.getAnswerPlaceholders()) {
+ List<Integer> filtered = ContainerUtil.filter(placeholder.getSubtaskInfos().keySet(), index -> index > mySubtaskIndex);
+ Map<Integer, AnswerPlaceholderSubtaskInfo> savedInfos = new HashMap<>();
+ for (Integer index : filtered) {
+ savedInfos.put(index, placeholder.getSubtaskInfos().get(index));
+ placeholder.getSubtaskInfos().remove(index);
+ }
+ for (Integer index : filtered) {
+ placeholder.getSubtaskInfos().put(index - 1, savedInfos.get(index));
+ }
+ }
+ }
+ }
+
+ private void renameFiles(VirtualFile taskDir) {
+ ApplicationManager.getApplication().runWriteAction(() -> {
+ Map<VirtualFile, String> newNames = new HashMap<>();
+ for (VirtualFile virtualFile : taskDir.getChildren()) {
+ int subtaskIndex = CCUtils.getSubtaskIndex(myProject, virtualFile);
+ if (subtaskIndex == -1) {
+ continue;
+ }
+ if (subtaskIndex > mySubtaskIndex) {
+ String index = subtaskIndex == 1 ? "" : Integer.toString(subtaskIndex - 1);
+ String fileName = virtualFile.getName();
+ String nameWithoutExtension = FileUtil.getNameWithoutExtension(fileName);
+ String extension = FileUtilRt.getExtension(fileName);
+ int subtaskMarkerIndex = nameWithoutExtension.indexOf(EduNames.SUBTASK_MARKER);
+ String newName = subtaskMarkerIndex == -1
+ ? nameWithoutExtension
+ : nameWithoutExtension.substring(0, subtaskMarkerIndex);
+ newName += index.isEmpty() ? "" : EduNames.SUBTASK_MARKER;
+ newName += index + "." + extension;
+ newNames.put(virtualFile, newName);
+ }
+ }
+ for (Map.Entry<VirtualFile, String> entry : newNames.entrySet()) {
+ try {
+ entry.getKey().rename(myProject, entry.getValue());
+ }
+ catch (IOException e) {
+ LOG.info(e);
+ }
+ }
+ });
+ }
+
+ private void deleteSubtaskFiles(VirtualFile taskDir) {
+ ApplicationManager.getApplication().runWriteAction(() -> {
+ List<VirtualFile> filesToDelete = new ArrayList<>();
+ for (VirtualFile file : taskDir.getChildren()) {
+ int index = CCUtils.getSubtaskIndex(myProject, file);
+ if (index != -1 && mySubtaskIndex == index) {
+ filesToDelete.add(file);
+ }
+ }
+ for (VirtualFile file : filesToDelete) {
+ try {
+ file.delete(myProject);
+ }
+ catch (IOException e) {
+ LOG.info(e);
+ }
+ }
+ });
+ }