Search in sources :

Example 1 with StudyEditor

use of com.jetbrains.edu.learning.editor.StudyEditor in project intellij-community by JetBrains.

the class StudyProjectGenerator method openFirstTask.

public static void openFirstTask(@NotNull final Course course, @NotNull final Project project) {
    LocalFileSystem.getInstance().refresh(false);
    final Lesson firstLesson = StudyUtils.getFirst(course.getLessons());
    if (firstLesson == null)
        return;
    final Task firstTask = StudyUtils.getFirst(firstLesson.getTaskList());
    if (firstTask == null)
        return;
    final VirtualFile taskDir = firstTask.getTaskDir(project);
    if (taskDir == null)
        return;
    final Map<String, TaskFile> taskFiles = firstTask.getTaskFiles();
    VirtualFile activeVirtualFile = null;
    for (Map.Entry<String, TaskFile> entry : taskFiles.entrySet()) {
        final String relativePath = entry.getKey();
        final TaskFile taskFile = entry.getValue();
        taskDir.refresh(false, true);
        final VirtualFile virtualFile = taskDir.findFileByRelativePath(relativePath);
        if (virtualFile != null) {
            if (!taskFile.getActivePlaceholders().isEmpty()) {
                activeVirtualFile = virtualFile;
            }
        }
    }
    if (activeVirtualFile != null) {
        final PsiFile file = PsiManager.getInstance(project).findFile(activeVirtualFile);
        ProjectView.getInstance(project).select(file, activeVirtualFile, false);
        final FileEditor[] editors = FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
        if (editors.length == 0) {
            return;
        }
        final FileEditor studyEditor = editors[0];
        if (studyEditor instanceof StudyEditor) {
            StudyUtils.selectFirstAnswerPlaceholder((StudyEditor) studyEditor, project);
        }
        FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
    } else {
        String first = StudyUtils.getFirst(taskFiles.keySet());
        if (first != null) {
            NewVirtualFile firstFile = ((VirtualDirectoryImpl) taskDir).refreshAndFindChild(first);
            if (firstFile != null) {
                FileEditorManager.getInstance(project).openFile(firstFile, true);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) VirtualDirectoryImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl) PsiFile(com.intellij.psi.PsiFile) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor)

Example 2 with StudyEditor

use of com.jetbrains.edu.learning.editor.StudyEditor in project intellij-community by JetBrains.

the class StudyRefreshTaskFileAction method showBalloon.

private static void showBalloon(@NotNull final Project project, String text, @NotNull final MessageType messageType) {
    BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(text, messageType, null);
    final Balloon balloon = balloonBuilder.createBalloon();
    StudyEditor selectedStudyEditor = StudyUtils.getSelectedStudyEditor(project);
    assert selectedStudyEditor != null;
    balloon.show(StudyUtils.computeLocation(selectedStudyEditor.getEditor()), Balloon.Position.above);
    Disposer.register(project, balloon);
}
Also used : Balloon(com.intellij.openapi.ui.popup.Balloon) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder)

Example 3 with StudyEditor

use of com.jetbrains.edu.learning.editor.StudyEditor in project intellij-community by JetBrains.

the class StudyRunAction method update.

@Override
public void update(AnActionEvent e) {
    EduUtils.enableAction(e, false);
    final Project project = e.getProject();
    if (project != null) {
        StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
        if (studyEditor != null) {
            final List<UserTest> userTests = StudyTaskManager.getInstance(project).getUserTests(studyEditor.getTaskFile().getTask());
            if (!userTests.isEmpty()) {
                EduUtils.enableAction(e, true);
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) UserTest(com.jetbrains.edu.learning.courseFormat.UserTest) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor)

Example 4 with StudyEditor

use of com.jetbrains.edu.learning.editor.StudyEditor in project intellij-community by JetBrains.

the class StudyUtils method selectFirstAnswerPlaceholder.

public static void selectFirstAnswerPlaceholder(@Nullable final StudyEditor studyEditor, @NotNull final Project project) {
    if (studyEditor == null)
        return;
    final Editor editor = studyEditor.getEditor();
    IdeFocusManager.getInstance(project).requestFocus(editor.getContentComponent(), true);
    final List<AnswerPlaceholder> placeholders = studyEditor.getTaskFile().getActivePlaceholders();
    if (placeholders.isEmpty())
        return;
    final AnswerPlaceholder placeholder = placeholders.get(0);
    Pair<Integer, Integer> offsets = getPlaceholderOffsets(placeholder, editor.getDocument());
    editor.getSelectionModel().setSelection(offsets.first, offsets.second);
    editor.getCaretModel().moveToOffset(offsets.first);
    editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
}
Also used : StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor)

Example 5 with StudyEditor

use of com.jetbrains.edu.learning.editor.StudyEditor in project intellij-community by JetBrains.

the class StudyCheckAction method updateDescription.

private static void updateDescription(AnActionEvent e) {
    final Presentation presentation = e.getPresentation();
    final Project project = e.getProject();
    if (project != null) {
        final StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
        if (studyEditor != null) {
            final Task task = studyEditor.getTaskFile().getTask();
            if (task.isTheoryTask()) {
                presentation.setText(getTextWithShortcuts("Get Next Recommendation"));
            } else {
                presentation.setText(getTextWithShortcuts(TEXT));
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) Task(com.jetbrains.edu.learning.courseFormat.Task) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Presentation(com.intellij.openapi.actionSystem.Presentation)

Aggregations

StudyEditor (com.jetbrains.edu.learning.editor.StudyEditor)20 Project (com.intellij.openapi.project.Project)10 TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Presentation (com.intellij.openapi.actionSystem.Presentation)4 Editor (com.intellij.openapi.editor.Editor)4 FileEditor (com.intellij.openapi.fileEditor.FileEditor)4 StudyState (com.jetbrains.edu.learning.StudyState)4 Task (com.jetbrains.edu.learning.courseFormat.Task)4 Document (com.intellij.openapi.editor.Document)3 UserTest (com.jetbrains.edu.learning.courseFormat.UserTest)3 Balloon (com.intellij.openapi.ui.popup.Balloon)2 StudyTaskManager (com.jetbrains.edu.learning.StudyTaskManager)2 AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)2 Map (java.util.Map)2 Nullable (org.jetbrains.annotations.Nullable)2 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 BalloonBuilder (com.intellij.openapi.ui.popup.BalloonBuilder)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 TextRange (com.intellij.openapi.util.TextRange)1