Search in sources :

Example 1 with BackgroundableActionEnabledHandler

use of com.intellij.openapi.vcs.impl.BackgroundableActionEnabledHandler 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 2 with BackgroundableActionEnabledHandler

use of com.intellij.openapi.vcs.impl.BackgroundableActionEnabledHandler in project intellij-community by JetBrains.

the class VcsHistoryProviderBackgroundableProxy method doExecuteAppendableSession.

private void doExecuteAppendableSession(final VcsKey vcsKey, final FilePath filePath, @Nullable VcsRevisionNumber startRevisionNumber, final VcsAppendableHistorySessionPartner partner, @Nullable VcsBackgroundableActions actionKey, boolean canUseCache, boolean canUseLastRevisionCheck) {
    if (myCachesHistory && canUseCache) {
        final VcsAbstractHistorySession session = getFullHistoryFromCache(vcsKey, filePath);
        if (session != null) {
            partner.reportCreatedEmptySession(session);
            partner.finished();
            return;
        }
    }
    final ProjectLevelVcsManagerImpl vcsManager = (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(myProject);
    final VcsBackgroundableActions resultingActionKey = actionKey == null ? VcsBackgroundableActions.CREATE_HISTORY_SESSION : actionKey;
    final BackgroundableActionEnabledHandler handler;
    handler = vcsManager.getBackgroundableActionHandler(resultingActionKey);
    // fo not start same action twice
    if (handler.isInProgress(resultingActionKey))
        return;
    handler.register(resultingActionKey);
    final VcsAppendableHistorySessionPartner cachedPartner;
    if (myCachesHistory && startRevisionNumber == null) {
        cachedPartner = new HistoryPartnerProxy(partner, session -> {
            if (session == null)
                return;
            VcsCacheableHistorySessionFactory<Serializable, VcsAbstractHistorySession> delegate = (VcsCacheableHistorySessionFactory<Serializable, VcsAbstractHistorySession>) myDelegate;
            FilePath correctedPath = delegate.getUsedFilePath(session);
            myVcsHistoryCache.put(filePath, correctedPath, vcsKey, (VcsAbstractHistorySession) session.copy(), delegate, true);
        });
    } else {
        cachedPartner = partner;
    }
    reportHistory(filePath, startRevisionNumber, vcsKey, resultingActionKey, handler, cachedPartner, canUseLastRevisionCheck);
}
Also used : ItemLatestState(com.intellij.openapi.vcs.diff.ItemLatestState) VcsBackgroundableComputable(com.intellij.openapi.vcs.impl.VcsBackgroundableComputable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) ArrayList(java.util.ArrayList) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Task(com.intellij.openapi.progress.Task) DiffProvider(com.intellij.openapi.vcs.diff.DiffProvider) Project(com.intellij.openapi.project.Project) com.intellij.openapi.vcs(com.intellij.openapi.vcs) VcsBackgroundableActions(com.intellij.openapi.vcs.impl.VcsBackgroundableActions) ProgressManager(com.intellij.openapi.progress.ProgressManager) VcsUtil(com.intellij.vcsUtil.VcsUtil) BackgroundableActionEnabledHandler(com.intellij.openapi.vcs.impl.BackgroundableActionEnabledHandler) ProjectLevelVcsManagerImpl(com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VcsHistoryProviderEx(com.intellij.vcs.history.VcsHistoryProviderEx) Serializable(java.io.Serializable) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) Serializable(java.io.Serializable) BackgroundableActionEnabledHandler(com.intellij.openapi.vcs.impl.BackgroundableActionEnabledHandler) ProjectLevelVcsManagerImpl(com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl) VcsBackgroundableActions(com.intellij.openapi.vcs.impl.VcsBackgroundableActions)

Aggregations

Project (com.intellij.openapi.project.Project)2 BackgroundableActionEnabledHandler (com.intellij.openapi.vcs.impl.BackgroundableActionEnabledHandler)2 ProjectLevelVcsManagerImpl (com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModalityState (com.intellij.openapi.application.ModalityState)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Task (com.intellij.openapi.progress.Task)1 ThrowableComputable (com.intellij.openapi.util.ThrowableComputable)1 com.intellij.openapi.vcs (com.intellij.openapi.vcs)1 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)1 DiffProvider (com.intellij.openapi.vcs.diff.DiffProvider)1 ItemLatestState (com.intellij.openapi.vcs.diff.ItemLatestState)1 VcsHistoryProvider (com.intellij.openapi.vcs.history.VcsHistoryProvider)1 VcsBackgroundableActions (com.intellij.openapi.vcs.impl.VcsBackgroundableActions)1 VcsBackgroundableComputable (com.intellij.openapi.vcs.impl.VcsBackgroundableComputable)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 Consumer (com.intellij.util.Consumer)1