Search in sources :

Example 1 with StudyChoiceVariantsPanel

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

the class StudyRefreshTaskFileAction method refreshFile.

private static void refreshFile(@NotNull final StudyState studyState, @NotNull final Project project) {
    final Editor editor = studyState.getEditor();
    final TaskFile taskFile = studyState.getTaskFile();
    final Task task = taskFile.getTask();
    if (task.hasSubtasks()) {
        for (AnswerPlaceholder placeholder : taskFile.getActivePlaceholders()) {
            StudySubtaskUtils.refreshPlaceholder(editor, placeholder);
        }
    } else {
        if (!resetTaskFile(editor.getDocument(), project, taskFile, studyState.getVirtualFile().getName())) {
            Messages.showInfoMessage("The initial text of task file is unavailable", "Failed to Refresh Task File");
            return;
        }
        if (task.isChoiceTask()) {
            final StudyToolWindow window = StudyUtils.getStudyToolWindow(project);
            if (window != null) {
                window.setBottomComponent(new StudyChoiceVariantsPanel(task));
            }
        }
    }
    WolfTheProblemSolver.getInstance(project).clearProblems(studyState.getVirtualFile());
    taskFile.setHighlightErrors(false);
    StudyUtils.drawAllAnswerPlaceholders(editor, taskFile);
    EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile);
    ApplicationManager.getApplication().invokeLater(() -> IdeFocusManager.getInstance(project).requestFocus(editor.getContentComponent(), true));
    StudyNavigator.navigateToFirstAnswerPlaceholder(editor, taskFile);
    showBalloon(project, "You can start again now", MessageType.INFO);
}
Also used : StudyChoiceVariantsPanel(com.jetbrains.edu.learning.editor.StudyChoiceVariantsPanel) StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Editor(com.intellij.openapi.editor.Editor)

Example 2 with StudyChoiceVariantsPanel

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

the class StudyBasePluginConfigurator method getFileEditorManagerListener.

@NotNull
@Override
public FileEditorManagerListener getFileEditorManagerListener(@NotNull Project project, @NotNull StudyToolWindow toolWindow) {
    return new FileEditorManagerListener() {

        @Override
        public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            Task task = getTask(file);
            setTaskText(task, StudyUtils.getTaskDir(file));
            if (task != null) {
                if (task.isChoiceTask()) {
                    final StudyChoiceVariantsPanel choicePanel = new StudyChoiceVariantsPanel(task);
                    toolWindow.setBottomComponent(choicePanel);
                } else {
                    toolWindow.setBottomComponent(null);
                }
            }
        }

        @Override
        public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            for (VirtualFile openedFile : source.getOpenFiles()) {
                if (StudyUtils.getTaskFile(project, openedFile) != null) {
                    return;
                }
            }
            toolWindow.setEmptyText(project);
        }

        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent event) {
            VirtualFile file = event.getNewFile();
            if (file != null) {
                Task task = getTask(file);
                setTaskText(task, StudyUtils.getTaskDir(file));
            }
            toolWindow.setBottomComponent(null);
        }

        @Nullable
        private Task getTask(@NotNull VirtualFile file) {
            return StudyUtils.getTaskForFile(project, file);
        }

        private void setTaskText(@Nullable final Task task, @Nullable final VirtualFile taskDirectory) {
            String text = StudyUtils.getTaskTextFromTask(taskDirectory, task);
            if (text == null) {
                toolWindow.setEmptyText(project);
                return;
            }
            toolWindow.setTaskText(text, taskDirectory, project);
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Task(com.jetbrains.edu.learning.courseFormat.Task) StudyChoiceVariantsPanel(com.jetbrains.edu.learning.editor.StudyChoiceVariantsPanel) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

StudyChoiceVariantsPanel (com.jetbrains.edu.learning.editor.StudyChoiceVariantsPanel)2 Editor (com.intellij.openapi.editor.Editor)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 FileEditorManagerEvent (com.intellij.openapi.fileEditor.FileEditorManagerEvent)1 FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Task (com.jetbrains.edu.learning.courseFormat.Task)1 StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)1 StudyToolWindow (com.jetbrains.edu.learning.ui.StudyToolWindow)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1