mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extracted common utils
This commit is contained in:
+2
-1
@@ -10,6 +10,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.edu.EduAnswerPlaceholderPainter;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.EduTaskWindowDeleteHandler;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.TaskFile;
|
||||
@@ -33,7 +34,7 @@ public class CCEditorFactoryListener implements EditorFactoryListener {
|
||||
return;
|
||||
}
|
||||
final VirtualFile taskDir = virtualFile.getParent();
|
||||
if (taskDir == null || !taskDir.getName().contains("task")) {
|
||||
if (taskDir == null || !taskDir.getName().contains(EduNames.TASK)) {
|
||||
return;
|
||||
}
|
||||
final VirtualFile lessonDir = taskDir.getParent();
|
||||
|
||||
+6
-5
@@ -16,6 +16,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileAdapter;
|
||||
import com.intellij.openapi.vfs.VirtualFileEvent;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
@@ -117,10 +118,10 @@ public class CCProjectComponent implements ProjectComponent {
|
||||
if (removedFile.getName().contains(".answer")) {
|
||||
deleteTaskFile(removedFile);
|
||||
}
|
||||
if (removedFile.getName().contains("task")) {
|
||||
if (removedFile.getName().contains(EduNames.TASK)) {
|
||||
deleteTask(removedFile);
|
||||
}
|
||||
if (removedFile.getName().contains("lesson")) {
|
||||
if (removedFile.getName().contains(EduNames.LESSON)) {
|
||||
deleteLesson(course, removedFile);
|
||||
}
|
||||
}
|
||||
@@ -141,7 +142,7 @@ public class CCProjectComponent implements ProjectComponent {
|
||||
private void deleteTask(VirtualFile removedFile) {
|
||||
VirtualFile lessonDir = removedFile.getParent();
|
||||
final CCProjectService projectService = CCProjectService.getInstance(myProject);
|
||||
if (lessonDir == null || !lessonDir.getName().contains("lesson")) {
|
||||
if (lessonDir == null || !lessonDir.getName().contains(EduNames.LESSON)) {
|
||||
return;
|
||||
}
|
||||
VirtualFile courseDir = lessonDir.getParent();
|
||||
@@ -163,11 +164,11 @@ public class CCProjectComponent implements ProjectComponent {
|
||||
private void deleteTaskFile(VirtualFile removedFile) {
|
||||
final CCProjectService projectService = CCProjectService.getInstance(myProject);
|
||||
final VirtualFile taskDir = removedFile.getParent();
|
||||
if (taskDir == null || !taskDir.getName().contains("task")) {
|
||||
if (taskDir == null || !taskDir.getName().contains(EduNames.TASK)) {
|
||||
return;
|
||||
}
|
||||
VirtualFile lessonDir = taskDir.getParent();
|
||||
if (lessonDir == null || !lessonDir.getName().contains("lesson")) {
|
||||
if (lessonDir == null || !lessonDir.getName().contains(EduNames.LESSON)) {
|
||||
return;
|
||||
}
|
||||
VirtualFile courseDir = lessonDir.getParent();
|
||||
|
||||
+9
-7
@@ -33,6 +33,8 @@ import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
import com.jetbrains.edu.EduAnswerPlaceholderPainter;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.EduUtils;
|
||||
import com.jetbrains.edu.courseFormat.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -108,7 +110,7 @@ public class CCProjectService implements PersistentStateComponent<CCProjectServi
|
||||
return null;
|
||||
}
|
||||
String taskDirName = taskDir.getName();
|
||||
if (!taskDirName.contains("task")) {
|
||||
if (!taskDirName.contains(EduNames.TASK)) {
|
||||
return null;
|
||||
}
|
||||
VirtualFile lessonDir = taskDir.getParent();
|
||||
@@ -116,7 +118,7 @@ public class CCProjectService implements PersistentStateComponent<CCProjectServi
|
||||
return null;
|
||||
}
|
||||
String lessonDirName = lessonDir.getName();
|
||||
if (!lessonDirName.contains("lesson")) {
|
||||
if (!lessonDirName.contains(EduNames.LESSON)) {
|
||||
return null;
|
||||
}
|
||||
Lesson lesson = myLessonsMap.get(lessonDirName);
|
||||
@@ -166,17 +168,17 @@ public class CCProjectService implements PersistentStateComponent<CCProjectServi
|
||||
VirtualFile taskDir = file.getParent();
|
||||
if (taskDir != null) {
|
||||
String taskDirName = taskDir.getName();
|
||||
if (taskDirName.contains("task")) {
|
||||
if (taskDirName.contains(EduNames.TASK)) {
|
||||
VirtualFile lessonDir = taskDir.getParent();
|
||||
if (lessonDir != null) {
|
||||
String lessonDirName = lessonDir.getName();
|
||||
int lessonIndex = getIndex(lessonDirName, "lesson");
|
||||
int lessonIndex = getIndex(lessonDirName, EduNames.LESSON);
|
||||
List<Lesson> lessons = myCourse.getLessons();
|
||||
if (!indexIsValid(lessonIndex, lessons)) {
|
||||
return false;
|
||||
}
|
||||
Lesson lesson = lessons.get(lessonIndex);
|
||||
int taskIndex = getIndex(taskDirName, "task");
|
||||
int taskIndex = getIndex(taskDirName, EduNames.TASK);
|
||||
List<Task> tasks = lesson.getTaskList();
|
||||
if (!indexIsValid(taskIndex, tasks)) {
|
||||
return false;
|
||||
@@ -213,10 +215,10 @@ public class CCProjectService implements PersistentStateComponent<CCProjectServi
|
||||
return false;
|
||||
}
|
||||
if (getInstance(project).getCourse() == null) {
|
||||
CCUtils.enableAction(e, false);
|
||||
EduUtils.enableAction(e, false);
|
||||
return false;
|
||||
}
|
||||
CCUtils.enableAction(e, true);
|
||||
EduUtils.enableAction(e, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementAdapter;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListenerProvider;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
@@ -69,11 +70,11 @@ public class CCRefactoringElementListenerProvider implements RefactoringElementL
|
||||
if (course == null) {
|
||||
return;
|
||||
}
|
||||
if (taskDir == null || !taskDir.getName().contains("task")) {
|
||||
if (taskDir == null || !taskDir.getName().contains(EduNames.TASK)) {
|
||||
return;
|
||||
}
|
||||
PsiDirectory lessonDir = taskDir.getParent();
|
||||
if (lessonDir == null || !lessonDir.getName().contains("lesson")) {
|
||||
if (lessonDir == null || !lessonDir.getName().contains(EduNames.LESSON)) {
|
||||
return;
|
||||
}
|
||||
Lesson lesson = service.getLesson(lessonDir.getName());
|
||||
|
||||
@@ -1,65 +1,11 @@
|
||||
package com.jetbrains.edu.coursecreator;
|
||||
|
||||
import com.intellij.ide.projectView.actions.MarkRootActionBase;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CCUtils {
|
||||
private static final Logger LOG = Logger.getInstance(CCUtils.class.getName());
|
||||
|
||||
public static void markDirAsSourceRoot(@NotNull final VirtualFile dir, @NotNull final Project project) {
|
||||
final Module module = ModuleUtilCore.findModuleForFile(dir, project);
|
||||
if (module == null) {
|
||||
LOG.info("Module for " + dir.getPath() + " was not found");
|
||||
return;
|
||||
}
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
ContentEntry entry = MarkRootActionBase.findContentEntry(model, dir);
|
||||
if (entry == null) {
|
||||
LOG.info("Content entry for " + dir.getPath() + " was not found");
|
||||
return;
|
||||
}
|
||||
entry.addSourceFolder(dir, false);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
model.commit();
|
||||
module.getProject().save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void enableAction(@NotNull final AnActionEvent event, boolean isEnable) {
|
||||
final Presentation presentation = event.getPresentation();
|
||||
presentation.setVisible(isEnable);
|
||||
presentation.setEnabled(isEnable);
|
||||
}
|
||||
|
||||
public static int getIndex(@NotNull final String fullName, @NotNull final String logicalName) {
|
||||
if (!fullName.startsWith(logicalName)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(fullName.substring(logicalName.length()));
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CCLanguageManager getStudyLanguageManager(@NotNull final Course course) {
|
||||
Language language = Language.findLanguageByID(course.getLanguage());
|
||||
|
||||
+17
-19
@@ -15,10 +15,11 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.EduUtils;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.coursecreator.CCProjectService;
|
||||
import com.jetbrains.edu.coursecreator.CCUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -41,7 +42,6 @@ public class CCCreateLesson extends DumbAwareAction {
|
||||
}
|
||||
final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
|
||||
if (directory == null) return;
|
||||
final String lessonDirName = "lesson";
|
||||
final CCProjectService service = CCProjectService.getInstance(project);
|
||||
final Course course = service.getCourse();
|
||||
if (course == null) {
|
||||
@@ -50,7 +50,7 @@ public class CCCreateLesson extends DumbAwareAction {
|
||||
//"Create Lesson" invoked from project root creates new lesson as last lesson
|
||||
if (directory.getVirtualFile().equals(project.getBaseDir())) {
|
||||
final int size = course.getLessons().size();
|
||||
createLesson(project, size + 1, view, course);
|
||||
createLesson(project, size + 1, view);
|
||||
return;
|
||||
}
|
||||
//"Create Lesson" invoked from any of lesson directories creates new lesson as next lesson
|
||||
@@ -60,33 +60,32 @@ public class CCCreateLesson extends DumbAwareAction {
|
||||
List<Lesson> lessons = course.getLessons();
|
||||
int lessonNum = lessons.size();
|
||||
for (int i = lessonNum; i >= index + 1; i--) {
|
||||
updateLesson(project, lessonDirName, course, i);
|
||||
updateLesson(project, EduNames.LESSON, i);
|
||||
}
|
||||
final PsiDirectory parent = directory.getParent();
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
createLesson(project, index + 1, view, course);
|
||||
createLesson(project, index + 1, view);
|
||||
}
|
||||
}
|
||||
|
||||
private static void createLesson(@NotNull final Project project,
|
||||
final int index,
|
||||
final IdeView view,
|
||||
@NotNull final Course course) {
|
||||
final String lessonName = Messages.showInputDialog("Name:", "Lesson Name", null, "lesson" + index, null);
|
||||
final IdeView view) {
|
||||
final String lessonName = Messages.showInputDialog("Name:", "Lesson Name", null, EduNames.LESSON + index, null);
|
||||
if (lessonName == null) {
|
||||
return;
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
createLessonDir(project, index, lessonName, view, course);
|
||||
createLessonDir(project, index, lessonName, view);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateLesson(@NotNull final Project project, final String lessonDirName, @NotNull final Course course, int i) {
|
||||
private void updateLesson(@NotNull final Project project, final String lessonDirName, int i) {
|
||||
final VirtualFile lessonDir = project.getBaseDir().findChild(lessonDirName + i);
|
||||
if (lessonDir == null) {
|
||||
return;
|
||||
@@ -113,11 +112,10 @@ public class CCCreateLesson extends DumbAwareAction {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiDirectory createLessonDir(@NotNull final Project project, int index, String name, final IdeView view,
|
||||
@NotNull final Course course) {
|
||||
String lessonFolderName = "lesson" + index;
|
||||
public static PsiDirectory createLessonDir(@NotNull final Project project, int index, String name, final IdeView view) {
|
||||
String lessonFolderName = EduNames.LESSON + index;
|
||||
final PsiDirectory projectDir = PsiManager.getInstance(project).findDirectory(project.getBaseDir());
|
||||
final PsiDirectory lessonDirectory = DirectoryUtil.createSubdirectories("lesson" + index, projectDir, "\\/");
|
||||
final PsiDirectory lessonDirectory = DirectoryUtil.createSubdirectories(EduNames.LESSON + index, projectDir, "\\/");
|
||||
final CCProjectService service = CCProjectService.getInstance(project);
|
||||
if (lessonDirectory != null) {
|
||||
if (view != null) {
|
||||
@@ -139,25 +137,25 @@ public class CCCreateLesson extends DumbAwareAction {
|
||||
final Project project = event.getData(CommonDataKeys.PROJECT);
|
||||
final IdeView view = event.getData(LangDataKeys.IDE_VIEW);
|
||||
if (project == null || view == null) {
|
||||
CCUtils.enableAction(event, false);
|
||||
EduUtils.enableAction(event, false);
|
||||
return;
|
||||
}
|
||||
final PsiDirectory[] directories = view.getDirectories();
|
||||
if (directories.length == 0) {
|
||||
CCUtils.enableAction(event, false);
|
||||
EduUtils.enableAction(event, false);
|
||||
return;
|
||||
}
|
||||
final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
|
||||
if (directory != null && project.getBaseDir().equals(directory.getVirtualFile())) {
|
||||
CCUtils.enableAction(event, true);
|
||||
EduUtils.enableAction(event, true);
|
||||
return;
|
||||
}
|
||||
final CCProjectService service = CCProjectService.getInstance(project);
|
||||
Course course = service.getCourse();
|
||||
if (directory != null && course != null && service.getLesson(directory.getName()) != null) {
|
||||
CCUtils.enableAction(event, true);
|
||||
EduUtils.enableAction(event, true);
|
||||
return;
|
||||
}
|
||||
CCUtils.enableAction(event, false);
|
||||
EduUtils.enableAction(event, false);
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -22,6 +22,8 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.EduUtils;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
@@ -59,10 +61,10 @@ public class CCCreateTask extends DumbAwareAction {
|
||||
final int size = lesson.getTaskList().size();
|
||||
final String taskName;
|
||||
if (showDialog) {
|
||||
taskName = Messages.showInputDialog("Name:", "Task Name", null, "task" + (size + 1), null);
|
||||
taskName = Messages.showInputDialog("Name:", "Task Name", null, EduNames.TASK + (size + 1), null);
|
||||
}
|
||||
else {
|
||||
taskName = "task" + (size + 1);
|
||||
taskName = EduNames.TASK + (size + 1);
|
||||
}
|
||||
|
||||
if (taskName == null) {
|
||||
@@ -71,14 +73,14 @@ public class CCCreateTask extends DumbAwareAction {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final PsiDirectory taskDirectory = DirectoryUtil.createSubdirectories("task" + (size + 1), lessonDir, "\\/");
|
||||
final PsiDirectory taskDirectory = DirectoryUtil.createSubdirectories(EduNames.TASK + (size + 1), lessonDir, "\\/");
|
||||
if (taskDirectory != null) {
|
||||
CCLanguageManager manager = CCUtils.getStudyLanguageManager(course);
|
||||
if (manager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
CCUtils.markDirAsSourceRoot(taskDirectory.getVirtualFile(), project);
|
||||
EduUtils.markDirAsSourceRoot(taskDirectory.getVirtualFile(), project);
|
||||
final Task task = new Task(taskName);
|
||||
task.setIndex(size + 1);
|
||||
service.addTask(task, taskDirectory);
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@ 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.EduNames;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
import com.jetbrains.edu.coursecreator.CCLanguageManager;
|
||||
@@ -129,7 +130,7 @@ public class CCCreateTaskFile extends DumbAwareAction {
|
||||
final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
|
||||
final CCProjectService service = CCProjectService.getInstance(project);
|
||||
final Course course = service.getCourse();
|
||||
if (course != null && directory != null && !directory.getName().contains("task")) {
|
||||
if (course != null && directory != null && !directory.getName().contains(EduNames.TASK)) {
|
||||
presentation.setVisible(false);
|
||||
presentation.setEnabled(false);
|
||||
return;
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@ package com.jetbrains.edu.coursecreator.actions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.coursecreator.CCProjectService;
|
||||
@@ -30,7 +31,7 @@ public class CCRenameLesson extends CCRename {
|
||||
|
||||
@Override
|
||||
public String getFolderName() {
|
||||
return "lesson";
|
||||
return EduNames.LESSON;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-2
@@ -18,6 +18,7 @@ package com.jetbrains.edu.coursecreator.actions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
@@ -30,13 +31,13 @@ public class CCRenameTask extends CCRename {
|
||||
|
||||
@Override
|
||||
public String getFolderName() {
|
||||
return "task";
|
||||
return EduNames.TASK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processRename(Project project, PsiDirectory directory, Course course) {
|
||||
PsiDirectory lessonDir = directory.getParent();
|
||||
if (lessonDir == null || !lessonDir.getName().contains("lesson")) {
|
||||
if (lessonDir == null || !lessonDir.getName().contains(EduNames.LESSON)) {
|
||||
return false;
|
||||
}
|
||||
final CCProjectService service = CCProjectService.getInstance(project);
|
||||
|
||||
+5
-4
@@ -34,6 +34,7 @@ import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.courseFormat.*;
|
||||
import com.jetbrains.edu.coursecreator.CCLanguageManager;
|
||||
import com.jetbrains.edu.coursecreator.CCProjectService;
|
||||
@@ -183,7 +184,7 @@ public abstract class CCRunTestsAction extends AnAction {
|
||||
LOG.debug("idea directory doesn't exist");
|
||||
return;
|
||||
}
|
||||
VirtualFile courseResourceDir = ideaDir.findChild("course");
|
||||
VirtualFile courseResourceDir = ideaDir.findChild(EduNames.COURSE);
|
||||
if (courseResourceDir != null) {
|
||||
courseResourceDir.delete(project);
|
||||
}
|
||||
@@ -210,9 +211,9 @@ public abstract class CCRunTestsAction extends AnAction {
|
||||
//some tests could compare task files after user modifications with initial task files
|
||||
private static void createResourceFiles(@NotNull final VirtualFile file, @NotNull final Project project) {
|
||||
VirtualFile taskDir = file.getParent();
|
||||
int index = CCProjectService.getIndex(taskDir.getName(), "task");
|
||||
int index = CCProjectService.getIndex(taskDir.getName(), EduNames.TASK);
|
||||
VirtualFile lessonDir = taskDir.getParent();
|
||||
int lessonIndex = CCProjectService.getIndex(lessonDir.getName(), "lesson");
|
||||
int lessonIndex = CCProjectService.getIndex(lessonDir.getName(), EduNames.LESSON);
|
||||
Course course = CCProjectService.getInstance(project).getCourse();
|
||||
if (course == null) {
|
||||
return;
|
||||
@@ -220,7 +221,7 @@ public abstract class CCRunTestsAction extends AnAction {
|
||||
VirtualFile ideaDir = project.getBaseDir().findChild(".idea");
|
||||
assert ideaDir != null;
|
||||
try {
|
||||
VirtualFile courseResourceDir = findOrCreateDir(project, ideaDir, "course");
|
||||
VirtualFile courseResourceDir = findOrCreateDir(project, ideaDir, EduNames.COURSE);
|
||||
VirtualFile lessonResourceDir = findOrCreateDir(project, courseResourceDir, lessonDir.getName());
|
||||
VirtualFile taskResourceDir = findOrCreateDir(project, lessonResourceDir, taskDir.getName());
|
||||
if (CCProjectService.indexIsValid(lessonIndex, course.getLessons())) {
|
||||
|
||||
+6
-7
@@ -6,11 +6,12 @@ import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.EduUtils;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
import com.jetbrains.edu.coursecreator.CCProjectService;
|
||||
import com.jetbrains.edu.coursecreator.CCUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CCDirectoryNode extends PsiDirectoryNode {
|
||||
@@ -67,12 +68,10 @@ public class CCDirectoryNode extends PsiDirectoryNode {
|
||||
@Override
|
||||
public int getTypeSortWeight(boolean sortByType) {
|
||||
String name = myValue.getName();
|
||||
String lessonDirName = "lesson";
|
||||
String taskDirName = "task";
|
||||
if (name.startsWith(lessonDirName) || name.startsWith(taskDirName)) {
|
||||
String logicalName = name.contains(lessonDirName) ? lessonDirName : taskDirName;
|
||||
int index = CCUtils.getIndex(name, logicalName) + 1;
|
||||
return index != -1 ? index : 0;
|
||||
if (name.startsWith(EduNames.LESSON) || name.startsWith(EduNames.TASK)) {
|
||||
String logicalName = name.contains(EduNames.LESSON) ? EduNames.LESSON : EduNames.TASK;
|
||||
int index = EduUtils.getIndex(name, logicalName) + 1;
|
||||
return index != -1 ? index + 1: 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -27,7 +28,7 @@ public class CreateCourseArchivePanel extends JPanel {
|
||||
myErrorIcon.setIcon(AllIcons.Actions.Lightning);
|
||||
setState(false);
|
||||
myDlg = dlg;
|
||||
myNameField.setText("course");
|
||||
myNameField.setText(EduNames.COURSE);
|
||||
myLocationField.setText(project.getBasePath());
|
||||
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
|
||||
myLocationField.addBrowseFolderListener("Choose location folder", null, project, descriptor);
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.ValidationInfo;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -27,7 +28,7 @@ public class CreateTaskWindowDialog extends DialogWrapper {
|
||||
setTitle(ourTitle);
|
||||
myAnswerPlaceholder = answerPlaceholder;
|
||||
myPanel = new CreateTaskWindowPanel(this);
|
||||
String generatedHintName = "lesson" + lessonIndex + "task" + taskIndex + taskFileName + "_" + taskWindowIndex;
|
||||
String generatedHintName = EduNames.LESSON + lessonIndex + EduNames.TASK + taskIndex + taskFileName + "_" + taskWindowIndex;
|
||||
myPanel.setGeneratedHintName(generatedHintName);
|
||||
if (answerPlaceholder.getHint() != null) {
|
||||
setHintText(answerPlaceholder);
|
||||
|
||||
@@ -10,5 +10,7 @@
|
||||
<orderEntry type="module" module-name="platform-api" />
|
||||
<orderEntry type="library" name="gson" level="project" />
|
||||
<orderEntry type="module" module-name="core-impl" />
|
||||
<orderEntry type="module" module-name="platform-impl" />
|
||||
<orderEntry type="module" module-name="lang-impl" />
|
||||
</component>
|
||||
</module>
|
||||
+5
-4
@@ -26,6 +26,7 @@ import com.intellij.openapi.vfs.VirtualFileEvent;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.wm.*;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.EduUtils;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
@@ -287,11 +288,11 @@ public class StudyProjectComponent implements ProjectComponent {
|
||||
final VirtualFile createdFile = event.getFile();
|
||||
final VirtualFile taskDir = createdFile.getParent();
|
||||
final Course course = StudyTaskManager.getInstance(myProject).getCourse();
|
||||
if (taskDir != null && taskDir.getName().contains(EduNames.TASK_DIR)) {
|
||||
int taskIndex = StudyUtils.getIndex(taskDir.getName(), EduNames.TASK_DIR);
|
||||
if (taskDir != null && taskDir.getName().contains(EduNames.TASK)) {
|
||||
int taskIndex = EduUtils.getIndex(taskDir.getName(), EduNames.TASK);
|
||||
final VirtualFile lessonDir = taskDir.getParent();
|
||||
if (lessonDir != null && lessonDir.getName().contains(EduNames.LESSON_DIR)) {
|
||||
int lessonIndex = StudyUtils.getIndex(lessonDir.getName(), EduNames.LESSON_DIR);
|
||||
if (lessonDir != null && lessonDir.getName().contains(EduNames.LESSON)) {
|
||||
int lessonIndex = EduUtils.getIndex(lessonDir.getName(), EduNames.LESSON);
|
||||
if (course != null) {
|
||||
List<Lesson> lessons = course.getLessons();
|
||||
if (StudyUtils.indexIsValid(lessonIndex, lessons)) {
|
||||
|
||||
+5
-51
@@ -4,7 +4,6 @@ import com.intellij.execution.RunContentExecutor;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.ide.SaveAndSyncHandlerImpl;
|
||||
import com.intellij.ide.projectView.actions.MarkRootActionBase;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
@@ -17,13 +16,8 @@ import com.intellij.openapi.editor.colors.EditorColors;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.ui.popup.Balloon;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -36,6 +30,7 @@ import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.edu.EduAnswerPlaceholderPainter;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.EduTaskWindowDeleteHandler;
|
||||
import com.jetbrains.edu.EduUtils;
|
||||
import com.jetbrains.edu.courseFormat.*;
|
||||
import com.jetbrains.edu.learning.editor.StudyEditor;
|
||||
import com.jetbrains.edu.learning.run.StudyExecutor;
|
||||
@@ -133,19 +128,6 @@ public class StudyUtils {
|
||||
VirtualFileManager.getInstance().refreshWithoutFileWatcher(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets number index in directory names like "task1", "lesson2"
|
||||
*
|
||||
* @param fullName full name of directory
|
||||
* @param logicalName part of name without index
|
||||
* @return index of object
|
||||
*/
|
||||
public static int getIndex(@NotNull final String fullName, @NotNull final String logicalName) {
|
||||
if (!fullName.contains(logicalName)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return Integer.parseInt(fullName.substring(logicalName.length())) - 1;
|
||||
}
|
||||
|
||||
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
|
||||
@Nullable
|
||||
@@ -207,7 +189,7 @@ public class StudyUtils {
|
||||
int taskNum = task.getIndex() + 1;
|
||||
int lessonNum = task.getLesson().getIndex() + 1;
|
||||
assert course != null;
|
||||
final String pathToResource = FileUtil.join(course.getCourseDirectory(), EduNames.LESSON_DIR + lessonNum, EduNames.TASK_DIR + taskNum);
|
||||
final String pathToResource = FileUtil.join(course.getCourseDirectory(), EduNames.LESSON + lessonNum, EduNames.TASK + taskNum);
|
||||
final File resourceFile = new File(pathToResource, copyName);
|
||||
FileUtil.copy(new File(pathToResource, sourceName), resourceFile);
|
||||
return resourceFile;
|
||||
@@ -219,28 +201,6 @@ public class StudyUtils {
|
||||
return StudyExecutor.INSTANCE.forLanguage(language).findSdk(project);
|
||||
}
|
||||
|
||||
public static void markDirAsSourceRoot(@NotNull final VirtualFile dir, @NotNull final Project project) {
|
||||
final Module module = ModuleUtilCore.findModuleForFile(dir, project);
|
||||
if (module == null) {
|
||||
LOG.info("Module for " + dir.getPath() + " was not found");
|
||||
return;
|
||||
}
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final ContentEntry entry = MarkRootActionBase.findContentEntry(model, dir);
|
||||
if (entry == null) {
|
||||
LOG.info("Content entry for " + dir.getPath() + " was not found");
|
||||
return;
|
||||
}
|
||||
entry.addSourceFolder(dir, false);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
model.commit();
|
||||
module.getProject().save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static StudyTestRunner getTestRunner(@NotNull final Task task, @NotNull final VirtualFile taskDir) {
|
||||
final Language language = task.getLesson().getCourse().getLanguageById();
|
||||
@@ -262,12 +222,6 @@ public class StudyUtils {
|
||||
StudyExecutor.INSTANCE.forLanguage(language).setCommandLineParameters(cmd, project, filePath, sdkPath, currentTask);
|
||||
}
|
||||
|
||||
public static void enableAction(@NotNull final AnActionEvent event, boolean isEnable) {
|
||||
final Presentation presentation = event.getPresentation();
|
||||
presentation.setVisible(isEnable);
|
||||
presentation.setEnabled(isEnable);
|
||||
}
|
||||
|
||||
public static void showNoSdkNotification(@NotNull final Task currentTask, @NotNull final Project project) {
|
||||
final Language language = currentTask.getLesson().getCourse().getLanguageById();
|
||||
StudyExecutor.INSTANCE.forLanguage(language).showNoSdkNotification(project);
|
||||
@@ -305,16 +259,16 @@ public class StudyUtils {
|
||||
return null;
|
||||
}
|
||||
final String taskDirName = taskDir.getName();
|
||||
if (taskDirName.contains(EduNames.TASK_DIR)) {
|
||||
if (taskDirName.contains(EduNames.TASK)) {
|
||||
final VirtualFile lessonDir = taskDir.getParent();
|
||||
if (lessonDir != null) {
|
||||
int lessonIndex = getIndex(lessonDir.getName(), EduNames.LESSON_DIR);
|
||||
int lessonIndex = EduUtils.getIndex(lessonDir.getName(), EduNames.LESSON);
|
||||
List<Lesson> lessons = course.getLessons();
|
||||
if (!indexIsValid(lessonIndex, lessons)) {
|
||||
return null;
|
||||
}
|
||||
final Lesson lesson = lessons.get(lessonIndex);
|
||||
int taskIndex = getIndex(taskDirName, EduNames.TASK_DIR);
|
||||
int taskIndex = EduUtils.getIndex(taskDirName, EduNames.TASK);
|
||||
final List<Task> tasks = lesson.getTaskList();
|
||||
if (!indexIsValid(taskIndex, tasks)) {
|
||||
return null;
|
||||
|
||||
+5
-4
@@ -22,6 +22,7 @@ import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import com.intellij.problems.WolfTheProblemSolver;
|
||||
import com.jetbrains.edu.EduAnswerPlaceholderPainter;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.EduUtils;
|
||||
import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
@@ -123,8 +124,8 @@ public class StudyRefreshTaskFileAction extends DumbAwareAction {
|
||||
taskFile.setTrackChanges(false);
|
||||
clearDocument(document);
|
||||
Task task = taskFile.getTask();
|
||||
String lessonDir = EduNames.LESSON_DIR + String.valueOf(task.getLesson().getIndex() + 1);
|
||||
String taskDir = EduNames.TASK_DIR + String.valueOf(task.getIndex() + 1);
|
||||
String lessonDir = EduNames.LESSON + String.valueOf(task.getLesson().getIndex() + 1);
|
||||
String taskDir = EduNames.TASK + String.valueOf(task.getIndex() + 1);
|
||||
Course course = task.getLesson().getCourse();
|
||||
File resourceFile = new File(course.getCourseDirectory());
|
||||
if (!resourceFile.exists()) {
|
||||
@@ -171,9 +172,9 @@ public class StudyRefreshTaskFileAction extends DumbAwareAction {
|
||||
StudyEditor studyEditor = StudyEditor.getSelectedStudyEditor(project);
|
||||
StudyState studyState = new StudyState(studyEditor);
|
||||
if (studyState.isValid()) {
|
||||
StudyUtils.enableAction(event, true);
|
||||
EduUtils.enableAction(event, true);
|
||||
}
|
||||
}
|
||||
StudyUtils.enableAction(event, false);
|
||||
EduUtils.enableAction(event, false);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -52,7 +52,7 @@ abstract public class StudyTaskNavigationAction extends DumbAwareAction {
|
||||
return;
|
||||
}
|
||||
VirtualFile projectDir = project.getBaseDir();
|
||||
String lessonDirName = EduNames.LESSON_DIR + String.valueOf(lessonIndex + 1);
|
||||
String lessonDirName = EduNames.LESSON + String.valueOf(lessonIndex + 1);
|
||||
if (projectDir == null) {
|
||||
return;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ abstract public class StudyTaskNavigationAction extends DumbAwareAction {
|
||||
if (lessonDir == null) {
|
||||
return;
|
||||
}
|
||||
String taskDirName = EduNames.TASK_DIR + String.valueOf(nextTaskIndex + 1);
|
||||
String taskDirName = EduNames.TASK + String.valueOf(nextTaskIndex + 1);
|
||||
VirtualFile taskDir = lessonDir.findChild(taskDirName);
|
||||
if (taskDir == null) {
|
||||
return;
|
||||
|
||||
+5
-5
@@ -5,8 +5,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.EduUtils;
|
||||
import com.jetbrains.edu.courseFormat.*;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
@@ -50,8 +50,8 @@ public class StudyGenerator {
|
||||
*/
|
||||
public static void createTask(@NotNull final Task task, @NotNull final VirtualFile lessonDir, @NotNull final File resourceRoot,
|
||||
@NotNull final Project project) throws IOException {
|
||||
VirtualFile taskDir = lessonDir.createChildDirectory(project, EduNames.TASK_DIR + Integer.toString(task.getIndex() + 1));
|
||||
StudyUtils.markDirAsSourceRoot(taskDir, project);
|
||||
VirtualFile taskDir = lessonDir.createChildDirectory(project, EduNames.TASK + Integer.toString(task.getIndex() + 1));
|
||||
EduUtils.markDirAsSourceRoot(taskDir, project);
|
||||
File newResourceRoot = new File(resourceRoot, taskDir.getName());
|
||||
int i = 0;
|
||||
for (Map.Entry<String, TaskFile> taskFile : task.getTaskFiles().entrySet()) {
|
||||
@@ -82,7 +82,7 @@ public class StudyGenerator {
|
||||
*/
|
||||
public static void createLesson(@NotNull final Lesson lesson, @NotNull final VirtualFile courseDir, @NotNull final File resourceRoot,
|
||||
@NotNull final Project project) throws IOException {
|
||||
String lessonDirName = EduNames.LESSON_DIR + Integer.toString(lesson.getIndex() + 1);
|
||||
String lessonDirName = EduNames.LESSON + Integer.toString(lesson.getIndex() + 1);
|
||||
VirtualFile lessonDir = courseDir.createChildDirectory(project, lessonDirName);
|
||||
final List<Task> taskList = lesson.getTaskList();
|
||||
for (int i = 0; i < taskList.size(); i++) {
|
||||
@@ -112,7 +112,7 @@ public class StudyGenerator {
|
||||
File[] files = resourceRoot.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return !name.contains(EduNames.LESSON_DIR) && !name.equals("course.json") && !name.equals("hints");
|
||||
return !name.contains(EduNames.LESSON) && !name.equals("course.json") && !name.equals("hints");
|
||||
}
|
||||
});
|
||||
for (File file : files) {
|
||||
|
||||
+3
-2
@@ -19,6 +19,7 @@ import com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
@@ -114,11 +115,11 @@ public class StudyProjectGenerator {
|
||||
|
||||
int lessonIndex = 1;
|
||||
for (Lesson lesson : course.lessons) {
|
||||
final File lessonDirectory = new File(courseDirectory, "lesson"+String.valueOf(lessonIndex));
|
||||
final File lessonDirectory = new File(courseDirectory, EduNames.LESSON + String.valueOf(lessonIndex));
|
||||
FileUtil.createDirectory(lessonDirectory);
|
||||
int taskIndex = 1;
|
||||
for (Task task : lesson.taskList) {
|
||||
final File taskDirectory = new File(lessonDirectory, "task" + String.valueOf(taskIndex));
|
||||
final File taskDirectory = new File(lessonDirectory, EduNames.TASK + String.valueOf(taskIndex));
|
||||
FileUtil.createDirectory(taskDirectory);
|
||||
for (Map.Entry<String, TaskFile> taskFileEntry : task.taskFiles.entrySet()) {
|
||||
final String name = taskFileEntry.getKey();
|
||||
|
||||
+9
-8
@@ -12,6 +12,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.jetbrains.edu.EduNames;
|
||||
import com.jetbrains.edu.EduUtils;
|
||||
import com.jetbrains.edu.courseFormat.Course;
|
||||
import com.jetbrains.edu.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
@@ -53,7 +54,7 @@ public class StudyDirectoryNode extends PsiDirectoryNode {
|
||||
data.addText(" (" + valueName + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
|
||||
return;
|
||||
}
|
||||
if (valueName.contains(EduNames.TASK_DIR)) {
|
||||
if (valueName.contains(EduNames.TASK)) {
|
||||
TaskFile file = null;
|
||||
for (PsiElement child : myValue.getChildren()) {
|
||||
VirtualFile virtualFile = child.getContainingFile().getVirtualFile();
|
||||
@@ -67,8 +68,8 @@ public class StudyDirectoryNode extends PsiDirectoryNode {
|
||||
setStudyAttributes(task, data, task.getName());
|
||||
}
|
||||
}
|
||||
if (valueName.contains(EduNames.LESSON_DIR)) {
|
||||
int lessonIndex = Integer.parseInt(valueName.substring(EduNames.LESSON_DIR.length())) - 1;
|
||||
if (valueName.contains(EduNames.LESSON)) {
|
||||
int lessonIndex = Integer.parseInt(valueName.substring(EduNames.LESSON.length())) - 1;
|
||||
Lesson lesson = course.getLessons().get(lessonIndex);
|
||||
setStudyAttributes(lesson, data, lesson.getName());
|
||||
}
|
||||
@@ -88,9 +89,9 @@ public class StudyDirectoryNode extends PsiDirectoryNode {
|
||||
@Override
|
||||
public int getTypeSortWeight(boolean sortByType) {
|
||||
String name = myValue.getName();
|
||||
if (name.contains(EduNames.LESSON_DIR) || name.contains(EduNames.TASK_DIR)) {
|
||||
String logicalName = name.contains(EduNames.LESSON_DIR) ? EduNames.LESSON_DIR : EduNames.TASK_DIR;
|
||||
return StudyUtils.getIndex(name, logicalName) + 1;
|
||||
if (name.contains(EduNames.LESSON) || name.contains(EduNames.TASK)) {
|
||||
String logicalName = name.contains(EduNames.LESSON) ? EduNames.LESSON : EduNames.TASK;
|
||||
return EduUtils.getIndex(name, logicalName) + 1;
|
||||
}
|
||||
return name.contains(EduNames.SANDBOX_DIR) ? 0 : 3;
|
||||
}
|
||||
@@ -148,7 +149,7 @@ public class StudyDirectoryNode extends PsiDirectoryNode {
|
||||
|
||||
@Override
|
||||
public void navigate(boolean requestFocus) {
|
||||
if (myValue.getName().contains(EduNames.TASK_DIR)) {
|
||||
if (myValue.getName().contains(EduNames.TASK)) {
|
||||
TaskFile taskFile = null;
|
||||
VirtualFile virtualFile = null;
|
||||
for (PsiElement child : myValue.getChildren()) {
|
||||
@@ -191,7 +192,7 @@ public class StudyDirectoryNode extends PsiDirectoryNode {
|
||||
|
||||
@Override
|
||||
public boolean expandOnDoubleClick() {
|
||||
if (myValue.getName().contains(EduNames.TASK_DIR)) {
|
||||
if (myValue.getName().contains(EduNames.TASK)) {
|
||||
return false;
|
||||
}
|
||||
return super.expandOnDoubleClick();
|
||||
|
||||
@@ -20,16 +20,13 @@ import org.jetbrains.annotations.NonNls;
|
||||
@NonNls
|
||||
public class EduNames {
|
||||
public static final String TASK_HTML = "task.html";
|
||||
public static final String TASK_TESTS = "tests.py";
|
||||
public static final String LESSON = "lesson";
|
||||
public static final String TEST_HELPER = "test_helper.py";
|
||||
public static final String USER_TESTER = "user_tester.py";
|
||||
public static final String LESSON_DIR = "lesson";
|
||||
public static final String COURSE = "course";
|
||||
public static final String TEST_TAB_NAME = "test";
|
||||
public static final String USER_TEST_INPUT = "input";
|
||||
public static final String USER_TEST_OUTPUT = "output";
|
||||
public static final String WINDOW_POSTFIX = "_window.py";
|
||||
public static final String TASK_DIR = "task";
|
||||
public static final String TASK = "task";
|
||||
public static final String USER_TESTS = "userTests";
|
||||
public static final String SANDBOX_DIR = "Sandbox";
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.jetbrains.edu;
|
||||
|
||||
import com.intellij.ide.projectView.actions.MarkRootActionBase;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EduUtils {
|
||||
private EduUtils() {
|
||||
}
|
||||
private static final Logger LOG = Logger.getInstance(EduUtils.class.getName());
|
||||
|
||||
|
||||
public static void markDirAsSourceRoot(@NotNull final VirtualFile dir, @NotNull final Project project) {
|
||||
final Module module = ModuleUtilCore.findModuleForFile(dir, project);
|
||||
if (module == null) {
|
||||
LOG.info("Module for " + dir.getPath() + " was not found");
|
||||
return;
|
||||
}
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final ContentEntry entry = MarkRootActionBase.findContentEntry(model, dir);
|
||||
if (entry == null) {
|
||||
LOG.info("Content entry for " + dir.getPath() + " was not found");
|
||||
return;
|
||||
}
|
||||
entry.addSourceFolder(dir, false);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
model.commit();
|
||||
module.getProject().save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void enableAction(@NotNull final AnActionEvent event, boolean isEnable) {
|
||||
final Presentation presentation = event.getPresentation();
|
||||
presentation.setVisible(isEnable);
|
||||
presentation.setEnabled(isEnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets number index in directory names like "task1", "lesson2"
|
||||
*
|
||||
* @param fullName full name of directory
|
||||
* @param logicalName part of name without index
|
||||
* @return index of object
|
||||
*/
|
||||
public static int getIndex(@NotNull final String fullName, @NotNull final String logicalName) {
|
||||
if (!fullName.contains(logicalName)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return Integer.parseInt(fullName.substring(logicalName.length())) - 1;
|
||||
}
|
||||
}
|
||||
@@ -97,8 +97,8 @@ public class Task {
|
||||
|
||||
@Nullable
|
||||
public VirtualFile getTaskDir(Project project) {
|
||||
String lessonDirName = EduNames.LESSON_DIR + String.valueOf(myLesson.getIndex() + 1);
|
||||
String taskDirName = EduNames.TASK_DIR + String.valueOf(myIndex + 1);
|
||||
String lessonDirName = EduNames.LESSON + String.valueOf(myLesson.getIndex() + 1);
|
||||
String taskDirName = EduNames.TASK + String.valueOf(myIndex + 1);
|
||||
VirtualFile courseDir = project.getBaseDir();
|
||||
if (courseDir != null) {
|
||||
VirtualFile lessonDir = courseDir.findChild(lessonDirName);
|
||||
|
||||
Reference in New Issue
Block a user