コード例 #1
0
  public void setSelected(AnActionEvent e, boolean state) {
    VcsContext context = VcsContextFactory.SERVICE.getInstance().createContextOn(e);
    Editor editor = context.getEditor();
    if (!state) {
      if (editor != null) {
        editor.getGutter().closeAllAnnotations();
      }
    } else {
      if (editor == null) {
        VirtualFile selectedFile = context.getSelectedFile();
        if (selectedFile == null) {
          return;
        }

        FileEditor[] fileEditors =
            FileEditorManager.getInstance(context.getProject()).openFile(selectedFile, false);
        for (FileEditor fileEditor : fileEditors) {
          if (fileEditor instanceof TextEditor) {
            editor = ((TextEditor) fileEditor).getEditor();
          }
        }
      }

      LOGGER.assertTrue(editor != null);

      doAnnotate(editor, context.getProject());
    }
  }
コード例 #2
0
  public static void doAnnotate(
      final Editor editor, final Project project, final FileAnnotation fileAnnotation) {
    final UpToDateLineNumberProvider getUpToDateLineNumber =
        new UpToDateLineNumberProviderImpl(editor.getDocument(), project);

    editor.getGutter().closeAllAnnotations();

    // be careful, not proxies but original items are put there (since only their presence not
    // behaviour is important)
    Collection<ActiveAnnotationGutter> annotations = editor.getUserData(KEY_IN_EDITOR);
    if (annotations == null) {
      annotations = new HashSet<ActiveAnnotationGutter>();
      editor.putUserData(KEY_IN_EDITOR, annotations);
    }

    final RevuAnnotationFieldGutter gutter = new RevuAnnotationFieldGutter(fileAnnotation, editor);
    final AnnotationGutterLineConvertorProxy proxy =
        new AnnotationGutterLineConvertorProxy(getUpToDateLineNumber, gutter);
    editor.getGutter().registerTextAnnotation(proxy, proxy);
    annotations.add(gutter);
  }
コード例 #3
0
 @Override
 public void update(AnActionEvent e) {
   boolean isShown = myEditor.getGutter().isAnnotationsShown();
   e.getPresentation().setEnabled(!isShown && !myIsLoading);
 }