diff --git a/python/edu/course-creator/resources/META-INF/plugin.xml b/python/edu/course-creator/resources/META-INF/plugin.xml index 7173f9d1c15b..f4e0d510a8d8 100644 --- a/python/edu/course-creator/resources/META-INF/plugin.xml +++ b/python/edu/course-creator/resources/META-INF/plugin.xml @@ -48,6 +48,9 @@ + + + diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCChangeCourseInfo.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCChangeCourseInfo.java new file mode 100644 index 000000000000..0f3b3ae4a092 --- /dev/null +++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/actions/CCChangeCourseInfo.java @@ -0,0 +1,106 @@ +package org.jetbrains.plugins.coursecreator.actions; + +import com.intellij.ide.IdeView; +import com.intellij.ide.util.DirectoryChooserUtil; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.LangDataKeys; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.project.DumbAwareAction; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.psi.PsiDirectory; +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.ui.CCNewProjectPanel; + +import javax.swing.*; + +public class CCChangeCourseInfo extends DumbAwareAction { + public CCChangeCourseInfo() { + super("Change course information", "Change course information", null); + } + + @Override + public void update(@NotNull AnActionEvent event) { + if (!CCProjectService.setCCActionAvailable(event)) { + return; + } + final Presentation presentation = event.getPresentation(); + presentation.setVisible(false); + presentation.setEnabled(false); + final Project project = event.getData(CommonDataKeys.PROJECT); + if (project == null) { + return; + } + final IdeView view = event.getData(LangDataKeys.IDE_VIEW); + if (view == null) { + return; + } + final PsiDirectory[] directories = view.getDirectories(); + if (directories.length == 0) { + return; + } + final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view); + if (directory != null && !project.getBaseDir().equals(directory.getVirtualFile())) { + return; + } + presentation.setVisible(true); + presentation.setEnabled(true); + + } + + @Override + public void actionPerformed(@NotNull AnActionEvent e) { + if (!CCProjectService.setCCActionAvailable(e)) { + return; + } + final Project project = e.getProject(); + if (project == null) { + return; + } + Course course = CCProjectService.getInstance(project).getCourse(); + if (course == null) { + return; + } + final IdeView view = e.getData(LangDataKeys.IDE_VIEW); + if (view == null) { + return; + } + final PsiDirectory[] directories = view.getDirectories(); + if (directories.length == 0) { + return; + } + final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view); + if (directory != null && !project.getBaseDir().equals(directory.getVirtualFile())) { + return; + } + CCNewProjectPanel panel = new CCNewProjectPanel(course.getName(), course.getAuthor(), course.getDescription()); + ChangeCourseInfoDialog changeCourseInfoDialog = + new ChangeCourseInfoDialog(project, panel); + changeCourseInfoDialog.show(); + if (changeCourseInfoDialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) { + course.setAuthor(panel.getAuthor()); + course.setName(panel.getName()); + course.setDescription(panel.getDescription()); + } + } + + static class ChangeCourseInfoDialog extends DialogWrapper { + + CCNewProjectPanel myNewProjectPanel; + public ChangeCourseInfoDialog(@Nullable Project project, CCNewProjectPanel panel) { + super(project); + myNewProjectPanel = panel; + init(); + } + + @Nullable + @Override + protected JComponent createCenterPanel() { + return myNewProjectPanel.getMainPanel(); + } + } +} diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Course.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Course.java index e124a6eb305d..e9af3472f260 100644 --- a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Course.java +++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/format/Course.java @@ -58,4 +58,20 @@ public class Course { } Collections.sort(lessons); } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public void setName(String name) { + this.name = name; + } + + public void setDescription(String description) { + this.description = description; + } } diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CCNewProjectPanel.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CCNewProjectPanel.java index d463718978bb..de23a904422c 100644 --- a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CCNewProjectPanel.java +++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CCNewProjectPanel.java @@ -27,6 +27,13 @@ public class CCNewProjectPanel { myDescription.setLineWrap(true); } + public CCNewProjectPanel(String name, String author, String description) { + this(); + myName.setText(name); + myAuthorField.setText(author); + myDescription.setText(description); + } + public JPanel getMainPanel() { return myPanel; } @@ -54,7 +61,9 @@ public class CCNewProjectPanel { @Override protected void textChanged(DocumentEvent e) { - myValidationManager.validate(); + if (myValidationManager != null) { + myValidationManager.validate(); + } } } }