mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EDU-235 Create sample lesson and task in course
This commit is contained in:
+5
-2
@@ -20,6 +20,8 @@ import icons.CourseCreatorIcons;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.coursecreator.actions.CCCreateLesson;
|
||||
import org.jetbrains.plugins.coursecreator.actions.CCCreateTask;
|
||||
import org.jetbrains.plugins.coursecreator.format.Course;
|
||||
import org.jetbrains.plugins.coursecreator.ui.CCNewProjectPanel;
|
||||
|
||||
@@ -69,9 +71,10 @@ public class CCProjectGenerator extends PythonProjectGenerator implements Direct
|
||||
catch (Exception ignored) {
|
||||
}
|
||||
DirectoryUtil.createSubdirectories("hints", projectDir, "\\/");
|
||||
final PsiDirectory lessonDir = CCCreateLesson.createLesson(projectDir, 1, null, null, course);
|
||||
CCCreateTask.createTask(null, project, lessonDir, false);
|
||||
}
|
||||
}.execute();
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -81,7 +84,7 @@ public class CCProjectGenerator extends PythonProjectGenerator implements Direct
|
||||
message = mySettingsPanel.getDescription().equals("") ? "Enter description" : message;
|
||||
message = mySettingsPanel.getAuthor().equals("") ? "Enter author name" : message;
|
||||
message = mySettingsPanel.getName().equals("") ? "Enter course name" : message;
|
||||
return message.equals("")? ValidationResult.OK : new ValidationResult(message) ;
|
||||
return message.equals("") ? ValidationResult.OK : new ValidationResult(message);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+18
-7
@@ -14,6 +14,7 @@ import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.coursecreator.CCProjectService;
|
||||
import org.jetbrains.plugins.coursecreator.format.Course;
|
||||
import org.jetbrains.plugins.coursecreator.format.Lesson;
|
||||
@@ -43,17 +44,27 @@ public class CCCreateLesson extends DumbAwareAction {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final PsiDirectory lessonDirectory = DirectoryUtil.createSubdirectories("lesson" + (size+1), directory, "\\/");
|
||||
if (lessonDirectory != null) {
|
||||
view.selectElement(lessonDirectory);
|
||||
final Lesson lesson = new Lesson(lessonName);
|
||||
lesson.setIndex(size + 1);
|
||||
course.addLesson(lesson, lessonDirectory);
|
||||
}
|
||||
createLesson(directory, size + 1, lessonName, view, course);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiDirectory createLesson(@NotNull final PsiDirectory projectDir, int index, String name, final IdeView view,
|
||||
@NotNull final Course course) {
|
||||
String lessonFolderName = "lesson" + index;
|
||||
final PsiDirectory lessonDirectory = DirectoryUtil.createSubdirectories("lesson" + index, projectDir, "\\/");
|
||||
if (lessonDirectory != null) {
|
||||
if (view != null) {
|
||||
view.selectElement(lessonDirectory);
|
||||
}
|
||||
final Lesson lesson = new Lesson(name != null ? name : lessonFolderName);
|
||||
lesson.setIndex(index);
|
||||
course.addLesson(lesson, lessonDirectory);
|
||||
}
|
||||
return lessonDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent event) {
|
||||
if (!CCProjectService.setCCActionAvailable(event)) {
|
||||
|
||||
+23
-12
@@ -36,24 +36,35 @@ public class CCCreateTask extends DumbAwareAction {
|
||||
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
|
||||
final Project project = e.getData(CommonDataKeys.PROJECT);
|
||||
|
||||
if (view == null || project == null) {
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
|
||||
|
||||
if (directory == null) return;
|
||||
createTask(view, project, directory, true);
|
||||
}
|
||||
|
||||
public static void createTask(final IdeView view, final Project project, final PsiDirectory lessonDir, boolean showDialog) {
|
||||
final CCProjectService service = CCProjectService.getInstance(project);
|
||||
final Course course = service.getCourse();
|
||||
final Lesson lesson = course.getLesson(directory.getName());
|
||||
final Lesson lesson = course.getLesson(lessonDir.getName());
|
||||
final int size = lesson.getTaskList().size();
|
||||
final String taskName;
|
||||
if (showDialog) {
|
||||
taskName = Messages.showInputDialog("Name:", "Task Name", null, "task" + (size + 1), null);
|
||||
}
|
||||
else {
|
||||
taskName = "task" + (size + 1);
|
||||
}
|
||||
|
||||
final String taskName = Messages.showInputDialog("Name:", "Task Name", null, "task" + (size + 1), null);
|
||||
if (taskName == null) return;
|
||||
|
||||
if (taskName == null) {
|
||||
return;
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final PsiDirectory taskDirectory = DirectoryUtil.createSubdirectories("task" + (size + 1), directory, "\\/");
|
||||
final PsiDirectory taskDirectory = DirectoryUtil.createSubdirectories("task" + (size + 1), lessonDir, "\\/");
|
||||
if (taskDirectory != null) {
|
||||
final FileTemplate template = FileTemplateManager.getInstance().getInternalTemplate("task.html");
|
||||
final FileTemplate testsTemplate = FileTemplateManager.getInstance().getInternalTemplate("tests");
|
||||
@@ -74,16 +85,17 @@ public class CCCreateTask extends DumbAwareAction {
|
||||
for (VirtualFile virtualFile : fileEditorManager.getOpenFiles()) {
|
||||
fileEditorManager.closeFile(virtualFile);
|
||||
}
|
||||
EditorHelper.openInEditor(testsFile, false);
|
||||
EditorHelper.openInEditor(taskPyFile, false);
|
||||
view.selectElement(taskFile);
|
||||
if (view != null) {
|
||||
EditorHelper.openInEditor(testsFile, false);
|
||||
EditorHelper.openInEditor(taskPyFile, false);
|
||||
view.selectElement(taskFile);
|
||||
EditorHelper.openInEditor(taskFile, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -126,6 +138,5 @@ public class CCCreateTask extends DumbAwareAction {
|
||||
|
||||
presentation.setVisible(true);
|
||||
presentation.setEnabled(true);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user