Search in sources :

Example 1 with AnnotationProvider

use of com.intellij.openapi.vcs.annotate.AnnotationProvider 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)

Example 2 with AnnotationProvider

use of com.intellij.openapi.vcs.annotate.AnnotationProvider in project intellij-community by JetBrains.

the class AnnotateLocalFileAction method isEnabled.

private static boolean isEnabled(AnActionEvent e) {
    VcsContext context = VcsContextFactory.SERVICE.getInstance().createContextOn(e);
    Project project = context.getProject();
    if (project == null || project.isDisposed())
        return false;
    VirtualFile file = context.getSelectedFile();
    if (file == null || file.isDirectory() || file.getFileType().isBinary())
        return false;
    final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
    if (vcs == null)
        return false;
    final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
    if (annotationProvider == null)
        return false;
    final FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(file);
    if (fileStatus == FileStatus.UNKNOWN || fileStatus == FileStatus.ADDED || fileStatus == FileStatus.IGNORED) {
        return false;
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AnnotationProvider(com.intellij.openapi.vcs.annotate.AnnotationProvider)

Example 3 with AnnotationProvider

use of com.intellij.openapi.vcs.annotate.AnnotationProvider in project intellij-community by JetBrains.

the class AnnotateLocalFileAction method doAnnotate.

private static void doAnnotate(@NotNull final Editor editor, @NotNull final Project project) {
    final VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument());
    if (file == null)
        return;
    final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
    if (vcs == null)
        return;
    final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
    assert annotationProvider != 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(annotationProvider.annotate(file));
            } 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, file, fileAnnotationRef.get(), vcs);
            }
        }
    };
    ProgressManager.getInstance().run(annotateTask);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) AnnotationProvider(com.intellij.openapi.vcs.annotate.AnnotationProvider) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull) 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 4 with AnnotationProvider

use of com.intellij.openapi.vcs.annotate.AnnotationProvider in project intellij-community by JetBrains.

the class AnnotateRevisionActionBase method annotate.

public static void annotate(@NotNull VirtualFile file, @NotNull VcsFileRevision fileRevision, @NotNull AbstractVcs vcs, @Nullable Editor editor, int annotatedLine) {
    final CharSequence oldContent = editor == null ? null : editor.getDocument().getImmutableCharSequence();
    final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
    assert annotationProvider != null;
    final Ref<FileAnnotation> fileAnnotationRef = new Ref<>();
    final Ref<Integer> newLineRef = new Ref<>();
    final Ref<VcsException> exceptionRef = new Ref<>();
    VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).lock();
    Semaphore semaphore = new Semaphore(0);
    AtomicBoolean shouldOpenEditorInSync = new AtomicBoolean(true);
    ProgressManager.getInstance().run(new Task.Backgroundable(vcs.getProject(), VcsBundle.message("retrieving.annotations"), true) {

        public void run(@NotNull ProgressIndicator indicator) {
            try {
                FileAnnotation fileAnnotation = annotationProvider.annotate(file, fileRevision);
                int newLine = translateLine(oldContent, fileAnnotation.getAnnotatedContent(), annotatedLine);
                fileAnnotationRef.set(fileAnnotation);
                newLineRef.set(newLine);
                shouldOpenEditorInSync.set(false);
                semaphore.release();
            } catch (VcsException e) {
                exceptionRef.set(e);
            }
        }

        @Override
        public void onFinished() {
            VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).unlock();
        }

        @Override
        public void onSuccess() {
            if (!exceptionRef.isNull()) {
                AbstractVcsHelper.getInstance(myProject).showError(exceptionRef.get(), VcsBundle.message("operation.name.annotate"));
            }
            if (fileAnnotationRef.isNull())
                return;
            AbstractVcsHelper.getInstance(myProject).showAnnotation(fileAnnotationRef.get(), file, vcs, newLineRef.get());
        }
    });
    try {
        semaphore.tryAcquire(ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS, TimeUnit.MILLISECONDS);
        // This will remove blinking on editor opening (step 1 - editor opens, step 2 - annotations are shown).
        if (shouldOpenEditorInSync.get()) {
            CharSequence content = LoadTextUtil.loadText(file);
            int newLine = translateLine(oldContent, content, annotatedLine);
            OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(vcs.getProject(), file, newLine, 0);
            FileEditorManager.getInstance(vcs.getProject()).openTextEditor(openFileDescriptor, true);
        }
    } catch (InterruptedException ignore) {
    }
}
Also used : Task(com.intellij.openapi.progress.Task) AnnotationProvider(com.intellij.openapi.vcs.annotate.AnnotationProvider) Semaphore(java.util.concurrent.Semaphore) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation)

Example 5 with AnnotationProvider

use of com.intellij.openapi.vcs.annotate.AnnotationProvider in project intellij-community by JetBrains.

the class AnnotateRevisionFromHistoryAction method isEnabled.

@Override
protected boolean isEnabled(@NotNull FileHistoryUi ui, @Nullable VcsFullCommitDetails detail, @NotNull AnActionEvent e) {
    VcsKey key = e.getData(VcsDataKeys.VCS);
    if (key == null)
        return false;
    AbstractVcs vcs = VcsUtil.findVcsByKey(notNull(e.getProject()), key);
    if (vcs == null)
        return false;
    AnnotationProvider provider = vcs.getAnnotationProvider();
    if (provider == null)
        return false;
    if (detail != null) {
        VcsFileRevision fileRevision = ui.createRevision(detail);
        return AnnotateRevisionActionBase.isEnabled(vcs, ui.createVcsVirtualFile(fileRevision), fileRevision);
    }
    return true;
}
Also used : VcsKey(com.intellij.openapi.vcs.VcsKey) AnnotationProvider(com.intellij.openapi.vcs.annotate.AnnotationProvider) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Aggregations

AnnotationProvider (com.intellij.openapi.vcs.annotate.AnnotationProvider)7 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 Project (com.intellij.openapi.project.Project)2 Ref (com.intellij.openapi.util.Ref)2 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)1 FilePath (com.intellij.openapi.vcs.FilePath)1 VcsException (com.intellij.openapi.vcs.VcsException)1 VcsKey (com.intellij.openapi.vcs.VcsKey)1 VcsAnnotation (com.intellij.openapi.vcs.annotate.VcsAnnotation)1 VcsCacheableAnnotationProvider (com.intellij.openapi.vcs.annotate.VcsCacheableAnnotationProvider)1 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)1 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)1 ContentRevisionVirtualFile (com.intellij.openapi.vcs.vfs.ContentRevisionVirtualFile)1 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)1 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)1