mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EDU-194 Add actions to change course author/description
This commit is contained in:
@@ -48,6 +48,9 @@
|
||||
<action id="CreateLesson" class="org.jetbrains.plugins.coursecreator.actions.CCCreateLesson">
|
||||
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewFile"/>
|
||||
</action>
|
||||
<action id="ChangeCourseInfo" class="org.jetbrains.plugins.coursecreator.actions.CCChangeCourseInfo">
|
||||
<add-to-group group-id="ProjectViewPopupMenu" anchor="before" relative-to-action="PackCourse"/>
|
||||
</action>
|
||||
<action id="CreateTaskFile" class="org.jetbrains.plugins.coursecreator.actions.CCCreateTaskFile">
|
||||
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewFile"/>
|
||||
</action>
|
||||
|
||||
+106
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user