Search in sources :

Example 16 with StudyEditor

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

the class StudyTaskNavigationAction method navigateTask.

public void navigateTask(@NotNull final Project project) {
    StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
    StudyState studyState = new StudyState(studyEditor);
    if (!studyState.isValid()) {
        return;
    }
    Task targetTask = getTargetTask(studyState.getTask());
    if (targetTask == null) {
        return;
    }
    StudyNavigator.navigateToTask(project, targetTask);
}
Also used : Task(com.jetbrains.edu.learning.courseFormat.Task) StudyState(com.jetbrains.edu.learning.StudyState) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor)

Example 17 with StudyEditor

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

the class StudyTaskNavigationAction method update.

@Override
public void update(AnActionEvent e) {
    StudyUtils.updateAction(e);
    Project project = e.getProject();
    if (project == null) {
        return;
    }
    StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
    StudyState studyState = new StudyState(studyEditor);
    if (!studyState.isValid()) {
        return;
    }
    if (getTargetTask(studyState.getTask()) == null) {
        e.getPresentation().setEnabled(false);
    }
}
Also used : Project(com.intellij.openapi.project.Project) StudyState(com.jetbrains.edu.learning.StudyState) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor)

Example 18 with StudyEditor

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

the class StudyCheckUtils method drawAllPlaceholders.

public static void drawAllPlaceholders(@NotNull final Project project, @NotNull final Task task) {
    VirtualFile taskDir = task.getTaskDir(project);
    if (taskDir == null) {
        return;
    }
    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;
        }
        FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
        if (fileEditor instanceof StudyEditor) {
            StudyEditor studyEditor = (StudyEditor) fileEditor;
            StudyUtils.drawAllAnswerPlaceholders(studyEditor.getEditor(), taskFile);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Map(java.util.Map)

Example 19 with StudyEditor

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

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

the class StudyUtils method showCheckPopUp.

/**
   * shows pop up in the center of "check task" button in study editor
   */
public static void showCheckPopUp(@NotNull final Project project, @NotNull final Balloon balloon) {
    final StudyEditor studyEditor = getSelectedStudyEditor(project);
    assert studyEditor != null;
    balloon.show(computeLocation(studyEditor.getEditor()), Balloon.Position.above);
    Disposer.register(project, balloon);
}
Also used : StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor)

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