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);
}
}
}
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);
}
}
}
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);
}
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);
}
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);
}
}
Aggregations