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