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;
}
generateJson(project, archiveFolder);
resetTaskFiles(savedTaskFiles);
VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
- packCourse(archiveFolder);
+ packCourse(archiveFolder, locationDir, zipName, showMessage);
synchronize(project);
}
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);
<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>
\ No newline at end of file
<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>
\ No newline at end of file
--- /dev/null
+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;
+ }
+ }
+}
--- /dev/null
+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));
+ }
+}
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
-import java.util.Comparator;
import java.util.List;
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