Search in sources :

Example 1 with AnnotationProviderEx

use of com.intellij.vcs.AnnotationProviderEx in project intellij-community by JetBrains.

the class AnnotateVcsVirtualFileAction method doAnnotate.

private static void doAnnotate(@NotNull final Project project, @NotNull final Editor editor, @NotNull final VirtualFile file) {
    final AnnotationData data = extractData(project, file);
    assert data != null;
    final AnnotationProviderEx provider = (AnnotationProviderEx) data.vcs.getAnnotationProvider();
    assert provider != null;
    final Ref<FileAnnotation> fileAnnotationRef = new Ref<>();
    final Ref<VcsException> exceptionRef = new Ref<>();
    VcsAnnotateUtil.getBackgroundableLock(project, file).lock();
    final Task.Backgroundable annotateTask = new Task.Backgroundable(project, VcsBundle.message("retrieving.annotations"), true) {

        @Override
        public void run(@NotNull final ProgressIndicator indicator) {
            try {
                fileAnnotationRef.set(provider.annotate(data.filePath, data.revisionNumber));
            } catch (VcsException e) {
                exceptionRef.set(e);
            } catch (ProcessCanceledException pce) {
                throw pce;
            } catch (Throwable t) {
                exceptionRef.set(new VcsException(t));
            }
        }

        @Override
        public void onCancel() {
            onSuccess();
        }

        @Override
        public void onSuccess() {
            VcsAnnotateUtil.getBackgroundableLock(project, file).unlock();
            if (!exceptionRef.isNull()) {
                LOG.warn(exceptionRef.get());
                AbstractVcsHelper.getInstance(project).showErrors(Collections.singletonList(exceptionRef.get()), VcsBundle.message("message.title.annotate"));
            }
            if (!fileAnnotationRef.isNull()) {
                AnnotateToggleAction.doAnnotate(editor, project, null, fileAnnotationRef.get(), data.vcs);
            }
        }
    };
    ProgressManager.getInstance().run(annotateTask);
}
Also used : Task(com.intellij.openapi.progress.Task) AnnotationProviderEx(com.intellij.vcs.AnnotationProviderEx) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 2 with AnnotationProviderEx

use of com.intellij.vcs.AnnotationProviderEx in project intellij-community by JetBrains.

the class AnnotateVcsVirtualFileAction method isEnabled.

private static boolean isEnabled(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null || project.isDisposed())
        return false;
    VirtualFile[] selectedFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (selectedFiles == null || selectedFiles.length != 1)
        return false;
    VirtualFile file = selectedFiles[0];
    if (file.isDirectory() || file.getFileType().isBinary())
        return false;
    if (VcsAnnotateUtil.getEditors(project, file).isEmpty())
        return false;
    AnnotationData data = extractData(project, file);
    if (data == null)
        return false;
    AnnotationProvider provider = data.vcs.getAnnotationProvider();
    return provider instanceof AnnotationProviderEx;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentRevisionVirtualFile(com.intellij.openapi.vcs.vfs.ContentRevisionVirtualFile) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) Project(com.intellij.openapi.project.Project) AnnotationProvider(com.intellij.openapi.vcs.annotate.AnnotationProvider) AnnotationProviderEx(com.intellij.vcs.AnnotationProviderEx)

Aggregations

AnnotationProviderEx (com.intellij.vcs.AnnotationProviderEx)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 Ref (com.intellij.openapi.util.Ref)1 AnnotationProvider (com.intellij.openapi.vcs.annotate.AnnotationProvider)1 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)1 ContentRevisionVirtualFile (com.intellij.openapi.vcs.vfs.ContentRevisionVirtualFile)1 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 NotNull (org.jetbrains.annotations.NotNull)1