コード例 #1
0
 public static void drawAllPlaceholders(
     @NotNull final Project project,
     @NotNull final Task task,
     @NotNull final VirtualFile taskDir) {
   for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
     String name = entry.getKey();
     TaskFile taskFile = entry.getValue();
     VirtualFile virtualFile = taskDir.findChild(name);
     if (virtualFile == null) {
       continue;
     }
     FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
     if (fileEditor instanceof StudyEditor) {
       StudyEditor studyEditor = (StudyEditor) fileEditor;
       StudyUtils.drawAllWindows(studyEditor.getEditor(), taskFile);
     }
   }
 }
コード例 #2
0
  public static void navigateToFailedPlaceholder(
      @NotNull final StudyState studyState,
      @NotNull final Task task,
      @NotNull final VirtualFile taskDir,
      @NotNull final Project project) {
    TaskFile selectedTaskFile = studyState.getTaskFile();
    Editor editor = studyState.getEditor();
    TaskFile taskFileToNavigate = selectedTaskFile;
    VirtualFile fileToNavigate = studyState.getVirtualFile();
    final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
    if (!taskManager.hasFailedAnswerPlaceholders(selectedTaskFile)) {
      for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
        String name = entry.getKey();
        TaskFile taskFile = entry.getValue();
        if (taskManager.hasFailedAnswerPlaceholders(taskFile)) {
          taskFileToNavigate = taskFile;
          VirtualFile virtualFile = taskDir.findChild(name);
          if (virtualFile == null) {
            continue;
          }
          FileEditor fileEditor =
              FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
          if (fileEditor instanceof StudyEditor) {
            StudyEditor studyEditor = (StudyEditor) fileEditor;
            editor = studyEditor.getEditor();
          }
          fileToNavigate = virtualFile;
          break;
        }
      }
    }
    if (fileToNavigate != null) {
      FileEditorManager.getInstance(project).openFile(fileToNavigate, true);
    }
    final Editor editorToNavigate = editor;
    ApplicationManager.getApplication()
        .invokeLater(
            () ->
                IdeFocusManager.getInstance(project)
                    .requestFocus(editorToNavigate.getContentComponent(), true));

    StudyNavigator.navigateToFirstFailedAnswerPlaceholder(editor, taskFileToNavigate);
  }