Search in sources :

Example 1 with StudyTaskManager

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

the class CCPluginConfigurator method accept.

@Override
public boolean accept(@NotNull Project project) {
    final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
    final Course course = taskManager.getCourse();
    if (course != null) {
        final String mode = course.getCourseMode();
        return COURSE_MODE.equals(mode);
    }
    return false;
}
Also used : StudyTaskManager(com.jetbrains.edu.learning.StudyTaskManager) Course(com.jetbrains.edu.learning.courseFormat.Course)

Example 2 with StudyTaskManager

use of com.jetbrains.edu.learning.StudyTaskManager 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 3 with StudyTaskManager

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

the class StudyCheckUtils method navigateToFailedPlaceholder.

public static void navigateToFailedPlaceholder(@NotNull final StudyState studyState, @NotNull final Task task, @NotNull final VirtualFile taskDir, @NotNull final Project project) {
    TaskFile selectedTaskFile = studyState.getTaskFile();
    Editor editor = studyState.getEditor();
    TaskFile taskFileToNavigate = selectedTaskFile;
    VirtualFile fileToNavigate = studyState.getVirtualFile();
    final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
    if (!taskManager.hasFailedAnswerPlaceholders(selectedTaskFile)) {
        for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
            String name = entry.getKey();
            TaskFile taskFile = entry.getValue();
            if (taskManager.hasFailedAnswerPlaceholders(taskFile)) {
                taskFileToNavigate = taskFile;
                VirtualFile virtualFile = taskDir.findFileByRelativePath(name);
                if (virtualFile == null) {
                    continue;
                }
                FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
                if (fileEditor instanceof StudyEditor) {
                    StudyEditor studyEditor = (StudyEditor) fileEditor;
                    editor = studyEditor.getEditor();
                }
                fileToNavigate = virtualFile;
                break;
            }
        }
    }
    if (fileToNavigate != null) {
        FileEditorManager.getInstance(project).openFile(fileToNavigate, true);
    }
    final Editor editorToNavigate = editor;
    ApplicationManager.getApplication().invokeLater(() -> IdeFocusManager.getInstance(project).requestFocus(editorToNavigate.getContentComponent(), true));
    StudyNavigator.navigateToFirstFailedAnswerPlaceholder(editor, taskFileToNavigate);
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StudyTaskManager(com.jetbrains.edu.learning.StudyTaskManager) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Map(java.util.Map)

Example 4 with StudyTaskManager

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

the class StudyToolWindowFactory method createToolWindowContent.

@Override
public void createToolWindowContent(@NotNull final Project project, @NotNull final ToolWindow toolWindow) {
    toolWindow.setIcon(InteractiveLearningIcons.TaskDescription);
    StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
    final Course course = taskManager.getCourse();
    if (course != null) {
        final StudyToolWindow studyToolWindow;
        if (StudyUtils.hasJavaFx() && taskManager.shouldUseJavaFx()) {
            studyToolWindow = new StudyJavaFxToolWindow();
        } else {
            studyToolWindow = new StudySwingToolWindow();
        }
        studyToolWindow.init(project, true);
        final ContentManager contentManager = toolWindow.getContentManager();
        final Content content = contentManager.getFactory().createContent(studyToolWindow, null, false);
        contentManager.addContent(content);
        Disposer.register(project, studyToolWindow);
    }
}
Also used : Content(com.intellij.ui.content.Content) ContentManager(com.intellij.ui.content.ContentManager) StudyTaskManager(com.jetbrains.edu.learning.StudyTaskManager) Course(com.jetbrains.edu.learning.courseFormat.Course)

Aggregations

StudyTaskManager (com.jetbrains.edu.learning.StudyTaskManager)4 Editor (com.intellij.openapi.editor.Editor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Course (com.jetbrains.edu.learning.courseFormat.Course)2 TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)2 StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)2 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 Content (com.intellij.ui.content.Content)1 ContentManager (com.intellij.ui.content.ContentManager)1 TabInfo (com.intellij.ui.tabs.TabInfo)1 TabsListener (com.intellij.ui.tabs.TabsListener)1 JBEditorTabs (com.intellij.ui.tabs.impl.JBEditorTabs)1 Task (com.jetbrains.edu.learning.courseFormat.Task)1 UserTest (com.jetbrains.edu.learning.courseFormat.UserTest)1 StudyTestContentPanel (com.jetbrains.edu.learning.ui.StudyTestContentPanel)1 Map (java.util.Map)1