Search in sources :

Example 26 with TaskFile

use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.

the class CCUtils method updateResources.

public static void updateResources(Project project, Task task, VirtualFile taskDir) {
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    VirtualFile lessonVF = taskDir.getParent();
    if (lessonVF == null) {
        return;
    }
    String taskResourcesPath = FileUtil.join(course.getCourseDirectory(), lessonVF.getName(), taskDir.getName());
    File taskResourceFile = new File(taskResourcesPath);
    if (!taskResourceFile.exists()) {
        if (!taskResourceFile.mkdirs()) {
            LOG.info("Failed to create resources for task " + taskResourcesPath);
        }
    }
    VirtualFile studentDir = LocalFileSystem.getInstance().findFileByIoFile(taskResourceFile);
    if (studentDir == null) {
        return;
    }
    for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
        String name = entry.getKey();
        VirtualFile answerFile = taskDir.findFileByRelativePath(name);
        if (answerFile == null) {
            continue;
        }
        ApplicationManager.getApplication().runWriteAction(() -> {
            EduUtils.createStudentFile(CCUtils.class, project, answerFile, studentDir, null, task.getActiveSubtaskIndex());
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Course(com.jetbrains.edu.learning.courseFormat.Course) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) File(java.io.File) Map(java.util.Map)

Example 27 with TaskFile

use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.

the class CCVirtualFileListener method fileCreated.

@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
    VirtualFile createdFile = event.getFile();
    if (createdFile.isDirectory()) {
        return;
    }
    if (createdFile.getPath().contains(CCUtils.GENERATED_FILES_FOLDER)) {
        return;
    }
    Project project = ProjectUtil.guessProjectForFile(createdFile);
    if (project == null) {
        return;
    }
    if (project.getBasePath() != null && !FileUtil.isAncestor(project.getBasePath(), createdFile.getPath(), true)) {
        return;
    }
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null || !CCUtils.isCourseCreator(project)) {
        return;
    }
    TaskFile taskFile = StudyUtils.getTaskFile(project, createdFile);
    if (taskFile != null) {
        return;
    }
    String taskRelativePath = StudyUtils.pathRelativeToTask(createdFile);
    CCLanguageManager manager = CCUtils.getStudyLanguageManager(course);
    if (manager != null && manager.doNotPackFile(new File(createdFile.getPath()))) {
        return;
    }
    if (CCUtils.isTestsFile(project, createdFile) || StudyUtils.isTaskDescriptionFile(createdFile.getName()) || taskRelativePath.contains(EduNames.WINDOW_POSTFIX) || taskRelativePath.contains(EduNames.WINDOWS_POSTFIX) || taskRelativePath.contains(EduNames.ANSWERS_POSTFIX)) {
        return;
    }
    VirtualFile taskVF = StudyUtils.getTaskDir(createdFile);
    if (taskVF == null) {
        return;
    }
    Task task = StudyUtils.getTask(project, taskVF);
    if (task == null) {
        return;
    }
    CCUtils.createResourceFile(createdFile, course, taskVF);
    task.addTaskFile(taskRelativePath, 1);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) Task(com.jetbrains.edu.learning.courseFormat.Task) Course(com.jetbrains.edu.learning.courseFormat.Course) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) File(java.io.File)

Example 28 with TaskFile

use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.

the class StudyEditInputAction method showInput.

public void showInput(final Project project) {
    final Editor selectedEditor = StudyUtils.getSelectedEditor(project);
    if (selectedEditor != null) {
        FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
        final VirtualFile openedFile = fileDocumentManager.getFile(selectedEditor.getDocument());
        final StudyTaskManager studyTaskManager = StudyTaskManager.getInstance(project);
        assert openedFile != null;
        TaskFile taskFile = StudyUtils.getTaskFile(project, openedFile);
        assert taskFile != null;
        final Task currentTask = taskFile.getTask();
        tabbedPane = new JBEditorTabs(project, ActionManager.getInstance(), IdeFocusManager.findInstance(), project);
        tabbedPane.addListener(new TabsListener.Adapter() {

            @Override
            public void selectionChanged(TabInfo oldSelection, TabInfo newSelection) {
                if (newSelection.getIcon() != null) {
                    int tabCount = tabbedPane.getTabCount();
                    VirtualFile taskDir = StudyUtils.getTaskDir(openedFile);
                    VirtualFile testsDir = taskDir.findChild(EduNames.USER_TESTS);
                    assert testsDir != null;
                    UserTest userTest = createUserTest(testsDir, currentTask, studyTaskManager);
                    userTest.setEditable(true);
                    StudyTestContentPanel testContentPanel = new StudyTestContentPanel(userTest);
                    TabInfo testTab = addTestTab(tabbedPane.getTabCount(), testContentPanel, currentTask, true);
                    myEditableTabs.put(testTab, userTest);
                    tabbedPane.addTabSilently(testTab, tabCount - 1);
                    tabbedPane.select(testTab, true);
                }
            }
        });
        List<UserTest> userTests = studyTaskManager.getUserTests(currentTask);
        int i = 1;
        for (UserTest userTest : userTests) {
            String inputFileText = StudyUtils.getFileText(null, userTest.getInput(), false, "UTF-8");
            String outputFileText = StudyUtils.getFileText(null, userTest.getOutput(), false, "UTF-8");
            StudyTestContentPanel myContentPanel = new StudyTestContentPanel(userTest);
            myContentPanel.addInputContent(inputFileText);
            myContentPanel.addOutputContent(outputFileText);
            TabInfo testTab = addTestTab(i, myContentPanel, currentTask, userTest.isEditable());
            tabbedPane.addTabSilently(testTab, i - 1);
            if (userTest.isEditable()) {
                myEditableTabs.put(testTab, userTest);
            }
            i++;
        }
        TabInfo plusTab = new TabInfo(new JPanel());
        plusTab.setIcon(PlatformIcons.ADD_ICON);
        tabbedPane.addTabSilently(plusTab, tabbedPane.getTabCount());
        final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), tabbedPane.getComponent()).setResizable(true).setMovable(true).setRequestFocus(true).createPopup();
        StudyEditor selectedStudyEditor = StudyUtils.getSelectedStudyEditor(project);
        assert selectedStudyEditor != null;
        hint.showInCenterOf(selectedStudyEditor.getComponent());
        hint.addListener(new HintClosedListener(currentTask, studyTaskManager));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) StudyTestContentPanel(com.jetbrains.edu.learning.ui.StudyTestContentPanel) UserTest(com.jetbrains.edu.learning.courseFormat.UserTest) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) StudyTaskManager(com.jetbrains.edu.learning.StudyTaskManager) TabsListener(com.intellij.ui.tabs.TabsListener) TabInfo(com.intellij.ui.tabs.TabInfo) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) JBEditorTabs(com.intellij.ui.tabs.impl.JBEditorTabs)

Example 29 with TaskFile

use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.

the class StudyTypeHandlerDelegate method handleTyping.

@NotNull
private static Result handleTyping(Project project, Editor editor, PsiFile file) {
    if (!StudyUtils.isStudentProject(project)) {
        return Result.CONTINUE;
    }
    TaskFile taskFile = StudyUtils.getTaskFile(project, file.getVirtualFile());
    if (taskFile == null || !taskFile.getTask().hasSubtasks()) {
        return Result.CONTINUE;
    }
    int offset = editor.getCaretModel().getOffset();
    boolean insidePlaceholder = taskFile.getAnswerPlaceholder(offset) != null;
    if (!insidePlaceholder) {
        HintManager.getInstance().showInformationHint(editor, "Text outside of placeholders is not editable in this task");
    }
    return insidePlaceholder ? Result.CONTINUE : Result.STOP;
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with TaskFile

use of com.jetbrains.edu.learning.courseFormat.TaskFile in project intellij-community by JetBrains.

the class CCSubtaskPlaceholderAction method update.

@Override
public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    presentation.setEnabledAndVisible(false);
    CCState state = getState(e);
    if (state == null) {
        return;
    }
    TaskFile taskFile = state.getTaskFile();
    if (!taskFile.getTask().hasSubtasks()) {
        return;
    }
    int offset = state.getEditor().getCaretModel().getOffset();
    if (isAvailable(taskFile, offset)) {
        presentation.setEnabledAndVisible(true);
    }
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Presentation(com.intellij.openapi.actionSystem.Presentation)

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