Search in sources :

Example 1 with StudyToolWindow

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

the class StudyProjectComponent method registerShortcuts.

private void registerShortcuts() {
    StudyToolWindow window = StudyUtils.getStudyToolWindow(myProject);
    if (window != null) {
        List<AnAction> actionsOnToolbar = window.getActions(true);
        for (AnAction action : actionsOnToolbar) {
            if (action instanceof StudyActionWithShortcut) {
                String id = ((StudyActionWithShortcut) action).getActionId();
                String[] shortcuts = ((StudyActionWithShortcut) action).getShortcuts();
                if (shortcuts != null) {
                    addShortcut(id, shortcuts);
                }
            }
        }
        addShortcut(StudyNextWindowAction.ACTION_ID, new String[] { StudyNextWindowAction.SHORTCUT, StudyNextWindowAction.SHORTCUT2 });
        addShortcut(StudyPrevWindowAction.ACTION_ID, new String[] { StudyPrevWindowAction.SHORTCUT });
    }
}
Also used : StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow) StudyActionWithShortcut(com.jetbrains.edu.learning.actions.StudyActionWithShortcut)

Example 2 with StudyToolWindow

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

the class StudySubtaskUtils method updateUI.

public static void updateUI(@NotNull Project project, @NotNull Task task, VirtualFile taskDir, boolean navigateToTask) {
    StudyCheckUtils.drawAllPlaceholders(project, task);
    ProjectView.getInstance(project).refresh();
    StudyToolWindow toolWindow = StudyUtils.getStudyToolWindow(project);
    if (toolWindow != null) {
        String text = StudyUtils.getTaskTextFromTask(taskDir, task);
        if (text == null) {
            toolWindow.setEmptyText(project);
            return;
        }
        toolWindow.setTaskText(text, taskDir, project);
    }
    if (navigateToTask) {
        StudyNavigator.navigateToTask(project, task);
    }
}
Also used : StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow)

Example 3 with StudyToolWindow

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

the class CCEditTaskTextAction method setSelected.

@Override
public void setSelected(AnActionEvent e, boolean state) {
    Project project = e.getProject();
    if (project == null) {
        return;
    }
    StudyToolWindow window = StudyUtils.getStudyToolWindow(project);
    if (window == null) {
        return;
    }
    Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    if (editor == null) {
        return;
    }
    VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(editor.getDocument());
    if (virtualFile == null) {
        StudyTaskManager.getInstance(project).setTurnEditingMode(true);
        return;
    }
    Task task = StudyUtils.getTaskForFile(project, virtualFile);
    if (task == null) {
        StudyTaskManager.getInstance(project).setTurnEditingMode(true);
        return;
    }
    VirtualFile taskDir = task.getTaskDir(project);
    if (taskDir == null) {
        StudyTaskManager.getInstance(project).setTurnEditingMode(true);
        return;
    }
    VirtualFile taskTextFile = StudyUtils.findTaskDescriptionVirtualFile(project, taskDir);
    if (taskTextFile == null) {
        LOG.info("Failed to find task.html");
        StudyTaskManager.getInstance(project).setTurnEditingMode(true);
        return;
    }
    Document document = FileDocumentManager.getInstance().getDocument(taskTextFile);
    if (!state) {
        if (document != null) {
            FileDocumentManager.getInstance().saveDocument(document);
        }
        window.leaveEditingMode(project);
        return;
    }
    window.enterEditingMode(taskTextFile, project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Task(com.jetbrains.edu.learning.courseFormat.Task) StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document)

Example 4 with StudyToolWindow

use of com.jetbrains.edu.learning.ui.StudyToolWindow 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);
}
Also used : StudyChoiceVariantsPanel(com.jetbrains.edu.learning.editor.StudyChoiceVariantsPanel) StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Editor(com.intellij.openapi.editor.Editor)

Example 5 with StudyToolWindow

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

the class StudyUtils method registerStudyToolWindow.

public static void registerStudyToolWindow(@Nullable final Course course, Project project) {
    if (course != null && "PyCharm".equals(course.getCourseType())) {
        final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
        registerToolWindows(toolWindowManager, project);
        final ToolWindow studyToolWindow = toolWindowManager.getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW);
        if (studyToolWindow != null) {
            studyToolWindow.show(null);
            initToolWindows(project);
        }
    }
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) StudyToolWindow(com.jetbrains.edu.learning.ui.StudyToolWindow) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager)

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