use of com.jetbrains.edu.learning.ui.StudyToolWindow in project intellij-community by JetBrains.
the class StudyProjectComponent method projectOpened.
@Override
public void projectOpened() {
Course course = StudyTaskManager.getInstance(myProject).getCourse();
// Check if user has javafx lib in his JDK. Now bundled JDK doesn't have this lib inside.
if (StudyUtils.hasJavaFx()) {
Platform.setImplicitExit(false);
}
if (course != null && !course.isAdaptive() && !course.isUpToDate()) {
final Notification notification = new Notification("Update.course", "Course Updates", "Course is ready to <a href=\"update\">update</a>", NotificationType.INFORMATION, new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
FileEditorManagerEx.getInstanceEx(myProject).closeAllFiles();
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
return execCancelable(() -> {
updateCourse();
return true;
});
}, "Updating Course", true, myProject);
EduUtils.synchronize();
course.setUpdated();
}
});
notification.notify(myProject);
}
StudyUtils.registerStudyToolWindow(course, myProject);
StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> ApplicationManager.getApplication().invokeLater((DumbAwareRunnable) () -> ApplicationManager.getApplication().runWriteAction((DumbAwareRunnable) () -> {
Course course1 = StudyTaskManager.getInstance(myProject).getCourse();
if (course1 != null) {
UISettings instance = UISettings.getInstance();
instance.setHideToolStripes(false);
instance.fireUISettingsChanged();
registerShortcuts();
EduUsagesCollector.projectTypeOpened(course1.isAdaptive() ? EduNames.ADAPTIVE : EduNames.STUDY);
}
})));
myBusConnection = ApplicationManager.getApplication().getMessageBus().connect();
myBusConnection.subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
@Override
public void globalSchemeChange(EditorColorsScheme scheme) {
final StudyToolWindow toolWindow = StudyUtils.getStudyToolWindow(myProject);
if (toolWindow != null) {
toolWindow.updateFonts(myProject);
}
}
});
}
use of com.jetbrains.edu.learning.ui.StudyToolWindow in project intellij-community by JetBrains.
the class EduAdaptiveStepicConnector method addNextRecommendedTask.
public static void addNextRecommendedTask(@NotNull Project project, @NotNull ProgressIndicator indicator, int reaction) {
final StudyEditor editor = StudyUtils.getSelectedStudyEditor(project);
final Course course = StudyTaskManager.getInstance(project).getCourse();
if (course != null && editor != null && editor.getTaskFile() != null) {
indicator.checkCanceled();
final StepicUser user = StepicUpdateSettings.getInstance().getUser();
final boolean recommendationReaction = postRecommendationReaction(String.valueOf(editor.getTaskFile().getTask().getLesson().getId()), String.valueOf(user.getId()), reaction);
if (recommendationReaction) {
indicator.checkCanceled();
final Task task = getNextRecommendation(project, course);
if (task != null) {
final Lesson adaptive = course.getLessons().get(0);
final Task unsolvedTask = adaptive.getTaskList().get(adaptive.getTaskList().size() - 1);
final String lessonName = EduNames.LESSON + String.valueOf(adaptive.getIndex());
if (reaction == TOO_HARD_RECOMMENDATION_REACTION || reaction == TOO_BORING_RECOMMENDATION_REACTION) {
unsolvedTask.copyParametersOf(task);
final Map<String, TaskFile> taskFiles = task.getTaskFiles();
if (taskFiles.size() == 1) {
final TaskFile taskFile = editor.getTaskFile();
taskFile.text = ((TaskFile) taskFiles.values().toArray()[0]).text;
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
final Document document = editor.getEditor().getDocument();
document.setText(taskFile.text);
}));
} else {
LOG.warn("Got task without unexpected number of task files: " + taskFiles.size());
}
final File lessonDirectory = new File(course.getCourseDirectory(), lessonName);
final String taskName = EduNames.TASK + String.valueOf(adaptive.getTaskList().size());
final File taskDirectory = new File(lessonDirectory, taskName);
StudyProjectGenerator.flushTask(task, taskDirectory);
StudyProjectGenerator.flushCourseJson(course, new File(course.getCourseDirectory()));
final VirtualFile lessonDir = project.getBaseDir().findChild(lessonName);
if (lessonDir != null) {
createTestFiles(course, project, unsolvedTask, lessonDir);
}
final StudyToolWindow window = StudyUtils.getStudyToolWindow(project);
if (window != null) {
window.setTaskText(StudyUtils.wrapTextToDisplayLatex(unsolvedTask.getText()), unsolvedTask.getTaskDir(project), project);
}
StudyNavigator.navigateToTask(project, lessonName, taskName);
} else {
adaptive.addTask(task);
task.setIndex(adaptive.getTaskList().size());
final VirtualFile lessonDir = project.getBaseDir().findChild(lessonName);
if (lessonDir != null) {
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
try {
final File lessonDirectory = new File(course.getCourseDirectory(), lessonName);
final String taskName = EduNames.TASK + String.valueOf(task.getIndex());
final File taskDir = new File(lessonDirectory, taskName);
StudyProjectGenerator.flushTask(task, taskDir);
StudyProjectGenerator.flushCourseJson(course, new File(course.getCourseDirectory()));
StudyGenerator.createTask(task, lessonDir, new File(course.getCourseDirectory(), lessonDir.getName()), project);
adaptive.initLesson(course, true);
StudyNavigator.navigateToTask(project, lessonName, taskName);
} catch (IOException e) {
LOG.warn(e.getMessage());
}
}));
}
}
} else {
ApplicationManager.getApplication().invokeLater(() -> {
final Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder("Couldn't load a new recommendation", MessageType.ERROR, null).createBalloon();
StudyUtils.showCheckPopUp(project, balloon);
});
}
ApplicationManager.getApplication().invokeLater(() -> {
VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
ProjectView.getInstance(project).refresh();
});
} else {
LOG.warn("Recommendation reactions weren't posted");
ApplicationManager.getApplication().invokeLater(() -> StudyUtils.showErrorPopupOnToolbar(project, "Couldn't post your reaction"));
}
}
}
use of com.jetbrains.edu.learning.ui.StudyToolWindow 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.ui.StudyToolWindow in project intellij-community by JetBrains.
the class PyStudyCheckAction method getCheckTask.
@NotNull
private StudyCheckTask getCheckTask(@NotNull final Project project, final StudyState studyState, final StudyTestRunner testRunner, final Process testProcess, final String commandLine) {
return new StudyCheckTask(project, studyState, myCheckInProgress, testProcess, commandLine) {
@Override
protected void onTaskFailed(@NotNull String message) {
ApplicationManager.getApplication().invokeLater(() -> {
if (myTaskDir == null)
return;
myTask.setStatus(StudyStatus.Failed);
for (Map.Entry<String, TaskFile> entry : myTask.getTaskFiles().entrySet()) {
final String name = entry.getKey();
final TaskFile taskFile = entry.getValue();
if (taskFile.getActivePlaceholders().size() < 2) {
continue;
}
final Course course = myTaskManger.getCourse();
if (course != null && EduNames.STUDY.equals(course.getCourseMode())) {
CommandProcessor.getInstance().runUndoTransparentAction(() -> ApplicationManager.getApplication().runWriteAction(() -> {
StudyCheckUtils.runSmartTestProcess(myTaskDir, testRunner, name, taskFile, project);
}));
}
}
final StudyToolWindow toolWindow = StudyUtils.getStudyToolWindow(project);
if (toolWindow != null) {
final Course course = StudyTaskManager.getInstance(project).getCourse();
if (course != null) {
if (course.isAdaptive()) {
if (myTask.isChoiceTask()) {
StudyCheckUtils.showTestResultPopUp("Wrong answer", MessageType.ERROR.getPopupBackground(), project);
} else {
StudyCheckUtils.showTestResultPopUp("Wrong answer", MessageType.ERROR.getPopupBackground(), project);
StudyCheckUtils.showTestResultsToolWindow(project, message, false);
}
repaintChoicePanel(project, myTask);
} else {
StudyCheckUtils.showTestResultPopUp(message, MessageType.ERROR.getPopupBackground(), project);
}
}
StudyCheckUtils.navigateToFailedPlaceholder(myStudyState, myTask, myTaskDir, project);
}
});
}
};
}
use of com.jetbrains.edu.learning.ui.StudyToolWindow in project intellij-community by JetBrains.
the class StudyUtils method updateToolWindows.
public static void updateToolWindows(@NotNull final Project project) {
final StudyToolWindow studyToolWindow = getStudyToolWindow(project);
if (studyToolWindow != null) {
String taskText = getTaskText(project);
if (taskText != null) {
studyToolWindow.setTaskText(taskText, null, project);
} else {
LOG.warn("Task text is null");
}
studyToolWindow.updateCourseProgress(project);
}
}
Aggregations