mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Create course from course creator plugin (EDU-349)
This commit is contained in:
+13
-12
@@ -68,20 +68,19 @@ public class CCCreateCourseArchive extends DumbAwareAction {
|
||||
if (project == null || module == null) {
|
||||
return;
|
||||
}
|
||||
createCourseArchive(project, module);
|
||||
}
|
||||
|
||||
private void createCourseArchive(final Project project, Module module) {
|
||||
final Course course = StudyTaskManager.getInstance(project).getCourse();
|
||||
if (course == null) return;
|
||||
CreateCourseArchiveDialog dlg = new CreateCourseArchiveDialog(project, this);
|
||||
dlg.show();
|
||||
if (dlg.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
|
||||
return;
|
||||
}
|
||||
final VirtualFile baseDir = project.getBaseDir();
|
||||
createCourseArchive(project, module, myZipName, myLocationDir, true);
|
||||
}
|
||||
|
||||
VirtualFile archiveFolder = CCUtils.generateFolder(project, module, this, myZipName);
|
||||
public static void createCourseArchive(final Project project, Module module, String zipName, String locationDir, boolean showMessage) {
|
||||
final Course course = StudyTaskManager.getInstance(project).getCourse();
|
||||
if (course == null) return;
|
||||
final VirtualFile baseDir = project.getBaseDir();
|
||||
VirtualFile archiveFolder = CCUtils.generateFolder(project, module, null, zipName);
|
||||
if (archiveFolder == null) {
|
||||
return;
|
||||
}
|
||||
@@ -112,7 +111,7 @@ public class CCCreateCourseArchive extends DumbAwareAction {
|
||||
generateJson(project, archiveFolder);
|
||||
resetTaskFiles(savedTaskFiles);
|
||||
VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
|
||||
packCourse(archiveFolder);
|
||||
packCourse(archiveFolder, locationDir, zipName, showMessage);
|
||||
synchronize(project);
|
||||
}
|
||||
|
||||
@@ -173,16 +172,18 @@ public class CCCreateCourseArchive extends DumbAwareAction {
|
||||
ProjectView.getInstance(project).refresh();
|
||||
}
|
||||
|
||||
private void packCourse(@NotNull final VirtualFile baseDir) {
|
||||
private static void packCourse(@NotNull final VirtualFile baseDir, String locationDir, String zipName, boolean showMessage) {
|
||||
try {
|
||||
final File zipFile = new File(myLocationDir, myZipName + ".zip");
|
||||
final File zipFile = new File(locationDir, zipName + ".zip");
|
||||
ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
|
||||
VirtualFile[] courseFiles = baseDir.getChildren();
|
||||
for (VirtualFile file : courseFiles) {
|
||||
ZipUtil.addFileOrDirRecursively(zos, null, new File(file.getPath()), file.getName(), null, null);
|
||||
}
|
||||
zos.close();
|
||||
Messages.showInfoMessage("Course archive was saved to " + zipFile.getPath(), "Course Archive Was Created Successfully");
|
||||
if (showMessage) {
|
||||
Messages.showInfoMessage("Course archive was saved to " + zipFile.getPath(), "Course Archive Was Created Successfully");
|
||||
}
|
||||
}
|
||||
catch (IOException e1) {
|
||||
LOG.error(e1);
|
||||
|
||||
@@ -14,5 +14,7 @@
|
||||
<orderEntry type="module" module-name="educational-python" />
|
||||
<orderEntry type="module" module-name="python-community" />
|
||||
<orderEntry type="module" module-name="student" />
|
||||
<orderEntry type="module" module-name="python-ide-community" />
|
||||
<orderEntry type="module" module-name="student-python" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -32,4 +32,11 @@
|
||||
<pyReferenceResolveProvider implementation="com.jetbrains.edu.coursecreator.PyCCReferenceResolveProvider"/>
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
<action class="com.jetbrains.edu.coursecreator.PyCCCreateProjectFromArchive" id="PyCC.NewEdu" text="Create New Educational Project">
|
||||
<add-to-group group-id="CCFileGroup" anchor="last"/>
|
||||
<add-to-group group-id="CCProjectViewGroup" anchor="last"/>
|
||||
</action>
|
||||
</actions>
|
||||
|
||||
</idea-plugin>
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.jetbrains.edu.coursecreator;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.platform.DirectoryProjectGenerator;
|
||||
import com.jetbrains.edu.coursecreator.actions.CCCreateCourseArchive;
|
||||
import com.jetbrains.edu.learning.PyStudyDirectoryProjectGenerator;
|
||||
import com.jetbrains.edu.learning.StudyTaskManager;
|
||||
import com.jetbrains.edu.learning.courseFormat.Course;
|
||||
import com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator;
|
||||
import com.jetbrains.edu.learning.stepic.CourseInfo;
|
||||
import com.jetbrains.python.newProject.actions.PyCharmNewProjectStep;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class CreateFromArchiveProjectStep extends PyCharmNewProjectStep {
|
||||
|
||||
public CreateFromArchiveProjectStep(Project project, Module module) {
|
||||
super(new MyCustomization(project, module));
|
||||
}
|
||||
|
||||
protected static class MyCustomization extends PyCharmNewProjectStep.Customization {
|
||||
|
||||
private final Project myProject;
|
||||
private final Module myModule;
|
||||
private PyStudyDirectoryProjectGenerator myGenerator = new PyStudyDirectoryProjectGenerator();
|
||||
|
||||
public MyCustomization(Project project,
|
||||
Module module) {
|
||||
|
||||
myProject = project;
|
||||
myModule = module;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected DirectoryProjectGenerator[] getProjectGenerators() {
|
||||
return new DirectoryProjectGenerator[] {};
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected DirectoryProjectGenerator createEmptyProjectGenerator() {
|
||||
Course course = StudyTaskManager.getInstance(myProject).getCourse();
|
||||
if (course != null) {
|
||||
VirtualFile folder = CCUtils.getGeneratedFilesFolder(myProject, myModule);
|
||||
String zipName = FileUtil.sanitizeFileName(course.getName());
|
||||
String locationDir = folder.getPath();
|
||||
CCCreateCourseArchive.createCourseArchive(myProject, myModule, zipName, locationDir, false);
|
||||
String path = FileUtil.join(folder.getPath(), zipName + ".zip");
|
||||
StudyProjectGenerator generator = myGenerator.getGenerator();
|
||||
CourseInfo info = generator.addLocalCourse(path);
|
||||
assert info != null;
|
||||
generator.setSelectedCourse(info);
|
||||
}
|
||||
return myGenerator;
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.jetbrains.edu.coursecreator;
|
||||
|
||||
import com.intellij.ide.util.projectWizard.AbstractNewProjectDialog;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
public class PyCCCreateProjectFromArchive extends DumbAwareAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final Project project = e.getData(CommonDataKeys.PROJECT);
|
||||
final Module module = e.getData(LangDataKeys.MODULE);
|
||||
if (project == null || module == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AbstractNewProjectDialog dialog = new AbstractNewProjectDialog() {
|
||||
@Override
|
||||
protected DefaultActionGroup createRootStep() {
|
||||
return new CreateFromArchiveProjectStep(project, module);
|
||||
}
|
||||
};
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Presentation presentation = e.getPresentation();
|
||||
Project project = e.getProject();
|
||||
presentation.setEnabledAndVisible(project != null && CCUtils.isCourseCreator(project));
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class PyCharmNewProjectStep extends AbstractNewProjectStep {
|
||||
@@ -40,7 +39,11 @@ public class PyCharmNewProjectStep extends AbstractNewProjectStep {
|
||||
super(new Customization());
|
||||
}
|
||||
|
||||
private static class Customization extends AbstractNewProjectStep.Customization {
|
||||
public PyCharmNewProjectStep(@NotNull AbstractNewProjectStep.Customization customization) {
|
||||
super(customization);
|
||||
}
|
||||
|
||||
protected static class Customization extends AbstractNewProjectStep.Customization {
|
||||
private final List<DirectoryProjectGenerator> pluginSpecificGenerators = Lists.newArrayList();
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user