private void deleteTaskFile(Course course, VirtualFile removedFile) { VirtualFile taskDir = removedFile.getParent(); if (taskDir == null || !taskDir.getName().contains("task")) { return; } VirtualFile lessonDir = taskDir.getParent(); if (lessonDir == null || !lessonDir.getName().contains("lesson")) { return; } VirtualFile courseDir = lessonDir.getParent(); if (!courseDir.getName().equals(myProject.getName())) { return; } Lesson lesson = course.getLesson(lessonDir.getName()); if (lesson == null) { return; } Task task = lesson.getTask(taskDir.getName()); if (task == null) { return; } TaskFile taskFile = task.getTaskFile(removedFile.getName()); if (taskFile == null) { return; } String name = CCProjectService.getRealTaskFileName(removedFile.getName()); task.getTaskFiles().remove(name); }
private void deleteTask(Course course, VirtualFile removedFile) { VirtualFile lessonDir = removedFile.getParent(); if (lessonDir == null || !lessonDir.getName().contains("lesson")) { return; } VirtualFile courseDir = lessonDir.getParent(); if (!courseDir.getName().equals(myProject.getName())) { return; } Lesson lesson = course.getLesson(lessonDir.getName()); if (lesson == null) { return; } Task task = lesson.getTask(removedFile.getName()); if (task == null) { return; } lesson.getTaskList().remove(task); lesson.getTasksMap().remove(removedFile.getName()); }
@Override public void actionPerformed(final AnActionEvent e) { final IdeView view = e.getData(LangDataKeys.IDE_VIEW); final Project project = e.getData(CommonDataKeys.PROJECT); if (view == null || project == null) { return; } final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view); if (directory == null) return; final CCProjectService service = CCProjectService.getInstance(project); final Course course = service.getCourse(); final Lesson lesson = course.getLesson(directory.getName()); final int size = lesson.getTaskList().size(); final String taskName = Messages.showInputDialog("Name:", "Task Name", null, "task" + (size + 1), null); if (taskName == null) return; ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { final PsiDirectory taskDirectory = DirectoryUtil.createSubdirectories("task" + (size + 1), directory, "\\/"); if (taskDirectory != null) { final FileTemplate template = FileTemplateManager.getInstance().getInternalTemplate("task.html"); final FileTemplate testsTemplate = FileTemplateManager.getInstance().getInternalTemplate("tests"); final FileTemplate taskTemplate = FileTemplateManager.getInstance().getInternalTemplate("task.answer"); try { final PsiElement taskFile = FileTemplateUtil.createFromTemplate( template, "task.html", null, taskDirectory); final PsiElement testsFile = FileTemplateUtil.createFromTemplate( testsTemplate, "tests.py", null, taskDirectory); final PsiElement taskPyFile = FileTemplateUtil.createFromTemplate( taskTemplate, "file1", null, taskDirectory); final Task task = new Task(taskName); task.addTaskFile("file1.py", size + 1); task.setIndex(size + 1); lesson.addTask(task, taskDirectory); ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { EditorHelper.openInEditor(testsFile, false); EditorHelper.openInEditor(taskPyFile, false); view.selectElement(taskFile); } }); } catch (Exception ignored) { } } } }); }