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