Search in sources :

Example 1 with StudyState

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

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

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

the class StudyShowHintAction method showHint.

public void showHint(Project project) {
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    StudyState studyState = new StudyState(StudyUtils.getSelectedStudyEditor(project));
    if (!studyState.isValid()) {
        return;
    }
    PsiFile file = PsiManager.getInstance(project).findFile(studyState.getVirtualFile());
    final Editor editor = studyState.getEditor();
    int offset = editor.getCaretModel().getOffset();
    AnswerPlaceholder answerPlaceholder = studyState.getTaskFile().getAnswerPlaceholder(offset);
    if (file == null) {
        return;
    }
    EduUsagesCollector.hintShown();
    final StudyToolWindow hintComponent = getHint(project, answerPlaceholder).getStudyToolWindow();
    hintComponent.setPreferredSize(new Dimension(400, 150));
    showHintPopUp(project, studyState, editor, hintComponent);
}
Also used : AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) StudyState(com.jetbrains.edu.learning.StudyState) PsiFile(com.intellij.psi.PsiFile) StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow) Course(com.jetbrains.edu.learning.courseFormat.Course) Editor(com.intellij.openapi.editor.Editor) StudyHint(com.jetbrains.edu.learning.ui.StudyHint)

Example 4 with StudyState

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

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

Aggregations

StudyState (com.jetbrains.edu.learning.StudyState)5 StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)4 Project (com.intellij.openapi.project.Project)3 AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)2 Course (com.jetbrains.edu.learning.courseFormat.Course)2 TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)2 Presentation (com.intellij.openapi.actionSystem.Presentation)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 PsiFile (com.intellij.psi.PsiFile)1 Task (com.jetbrains.edu.learning.courseFormat.Task)1 StudyHint (com.jetbrains.edu.learning.ui.StudyHint)1 StudyToolWindow (com.jetbrains.edu.learning.ui.StudyToolWindow)1