mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
add ability to hide file from student
This commit is contained in:
@@ -47,12 +47,10 @@
|
||||
<action id="CreateTask" class="com.jetbrains.edu.coursecreator.actions.CCCreateTask">
|
||||
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewFile"/>
|
||||
</action>
|
||||
<action id="CreateTaskFile" class="com.jetbrains.edu.coursecreator.actions.CCCreateTaskFile">
|
||||
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewFile"/>
|
||||
</action>
|
||||
|
||||
<group id="CCProjectViewGroup">
|
||||
<action id="AddTaskFile" class="com.jetbrains.edu.coursecreator.actions.CCAddAsTaskFile" text="Add As Task File"/>
|
||||
<action id="AddTaskFile" class="com.jetbrains.edu.coursecreator.actions.CCAddAsTaskFile" text="Add as Task File"/>
|
||||
<action id="HideTaskFile" class="com.jetbrains.edu.coursecreator.actions.CCHideFromStudent" text="Hide from Student"/>
|
||||
<action id="ShowPreview" class="com.jetbrains.edu.coursecreator.actions.CCShowPreview">
|
||||
<add-to-group group-id="EditorTabPopupMenu"/>
|
||||
</action>
|
||||
|
||||
+8
-34
@@ -1,46 +1,20 @@
|
||||
package com.jetbrains.edu.coursecreator.actions;
|
||||
|
||||
import com.intellij.ide.projectView.ProjectView;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.edu.coursecreator.CCUtils;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import com.jetbrains.edu.learning.courseFormat.Course;
|
||||
import com.jetbrains.edu.learning.courseFormat.Task;
|
||||
|
||||
public class CCAddAsTaskFile extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
Task task = StudyUtils.getTask(project, file);
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
public class CCAddAsTaskFile extends CCTaskFileActionBase {
|
||||
|
||||
protected void performAction(VirtualFile file, Task task, Course course, Project project) {
|
||||
task.addTaskFile(file.getName(), task.getTaskFiles().size());
|
||||
ProjectView.getInstance(project).refresh();
|
||||
CCUtils.createResourceFile(file, course, StudyUtils.getTaskDir(file));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
Presentation presentation = e.getPresentation();
|
||||
if (project == null) {
|
||||
presentation.setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
|
||||
if (file == null || file.isDirectory() || StudyUtils.getTaskFile(project, file) != null) {
|
||||
presentation.setEnabledAndVisible(false);
|
||||
}
|
||||
protected boolean isAvailable(Project project, VirtualFile file) {
|
||||
return StudyUtils.getTaskFile(project, file) == null && !CCUtils.isTestsFile(project, file);
|
||||
}
|
||||
}
|
||||
|
||||
-129
@@ -1,129 +0,0 @@
|
||||
package com.jetbrains.edu.coursecreator.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.IdeView;
|
||||
import com.intellij.ide.fileTemplates.FileTemplate;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateUtil;
|
||||
import com.intellij.ide.projectView.ProjectView;
|
||||
import com.intellij.ide.util.DirectoryChooserUtil;
|
||||
import com.intellij.ide.util.EditorHelper;
|
||||
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.application.ApplicationManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.edu.learning.StudyTaskManager;
|
||||
import com.jetbrains.edu.learning.core.EduNames;
|
||||
import com.jetbrains.edu.learning.courseFormat.Course;
|
||||
import com.jetbrains.edu.learning.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.learning.courseFormat.Task;
|
||||
import com.jetbrains.edu.coursecreator.CCLanguageManager;
|
||||
import com.jetbrains.edu.coursecreator.CCUtils;
|
||||
import com.jetbrains.edu.coursecreator.ui.CreateTaskFileDialog;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.openapi.ui.DialogWrapper.OK_EXIT_CODE;
|
||||
|
||||
public class CCCreateTaskFile extends DumbAwareAction {
|
||||
|
||||
public CCCreateTaskFile() {
|
||||
super("Task File", "Create new Task File", AllIcons.FileTypes.Text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
|
||||
final Project project = e.getData(CommonDataKeys.PROJECT);
|
||||
|
||||
if (view == null || project == null) {
|
||||
return;
|
||||
}
|
||||
final PsiDirectory taskDir = DirectoryChooserUtil.getOrChooseDirectory(view);
|
||||
if (taskDir == null) return;
|
||||
PsiDirectory lessonDir = taskDir.getParent();
|
||||
if (lessonDir == null) {
|
||||
return;
|
||||
}
|
||||
final Course course = StudyTaskManager.getInstance(project).getCourse();
|
||||
final Lesson lesson = course.getLesson(lessonDir.getName());
|
||||
final Task task = lesson.getTask(taskDir.getName());
|
||||
|
||||
final int index = task.getTaskFiles().size() + 1;
|
||||
String generatedName = "file" + index;
|
||||
CreateTaskFileDialog dialog = new CreateTaskFileDialog(project, generatedName, course);
|
||||
dialog.show();
|
||||
if (dialog.getExitCode() != OK_EXIT_CODE) {
|
||||
return;
|
||||
}
|
||||
final String name = dialog.getFileName();
|
||||
if (name == null) return;
|
||||
FileType type = dialog.getFileType();
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
final CCLanguageManager CCLanguageManager = CCUtils.getStudyLanguageManager(course);
|
||||
if (CCLanguageManager == null) {
|
||||
return;
|
||||
}
|
||||
final String extension = type.getDefaultExtension();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final FileTemplate taskTemplate = CCLanguageManager.getTaskFileTemplateForExtension(project, extension);
|
||||
final String taskFileName = name + "." + extension;
|
||||
try {
|
||||
if (taskTemplate == null) {
|
||||
VirtualFile file = taskDir.getVirtualFile().createChildData(this, taskFileName);
|
||||
ProjectView.getInstance(project).select(file, file, false);
|
||||
FileEditorManager.getInstance(project).openFile(file, true);
|
||||
}
|
||||
else {
|
||||
final PsiElement taskFile = FileTemplateUtil.createFromTemplate(taskTemplate, taskFileName, null, taskDir);
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
EditorHelper.openInEditor(taskFile, false);
|
||||
view.selectElement(taskFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
task.addTaskFile(taskFileName, index);
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent event) {
|
||||
final Presentation presentation = event.getPresentation();
|
||||
presentation.setEnabledAndVisible(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);
|
||||
final Course course = StudyTaskManager.getInstance(project).getCourse();
|
||||
if (course != null && directory != null && !directory.getName().contains(EduNames.TASK)) {
|
||||
return;
|
||||
}
|
||||
presentation.setEnabledAndVisible(true);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.jetbrains.edu.coursecreator.actions;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import com.jetbrains.edu.learning.courseFormat.Course;
|
||||
import com.jetbrains.edu.learning.courseFormat.Task;
|
||||
import com.jetbrains.edu.learning.courseFormat.TaskFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class CCHideFromStudent extends CCTaskFileActionBase {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(CCHideFromStudent.class);
|
||||
|
||||
@Override
|
||||
protected void performAction(VirtualFile file, Task task, Course course, Project project) {
|
||||
Map<String, TaskFile> taskFiles = task.getTaskFiles();
|
||||
TaskFile taskFile = StudyUtils.getTaskFile(project, file);
|
||||
if (taskFile == null) {
|
||||
return;
|
||||
}
|
||||
String name = file.getName();
|
||||
VirtualFile patternFile = StudyUtils.getPatternFile(taskFile, name);
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
if (patternFile != null) {
|
||||
try {
|
||||
patternFile.delete(CCHideFromStudent.class);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.info(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
taskFiles.remove(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAvailable(Project project, VirtualFile file) {
|
||||
return StudyUtils.getTaskFile(project, file) != null;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.jetbrains.edu.coursecreator.actions;
|
||||
|
||||
import com.intellij.ide.projectView.ProjectView;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.edu.coursecreator.CCUtils;
|
||||
import com.jetbrains.edu.learning.StudyTaskManager;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import com.jetbrains.edu.learning.courseFormat.Course;
|
||||
import com.jetbrains.edu.learning.courseFormat.Task;
|
||||
|
||||
public abstract class CCTaskFileActionBase extends AnAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
VirtualFile taskVF = file.getParent();
|
||||
if (taskVF == null) {
|
||||
return;
|
||||
}
|
||||
Task task = StudyUtils.getTask(project, taskVF);
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
Course course = StudyTaskManager.getInstance(project).getCourse();
|
||||
performAction(file, task, course, project);
|
||||
ProjectView.getInstance(project).refresh();
|
||||
}
|
||||
|
||||
protected abstract void performAction(VirtualFile file, Task task, Course course, Project project);
|
||||
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
Presentation presentation = e.getPresentation();
|
||||
if (project == null || !CCUtils.isCourseCreator(project)) {
|
||||
presentation.setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
|
||||
if (file == null || file.isDirectory() || !isAvailable(project, file)) {
|
||||
presentation.setEnabledAndVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract boolean isAvailable(Project project, VirtualFile file);
|
||||
}
|
||||
Reference in New Issue
Block a user