diff --git a/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java b/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java index 2d68478b6845..331366280c17 100644 --- a/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java +++ b/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java @@ -44,7 +44,7 @@ public class CCUtils { @Nullable public static CCLanguageManager getStudyLanguageManager(@NotNull final Course course) { - Language language = Language.findLanguageByID(course.getLanguage()); + Language language = Language.findLanguageByID(course.getLanguageID()); return language == null ? null : CCLanguageManager.INSTANCE.forLanguage(language); } diff --git a/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/ui/CCNewProjectPanel.form b/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/ui/CCNewProjectPanel.form index d4c33c0524d1..9af0ba14c209 100644 --- a/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/ui/CCNewProjectPanel.form +++ b/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/ui/CCNewProjectPanel.form @@ -1,6 +1,6 @@
- + @@ -26,7 +26,7 @@ - + @@ -52,7 +52,7 @@ - + @@ -60,6 +60,20 @@ + + + + + + + + + + + + + + diff --git a/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/ui/CCNewProjectPanel.java b/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/ui/CCNewProjectPanel.java index b3b141d6cb8c..7b4830c9cb43 100644 --- a/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/ui/CCNewProjectPanel.java +++ b/python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/ui/CCNewProjectPanel.java @@ -1,10 +1,12 @@ package com.jetbrains.edu.coursecreator.ui; import com.intellij.facet.ui.FacetValidatorsManager; +import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.DocumentAdapter; import com.intellij.ui.JBColor; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.DocumentEvent; @@ -14,10 +16,14 @@ public class CCNewProjectPanel { private JTextArea myDescription; private JTextField myName; private JTextField myAuthorField; + private JLabel myLanguageLevelLabel; + private ComboBox myLanguageLevelCombobox; private FacetValidatorsManager myValidationManager; public CCNewProjectPanel() { + myLanguageLevelLabel.setVisible(false); + myLanguageLevelCombobox.setVisible(false); final String userName = System.getProperty("user.name"); if (userName != null) { myAuthorField.setText(userName); @@ -81,4 +87,20 @@ public class CCNewProjectPanel { public JTextField getNameField() { return myName; } + + public JLabel getLanguageLevelLabel() { + return myLanguageLevelLabel; + } + + public ComboBox getLanguageLevelCombobox() { + return myLanguageLevelCombobox; + } + + @Nullable + public String getLanguageVersion() { + if (!myLanguageLevelCombobox.isVisible() || myLanguageLevelCombobox.getItemCount() == 0) { + return null; + } + return (String)myLanguageLevelCombobox.getSelectedItem(); + } } diff --git a/python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/Course.java b/python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/Course.java index fa4f47594757..98e3eeca0f1b 100644 --- a/python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/Course.java +++ b/python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/Course.java @@ -10,6 +10,7 @@ import com.jetbrains.edu.learning.core.EduUtils; import com.jetbrains.edu.learning.stepic.StepicUser; import org.jdom.Element; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -122,9 +123,14 @@ public class Course { } public Language getLanguageById() { - return Language.findLanguageByID(myLanguage); + return Language.findLanguageByID(getLanguageID()); } + /** + * This method should be used by serialized only + * Use {@link #getLanguageID()} and {@link #getLanguageVersion()} methods instead + */ + @Deprecated public String getLanguage() { return myLanguage; } @@ -133,6 +139,19 @@ public class Course { myLanguage = language; } + public String getLanguageID() { + return myLanguage.split(" ")[0]; + } + + @Nullable + public String getLanguageVersion() { + String[] split = myLanguage.split(" "); + if (split.length <= 1) { + return null; + } + return split[1]; + } + public void setAuthors(List authors) { this.authors = authors; } diff --git a/python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java b/python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java index b0b612df6f2e..b37ea4c4f0f0 100644 --- a/python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java +++ b/python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java @@ -12,6 +12,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.platform.DirectoryProjectGenerator; @@ -27,6 +28,7 @@ import com.jetbrains.edu.learning.courseFormat.Course; import com.jetbrains.edu.learning.statistics.EduUsagesCollector; import com.jetbrains.python.PythonLanguage; import com.jetbrains.python.newProject.PythonProjectGenerator; +import com.jetbrains.python.psi.LanguageLevel; import icons.CourseCreatorPythonIcons; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -38,6 +40,9 @@ import java.io.File; public class PyCCProjectGenerator extends PythonProjectGenerator implements DirectoryProjectGenerator { private static final Logger LOG = Logger.getInstance(PyCCProjectGenerator.class); + public static final String ALL_VERSIONS = "All versions"; + public static final String PYTHON_3 = "3x"; + public static final String PYTHON_2 = "2x"; private CCNewProjectPanel mySettingsPanel; @Nls @@ -56,14 +61,11 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire @Override public void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir, @Nullable Object settings, @NotNull Module module) { - generateProject(project, baseDir, mySettingsPanel.getName(), - mySettingsPanel.getAuthors(), mySettingsPanel.getDescription()); + generateProject(project, baseDir, mySettingsPanel); } - public static void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir, - @NotNull final String name, @NotNull final String[] authors, - @NotNull final String description) { - final Course course = getCourse(project, name, authors, description); + public static void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir, CCNewProjectPanel settingsPanel) { + final Course course = getCourse(project, settingsPanel); EduUsagesCollector.projectTypeCreated(CCUtils.COURSE_MODE); final PsiDirectory projectDir = PsiManager.getInstance(project).findDirectory(baseDir); @@ -94,12 +96,19 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire } @NotNull - private static Course getCourse(@NotNull Project project, @NotNull String name, @NotNull String[] authors, @NotNull String description) { + private static Course getCourse(@NotNull Project project, @NotNull CCNewProjectPanel settingsPanel) { final Course course = new Course(); + String name = settingsPanel.getName(); course.setName(name); - course.setAuthors(authors); - course.setDescription(description); - course.setLanguage(PythonLanguage.getInstance().getID()); + course.setAuthors(settingsPanel.getAuthors()); + course.setDescription(settingsPanel.getDescription()); + + String language = PythonLanguage.getInstance().getID(); + String version = settingsPanel.getLanguageVersion(); + if (version != null && !ALL_VERSIONS.equals(version)) { + language += " " + version; + } + course.setLanguage(language); course.setCourseMode(CCUtils.COURSE_MODE); File coursesDir = new File(PathManager.getConfigPath(), "courses"); @@ -125,6 +134,7 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire @Override public JPanel extendBasePanel() throws ProcessCanceledException { mySettingsPanel = new CCNewProjectPanel(); + setupLanguageLevels(mySettingsPanel); mySettingsPanel.registerValidators(new FacetValidatorsManager() { public void registerValidator(FacetEditorValidator validator, JComponent... componentsToWatch) { throw new UnsupportedOperationException(); @@ -136,4 +146,18 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire }); return mySettingsPanel.getMainPanel(); } + + private static void setupLanguageLevels(CCNewProjectPanel panel) { + JLabel languageLevelLabel = panel.getLanguageLevelLabel(); + languageLevelLabel.setText("Python Version:"); + languageLevelLabel.setVisible(true); + ComboBox languageLevelCombobox = panel.getLanguageLevelCombobox(); + languageLevelCombobox.addItem(ALL_VERSIONS); + languageLevelCombobox.addItem(PYTHON_3); + languageLevelCombobox.addItem(PYTHON_2); + for (LanguageLevel level : LanguageLevel.values()) { + languageLevelCombobox.addItem(level.toString()); + } + languageLevelCombobox.setVisible(true); + } } diff --git a/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyPluginConfigurator.java b/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyPluginConfigurator.java index 5a163337ecfa..76890be13420 100644 --- a/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyPluginConfigurator.java +++ b/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyPluginConfigurator.java @@ -34,6 +34,6 @@ public class PyStudyPluginConfigurator extends StudyBasePluginConfigurator { StudyTaskManager taskManager = StudyTaskManager.getInstance(project); if (taskManager == null) return false; Course course = taskManager.getCourse(); - return course != null && "Python".equals(course.getLanguage()) && "PyCharm".equals(course.getCourseType()); + return course != null && "Python".equals(course.getLanguageID()) && "PyCharm".equals(course.getCourseType()); } }