use of com.intellij.openapi.vcs.AbstractVcs 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.AbstractVcs 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.AbstractVcs in project intellij-community by JetBrains.
the class VcsQuickListPopupAction method getActiveVCS.
private Pair<SupportedVCS, AbstractVcs> getActiveVCS(@NotNull final Project project, @Nullable final DataContext dataContext) {
final AbstractVcs[] activeVcss = getActiveVCSs(project);
if (activeVcss.length == 0) {
// no vcs
return new Pair<>(SupportedVCS.NOT_IN_VCS, null);
} else if (activeVcss.length == 1) {
// get by name
return Pair.create(SupportedVCS.VCS, activeVcss[0]);
}
// by current file
final VirtualFile file = dataContext != null ? CommonDataKeys.VIRTUAL_FILE.getData(dataContext) : null;
if (file != null) {
final AbstractVcs vscForFile = ProjectLevelVcsManager.getInstance(project).getVcsFor(file);
if (vscForFile != null) {
return Pair.create(SupportedVCS.VCS, vscForFile);
}
}
return new Pair<>(SupportedVCS.VCS, null);
}
use of com.intellij.openapi.vcs.AbstractVcs in project intellij-community by JetBrains.
the class VcsQuickListPopupAction method fillActions.
protected void fillActions(@Nullable final Project project, @NotNull final DefaultActionGroup group, @NotNull final DataContext dataContext) {
if (project == null) {
return;
}
final Pair<SupportedVCS, AbstractVcs> typeAndVcs = getActiveVCS(project, dataContext);
final AbstractVcs vcs = typeAndVcs.getSecond();
final SupportedVCS popupType = typeAndVcs.getFirst();
switch(popupType) {
case VCS:
fillVcsPopup(project, group, dataContext, vcs);
break;
case NOT_IN_VCS:
fillNonInVcsActions(project, group, dataContext);
break;
}
}
use of com.intellij.openapi.vcs.AbstractVcs in project intellij-community by JetBrains.
the class TabbedShowHistoryAction method actionPerformed.
@Override
protected void actionPerformed(@NotNull VcsContext context) {
Project project = assertNotNull(context.getProject());
Pair<FilePath, VirtualFile> pair = getPathAndParentFile(context);
FilePath path = assertNotNull(pair.first);
VirtualFile fileOrParent = assertNotNull(pair.second);
AbstractVcs vcs = assertNotNull(ChangesUtil.getVcsForFile(fileOrParent, project));
if (canShowNewFileHistory(project, path)) {
showNewFileHistory(project, path);
} else {
showOldFileHistory(project, vcs, path);
}
}
Aggregations