Search in sources :

Example 6 with StudyEditor

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

the class StudyFillPlaceholdersAction method update.

@Override
public void update(AnActionEvent e) {
    StudyUtils.updateAction(e);
    final Project project = e.getProject();
    if (project != null) {
        Course course = StudyTaskManager.getInstance(project).getCourse();
        Presentation presentation = e.getPresentation();
        if (course != null && !EduNames.STUDY.equals(course.getCourseMode())) {
            presentation.setEnabled(false);
            presentation.setVisible(true);
            return;
        }
        StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
        StudyState studyState = new StudyState(studyEditor);
        if (!studyState.isValid()) {
            presentation.setEnabledAndVisible(false);
            return;
        }
        TaskFile taskFile = studyState.getTaskFile();
        if (taskFile.getActivePlaceholders().isEmpty()) {
            presentation.setEnabledAndVisible(false);
        }
    }
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) StudyState(com.jetbrains.edu.learning.StudyState) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Course(com.jetbrains.edu.learning.courseFormat.Course) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 7 with StudyEditor

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

the class StudyFillPlaceholdersAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project != null) {
        StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
        StudyState studyState = new StudyState(studyEditor);
        if (!studyState.isValid()) {
            return;
        }
        TaskFile taskFile = studyState.getTaskFile();
        final Document document = studyState.getEditor().getDocument();
        for (AnswerPlaceholder placeholder : taskFile.getActivePlaceholders()) {
            String answer = placeholder.getPossibleAnswer();
            if (answer == null) {
                continue;
            }
            EduUtils.replaceAnswerPlaceholder(document, placeholder, placeholder.getRealLength(), answer);
        }
    }
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Project(com.intellij.openapi.project.Project) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) StudyState(com.jetbrains.edu.learning.StudyState) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Document(com.intellij.openapi.editor.Document)

Example 8 with StudyEditor

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

the class StudyUtils method getTaskFromSelectedEditor.

@Nullable
public static Task getTaskFromSelectedEditor(Project project) {
    final StudyEditor editor = getSelectedStudyEditor(project);
    Task task = null;
    if (editor != null) {
        final TaskFile file = editor.getTaskFile();
        task = file.getTask();
    }
    return task;
}
Also used : StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with StudyEditor

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

the class StudyEditInputAction method update.

@Override
public void update(final AnActionEvent e) {
    EduUtils.enableAction(e, false);
    final Project project = e.getProject();
    if (project != null) {
        StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
        if (studyEditor != null) {
            final List<UserTest> userTests = StudyTaskManager.getInstance(project).getUserTests(studyEditor.getTaskFile().getTask());
            if (!userTests.isEmpty()) {
                EduUtils.enableAction(e, true);
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) UserTest(com.jetbrains.edu.learning.courseFormat.UserTest) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor)

Example 10 with StudyEditor

use of com.jetbrains.edu.learning.editor.StudyEditor 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)

Aggregations

StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)20 Project (com.intellij.openapi.project.Project)10 TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Presentation (com.intellij.openapi.actionSystem.Presentation)4 Editor (com.intellij.openapi.editor.Editor)4 FileEditor (com.intellij.openapi.fileEditor.FileEditor)4 StudyState (com.jetbrains.edu.learning.StudyState)4 Task (com.jetbrains.edu.learning.courseFormat.Task)4 Document (com.intellij.openapi.editor.Document)3 UserTest (com.jetbrains.edu.learning.courseFormat.UserTest)3 Balloon (com.intellij.openapi.ui.popup.Balloon)2 StudyTaskManager (com.jetbrains.edu.learning.StudyTaskManager)2 AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)2 Map (java.util.Map)2 Nullable (org.jetbrains.annotations.Nullable)2 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 BalloonBuilder (com.intellij.openapi.ui.popup.BalloonBuilder)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 TextRange (com.intellij.openapi.util.TextRange)1