Search in sources :

Example 6 with StudyToolWindow

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);
            }
        }
    });
}
Also used : EditorColorsListener(com.intellij.openapi.editor.colors.EditorColorsListener) HyperlinkEvent(javax.swing.event.HyperlinkEvent) UISettings(com.intellij.ide.ui.UISettings) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow) StudyProjectGenerator.flushCourse(com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator.flushCourse) Notification(com.intellij.notification.Notification) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable) NotificationListener(com.intellij.notification.NotificationListener)

Example 7 with StudyToolWindow

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"));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Balloon(com.intellij.openapi.ui.popup.Balloon) StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow) IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 8 with StudyToolWindow

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);
}
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 9 with StudyToolWindow

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);
                }
            });
        }
    };
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow) StudyCheckTask(com.jetbrains.edu.learning.checker.StudyCheckTask) Course(com.jetbrains.edu.learning.courseFormat.Course) NotNull(org.jetbrains.annotations.NotNull) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with StudyToolWindow

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);
    }
}
Also used : StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow)

Aggregations

StudyToolWindow (com.jetbrains.edu.learning.ui.StudyToolWindow)10 Editor (com.intellij.openapi.editor.Editor)3 Document (com.intellij.openapi.editor.Document)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Course (com.jetbrains.edu.learning.courseFormat.Course)2 StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)2 UISettings (com.intellij.ide.ui.UISettings)1 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 EditorColorsListener (com.intellij.openapi.editor.colors.EditorColorsListener)1 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 DumbAwareRunnable (com.intellij.openapi.project.DumbAwareRunnable)1 Project (com.intellij.openapi.project.Project)1 Balloon (com.intellij.openapi.ui.popup.Balloon)1 ToolWindow (com.intellij.openapi.wm.ToolWindow)1 ToolWindowManager (com.intellij.openapi.wm.ToolWindowManager)1 PsiFile (com.intellij.psi.PsiFile)1 StudyState (com.jetbrains.edu.learning.StudyState)1 StudyActionWithShortcut (com.jetbrains.edu.learning.actions.StudyActionWithShortcut)1 StudyCheckTask (com.jetbrains.edu.learning.checker.StudyCheckTask)1