use of com.intellij.openapi.vcs.history.VcsHistoryProvider in project intellij-community by JetBrains.
the class TabbedShowHistoryForRevisionAction method isVisible.
private static boolean isVisible(@NotNull AnActionEvent event) {
Project project = event.getProject();
if (project == null)
return false;
if (getVcsHelper(project) == null)
return false;
AbstractVcs vcs = getVcs(project, event.getData(VcsDataKeys.VCS));
if (vcs == null)
return false;
VcsHistoryProvider vcsHistoryProvider = vcs.getVcsHistoryProvider();
if (!(vcsHistoryProvider instanceof VcsHistoryProviderEx))
return false;
return true;
}
use of com.intellij.openapi.vcs.history.VcsHistoryProvider in project intellij-community by JetBrains.
the class AnnotateStackTraceAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
myIsLoading = true;
ProgressManager.getInstance().run(new Task.Backgroundable(myEditor.getProject(), "Getting File History", true) {
private final Object LOCK = new Object();
private final MergingUpdateQueue myUpdateQueue = new MergingUpdateQueue("AnnotateStackTraceAction", 200, true, null);
private MyActiveAnnotationGutter myGutter;
@Override
public void onCancel() {
myEditor.getGutter().closeAllAnnotations();
}
@Override
public void onFinished() {
myIsLoading = false;
Disposer.dispose(myUpdateQueue);
}
@Override
public void run(@NotNull ProgressIndicator indicator) {
MultiMap<VirtualFile, Integer> files2lines = new MultiMap<>();
Map<Integer, LastRevision> revisions = ContainerUtil.newHashMap();
ApplicationManager.getApplication().runReadAction(() -> {
for (int line = 0; line < myEditor.getDocument().getLineCount(); line++) {
indicator.checkCanceled();
VirtualFile file = getHyperlinkVirtualFile(myHyperlinks.findAllHyperlinksOnLine(line));
if (file == null)
continue;
files2lines.putValue(file, line);
}
});
files2lines.entrySet().forEach(entry -> {
indicator.checkCanceled();
VirtualFile file = entry.getKey();
Collection<Integer> lines = entry.getValue();
LastRevision revision = getLastRevision(file);
if (revision == null)
return;
synchronized (LOCK) {
for (Integer line : lines) {
revisions.put(line, revision);
}
}
myUpdateQueue.queue(new Update("update") {
@Override
public void run() {
updateGutter(indicator, revisions);
}
});
});
// myUpdateQueue can be disposed before the last revisions are passed to the gutter
ApplicationManager.getApplication().invokeLater(() -> updateGutter(indicator, revisions));
}
@CalledInAwt
private void updateGutter(@NotNull ProgressIndicator indicator, @NotNull Map<Integer, LastRevision> revisions) {
if (indicator.isCanceled())
return;
if (myGutter == null) {
myGutter = new MyActiveAnnotationGutter(getProject(), myHyperlinks, indicator);
myEditor.getGutter().registerTextAnnotation(myGutter, myGutter);
}
Map<Integer, LastRevision> revisionsCopy;
synchronized (LOCK) {
revisionsCopy = ContainerUtil.newHashMap(revisions);
}
myGutter.updateData(revisionsCopy);
((EditorGutterComponentEx) myEditor.getGutter()).revalidateMarkup();
}
@Nullable
private LastRevision getLastRevision(@NotNull VirtualFile file) {
try {
AbstractVcs vcs = VcsUtil.getVcsFor(myEditor.getProject(), file);
if (vcs == null)
return null;
VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
if (historyProvider == null)
return null;
FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
if (historyProvider instanceof VcsHistoryProviderEx) {
VcsFileRevision revision = ((VcsHistoryProviderEx) historyProvider).getLastRevision(filePath);
if (revision == null)
return null;
return LastRevision.create(revision);
} else {
VcsHistorySession session = historyProvider.createSessionFor(filePath);
if (session == null)
return null;
List<VcsFileRevision> list = session.getRevisionList();
if (list == null || list.isEmpty())
return null;
return LastRevision.create(list.get(0));
}
} catch (VcsException ignored) {
LOG.warn(ignored);
return null;
}
}
});
}
use of com.intellij.openapi.vcs.history.VcsHistoryProvider in project intellij-community by JetBrains.
the class SelectedBlockHistoryAction method isEnabled.
protected boolean isEnabled(VcsContext context) {
Project project = context.getProject();
if (project == null)
return false;
VcsSelection selection = VcsSelectionUtil.getSelection(context);
if (selection == null)
return false;
VirtualFile file = FileDocumentManager.getInstance().getFile(selection.getDocument());
if (file == null)
return false;
final ProjectLevelVcsManagerImpl vcsManager = (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(project);
final BackgroundableActionEnabledHandler handler = vcsManager.getBackgroundableActionHandler(VcsBackgroundableActions.HISTORY_FOR_SELECTION);
if (handler.isInProgress(VcsBackgroundableActions.keyFrom(file)))
return false;
AbstractVcs activeVcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
if (activeVcs == null)
return false;
VcsHistoryProvider provider = activeVcs.getVcsBlockHistoryProvider();
if (provider == null)
return false;
if (!AbstractVcs.fileInVcsByFileStatus(project, VcsUtil.getFilePath(file)))
return false;
return true;
}
use of com.intellij.openapi.vcs.history.VcsHistoryProvider in project intellij-community by JetBrains.
the class SelectedBlockHistoryAction method actionPerformed.
public void actionPerformed(@NotNull final VcsContext context) {
try {
final Project project = context.getProject();
assert project != null;
final VcsSelection selection = VcsSelectionUtil.getSelection(context);
assert selection != null;
final VirtualFile file = FileDocumentManager.getInstance().getFile(selection.getDocument());
assert file != null;
final AbstractVcs activeVcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
assert activeVcs != null;
final VcsHistoryProvider provider = activeVcs.getVcsBlockHistoryProvider();
assert provider != null;
final int selectionStart = selection.getSelectionStartLineNumber();
final int selectionEnd = selection.getSelectionEndLineNumber();
new VcsHistoryProviderBackgroundableProxy(activeVcs, provider, activeVcs.getDiffProvider()).createSessionFor(activeVcs.getKeyInstanceMethod(), VcsUtil.getFilePath(file), new Consumer<VcsHistorySession>() {
public void consume(VcsHistorySession session) {
if (session == null)
return;
final VcsSelectionHistoryDialog vcsHistoryDialog = new VcsSelectionHistoryDialog(project, file, selection.getDocument(), provider, session, activeVcs, Math.min(selectionStart, selectionEnd), Math.max(selectionStart, selectionEnd), selection.getDialogTitle());
vcsHistoryDialog.show();
}
}, VcsBackgroundableActions.HISTORY_FOR_SELECTION, false, null);
} catch (Exception exception) {
reportError(exception);
}
}
use of com.intellij.openapi.vcs.history.VcsHistoryProvider in project intellij-community by JetBrains.
the class TabbedShowHistoryAction method showOldFileHistory.
private static void showOldFileHistory(@NotNull Project project, @NotNull AbstractVcs vcs, @NotNull FilePath path) {
VcsHistoryProvider provider = assertNotNull(vcs.getVcsHistoryProvider());
AbstractVcsHelper.getInstance(project).showFileHistory(provider, vcs.getAnnotationProvider(), path, null, vcs);
}
Aggregations