Search in sources :

Example 16 with TaskFile

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()));
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) File(java.io.File) Map(java.util.Map)

Example 17 with TaskFile

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);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) VirtualDirectoryImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl) PsiFile(com.intellij.psi.PsiFile) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor)

Example 18 with TaskFile

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();
    }
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessListener(com.intellij.execution.process.ProcessListener) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RunContentExecutor(com.intellij.execution.RunContentExecutor) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException)

Example 19 with TaskFile

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);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Editor(com.intellij.openapi.editor.Editor)

Example 20 with TaskFile

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);
    }
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Map(java.util.Map)

Aggregations

TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)30 Project (com.intellij.openapi.project.Project)14 Editor (com.intellij.openapi.editor.Editor)11 AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)11 Map (java.util.Map)10 Course (com.jetbrains.edu.learning.courseFormat.Course)9 Task (com.jetbrains.edu.learning.courseFormat.Task)8 Document (com.intellij.openapi.editor.Document)7 PsiFile (com.intellij.psi.PsiFile)7 StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)7 File (java.io.File)6 Nullable (org.jetbrains.annotations.Nullable)6 FileEditor (com.intellij.openapi.fileEditor.FileEditor)5 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)4 Lesson (com.jetbrains.edu.learning.courseFormat.Lesson)4 Presentation (com.intellij.openapi.actionSystem.Presentation)3 EduDocumentListener (com.jetbrains.edu.learning.core.EduDocumentListener)3 AnswerPlaceholderSubtaskInfo (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo)3 ExecutionException (com.intellij.execution.ExecutionException)2