use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class StudyGenerator method createTask.
/**
* Creates task directory in its lesson folder in project user created
*
* @param lessonDir project directory of lesson which task belongs to
* @param resourceRoot directory where original task file stored
* @throws IOException
*/
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 + Integer.toString(task.getIndex()));
File newResourceRoot = new File(resourceRoot, taskDir.getName());
int i = 0;
for (Map.Entry<String, TaskFile> taskFile : task.getTaskFiles().entrySet()) {
TaskFile taskFileContent = taskFile.getValue();
taskFileContent.setIndex(i);
i++;
createTaskFile(taskDir, newResourceRoot, taskFile.getKey());
}
File[] filesInTask = newResourceRoot.listFiles();
if (filesInTask != null) {
for (File file : filesInTask) {
String fileName = file.getName();
if (!task.isTaskFile(fileName)) {
File resourceFile = new File(newResourceRoot, fileName);
File fileInProject = new File(taskDir.getCanonicalPath(), fileName);
FileUtil.copyFileOrDir(resourceFile, fileInProject);
if (!StudyUtils.isTestsFile(project, fileName) && !StudyUtils.isTaskDescriptionFile(fileName)) {
StudyTaskManager.getInstance(project).addInvisibleFiles(FileUtil.toSystemIndependentName(fileInProject.getPath()));
}
}
}
}
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class StudyProjectGenerator method openFirstTask.
public static void openFirstTask(@NotNull final Course course, @NotNull final Project project) {
LocalFileSystem.getInstance().refresh(false);
final Lesson firstLesson = StudyUtils.getFirst(course.getLessons());
if (firstLesson == null)
return;
final Task firstTask = StudyUtils.getFirst(firstLesson.getTaskList());
if (firstTask == null)
return;
final VirtualFile taskDir = firstTask.getTaskDir(project);
if (taskDir == null)
return;
final Map<String, TaskFile> taskFiles = firstTask.getTaskFiles();
VirtualFile activeVirtualFile = null;
for (Map.Entry<String, TaskFile> entry : taskFiles.entrySet()) {
final String relativePath = entry.getKey();
final TaskFile taskFile = entry.getValue();
taskDir.refresh(false, true);
final VirtualFile virtualFile = taskDir.findFileByRelativePath(relativePath);
if (virtualFile != null) {
if (!taskFile.getActivePlaceholders().isEmpty()) {
activeVirtualFile = virtualFile;
}
}
}
if (activeVirtualFile != null) {
final PsiFile file = PsiManager.getInstance(project).findFile(activeVirtualFile);
ProjectView.getInstance(project).select(file, activeVirtualFile, false);
final FileEditor[] editors = FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
if (editors.length == 0) {
return;
}
final FileEditor studyEditor = editors[0];
if (studyEditor instanceof StudyEditor) {
StudyUtils.selectFirstAnswerPlaceholder((StudyEditor) studyEditor, project);
}
FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
} else {
String first = StudyUtils.getFirst(taskFiles.keySet());
if (first != null) {
NewVirtualFile firstFile = ((VirtualDirectoryImpl) taskDir).refreshAndFindChild(first);
if (firstFile != null) {
FileEditorManager.getInstance(project).openFile(firstFile, true);
}
}
}
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class StudyRunAction method executeFile.
private void executeFile(@NotNull final Project project, @NotNull final VirtualFile openedFile, @NotNull final String filePath) {
GeneralCommandLine cmd = new GeneralCommandLine();
cmd.withWorkDirectory(openedFile.getParent().getCanonicalPath());
TaskFile selectedTaskFile = StudyUtils.getTaskFile(project, openedFile);
assert selectedTaskFile != null;
final Task currentTask = selectedTaskFile.getTask();
final Sdk sdk = StudyUtils.findSdk(currentTask, project);
if (sdk == null) {
StudyUtils.showNoSdkNotification(currentTask, project);
return;
}
String sdkHomePath = sdk.getHomePath();
if (sdkHomePath != null) {
cmd.setExePath(sdkHomePath);
StudyUtils.setCommandLineParameters(cmd, project, filePath, sdkHomePath, currentTask);
try {
myHandler = new OSProcessHandler(cmd);
} catch (ExecutionException e) {
LOG.error(e);
return;
}
for (ProcessListener processListener : myProcessListeners) {
myHandler.addProcessListener(processListener);
}
final RunContentExecutor executor = StudyUtils.getExecutor(project, currentTask, myHandler);
if (executor != null) {
Disposer.register(project, executor);
executor.run();
}
EduUtils.synchronize();
}
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class StudyWindowNavigationAction method navigateToPlaceholder.
private void navigateToPlaceholder(@NotNull final Project project) {
final Editor selectedEditor = StudyUtils.getSelectedEditor(project);
if (selectedEditor != null) {
final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
final VirtualFile openedFile = fileDocumentManager.getFile(selectedEditor.getDocument());
if (openedFile != null) {
final TaskFile selectedTaskFile = StudyUtils.getTaskFile(project, openedFile);
if (selectedTaskFile != null) {
final int offset = selectedEditor.getCaretModel().getOffset();
final AnswerPlaceholder targetPlaceholder = getTargetPlaceholder(selectedTaskFile, offset);
if (targetPlaceholder == null) {
return;
}
StudyNavigator.navigateToAnswerPlaceholder(selectedEditor, targetPlaceholder);
}
}
}
}
use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.
the class StudyCheckUtils method flushWindows.
public static void flushWindows(@NotNull final Task task, @NotNull final VirtualFile taskDir) {
for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
String name = entry.getKey();
TaskFile taskFile = entry.getValue();
VirtualFile virtualFile = taskDir.findFileByRelativePath(name);
if (virtualFile == null) {
continue;
}
EduUtils.flushWindows(taskFile, virtualFile);
}
}
Aggregations