Search in sources :

Example 31 with AbstractVcs

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) VcsSelection(com.intellij.vcsUtil.VcsSelection) BackgroundableActionEnabledHandler(com.intellij.openapi.vcs.impl.BackgroundableActionEnabledHandler) ProjectLevelVcsManagerImpl(com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl) VcsHistoryProvider(com.intellij.openapi.vcs.history.VcsHistoryProvider) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Example 32 with AbstractVcs

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) VcsSelection(com.intellij.vcsUtil.VcsSelection) VcsSelectionHistoryDialog(com.intellij.openapi.vcs.history.impl.VcsSelectionHistoryDialog) VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) VcsHistoryProvider(com.intellij.openapi.vcs.history.VcsHistoryProvider) VcsHistoryProviderBackgroundableProxy(com.intellij.openapi.vcs.history.VcsHistoryProviderBackgroundableProxy) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Example 33 with AbstractVcs

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) Pair(com.intellij.openapi.util.Pair)

Example 34 with AbstractVcs

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;
    }
}
Also used : AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Example 35 with AbstractVcs

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);
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Aggregations

AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 NotNull (org.jetbrains.annotations.NotNull)12 Project (com.intellij.openapi.project.Project)9 FilePath (com.intellij.openapi.vcs.FilePath)7 VcsRoot (com.intellij.openapi.vcs.VcsRoot)7 ProjectLevelVcsManager (com.intellij.openapi.vcs.ProjectLevelVcsManager)6 Nullable (org.jetbrains.annotations.Nullable)5 Module (com.intellij.openapi.module.Module)3 VcsDirectoryMapping (com.intellij.openapi.vcs.VcsDirectoryMapping)3 VcsKey (com.intellij.openapi.vcs.VcsKey)3 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)3 VcsHistoryProvider (com.intellij.openapi.vcs.history.VcsHistoryProvider)3 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)3 Date (java.util.Date)3 Pair (com.intellij.openapi.util.Pair)2 VcsException (com.intellij.openapi.vcs.VcsException)2 DiffProvider (com.intellij.openapi.vcs.diff.DiffProvider)2 VcsHistorySession (com.intellij.openapi.vcs.history.VcsHistorySession)2 VcsLogProvider (com.intellij.vcs.log.VcsLogProvider)2