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