Search in sources :

Example 1 with RollbackEnvironment

use of com.intellij.openapi.vcs.rollback.RollbackEnvironment in project intellij-community by JetBrains.

the class RollbackAction method rollbackModifiedWithoutEditing.

private static void rollbackModifiedWithoutEditing(final Project project, final LinkedHashSet<VirtualFile> modifiedWithoutEditing) {
    final String operationName = StringUtil.decapitalize(UIUtil.removeMnemonic(RollbackUtil.getRollbackOperationName(project)));
    String message = (modifiedWithoutEditing.size() == 1) ? VcsBundle.message("rollback.modified.without.editing.confirm.single", operationName, modifiedWithoutEditing.iterator().next().getPresentableUrl()) : VcsBundle.message("rollback.modified.without.editing.confirm.multiple", operationName, modifiedWithoutEditing.size());
    int rc = showYesNoDialog(project, message, VcsBundle.message("changes.action.rollback.title", operationName), getQuestionIcon());
    if (rc != Messages.YES) {
        return;
    }
    final List<VcsException> exceptions = new ArrayList<>();
    final ProgressManager progressManager = ProgressManager.getInstance();
    final Runnable action = new Runnable() {

        public void run() {
            final ProgressIndicator indicator = progressManager.getProgressIndicator();
            try {
                ChangesUtil.processVirtualFilesByVcs(project, modifiedWithoutEditing, (vcs, items) -> {
                    final RollbackEnvironment rollbackEnvironment = vcs.getRollbackEnvironment();
                    if (rollbackEnvironment != null) {
                        if (indicator != null) {
                            indicator.setText(vcs.getDisplayName() + ": performing " + UIUtil.removeMnemonic(rollbackEnvironment.getRollbackOperationName()).toLowerCase() + "...");
                            indicator.setIndeterminate(false);
                        }
                        rollbackEnvironment.rollbackModifiedWithoutCheckout(items, exceptions, new RollbackProgressModifier(items.size(), indicator));
                        if (indicator != null) {
                            indicator.setText2("");
                        }
                    }
                });
            } catch (ProcessCanceledException e) {
            // for files refresh  
            }
            if (!exceptions.isEmpty()) {
                AbstractVcsHelper.getInstance(project).showErrors(exceptions, VcsBundle.message("rollback.modified.without.checkout.error.tab", operationName));
            }
            VfsUtil.markDirty(true, false, VfsUtilCore.toVirtualFileArray(modifiedWithoutEditing));
            VirtualFileManager.getInstance().asyncRefresh(new Runnable() {

                public void run() {
                    for (VirtualFile virtualFile : modifiedWithoutEditing) {
                        VcsDirtyScopeManager.getInstance(project).fileDirty(virtualFile);
                    }
                }
            });
        }
    };
    progressManager.runProcessWithProgressSynchronously(action, operationName, true, project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RollbackProgressModifier(com.intellij.openapi.vcs.changes.ui.RollbackProgressModifier) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) RollbackEnvironment(com.intellij.openapi.vcs.rollback.RollbackEnvironment) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 2 with RollbackEnvironment

use of com.intellij.openapi.vcs.rollback.RollbackEnvironment in project intellij-community by JetBrains.

the class RollbackDeletionAction method processFiles.

protected List<VcsException> processFiles(final AbstractVcs vcs, final List<FilePath> files) {
    RollbackEnvironment environment = vcs.getRollbackEnvironment();
    if (environment == null)
        return Collections.emptyList();
    final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (indicator != null) {
        indicator.setText(vcs.getDisplayName() + ": performing rollback...");
    }
    final List<VcsException> result = new ArrayList<>(0);
    try {
        environment.rollbackMissingFileDeletion(files, result, new RollbackProgressModifier(files.size(), indicator));
    } catch (ProcessCanceledException e) {
    // for files refresh
    }
    LocalFileSystem.getInstance().refreshIoFiles(ChangesUtil.filePathsToFiles(files));
    return result;
}
Also used : RollbackProgressModifier(com.intellij.openapi.vcs.changes.ui.RollbackProgressModifier) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) ArrayList(java.util.ArrayList) RollbackEnvironment(com.intellij.openapi.vcs.rollback.RollbackEnvironment) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 3 with RollbackEnvironment

use of com.intellij.openapi.vcs.rollback.RollbackEnvironment in project intellij-community by JetBrains.

the class VcsFileStatusProvider method refreshFileStatusFromDocument.

@Override
public void refreshFileStatusFromDocument(@NotNull final VirtualFile virtualFile, @NotNull final Document doc) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("refreshFileStatusFromDocument: file.getModificationStamp()=" + virtualFile.getModificationStamp() + ", document.getModificationStamp()=" + doc.getModificationStamp());
    }
    FileStatus cachedStatus = myFileStatusManager.getCachedStatus(virtualFile);
    if (cachedStatus == null || cachedStatus == FileStatus.NOT_CHANGED || !isDocumentModified(virtualFile)) {
        final AbstractVcs vcs = myVcsManager.getVcsFor(virtualFile);
        if (vcs == null)
            return;
        if (cachedStatus == FileStatus.MODIFIED && !isDocumentModified(virtualFile)) {
            if (!((ReadonlyStatusHandlerImpl) ReadonlyStatusHandlerImpl.getInstance(myProject)).getState().SHOW_DIALOG) {
                RollbackEnvironment rollbackEnvironment = vcs.getRollbackEnvironment();
                if (rollbackEnvironment != null) {
                    rollbackEnvironment.rollbackIfUnchanged(virtualFile);
                }
            }
        }
        myFileStatusManager.fileStatusChanged(virtualFile);
        ChangeProvider cp = vcs.getChangeProvider();
        if (cp != null && cp.isModifiedDocumentTrackingRequired()) {
            myDirtyScopeManager.fileDirty(virtualFile);
        }
    }
}
Also used : ReadonlyStatusHandlerImpl(com.intellij.openapi.vcs.readOnlyHandler.ReadonlyStatusHandlerImpl) RollbackEnvironment(com.intellij.openapi.vcs.rollback.RollbackEnvironment)

Aggregations

RollbackEnvironment (com.intellij.openapi.vcs.rollback.RollbackEnvironment)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 RollbackProgressModifier (com.intellij.openapi.vcs.changes.ui.RollbackProgressModifier)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 VcsException (com.intellij.openapi.vcs.VcsException)1 ReadonlyStatusHandlerImpl (com.intellij.openapi.vcs.readOnlyHandler.ReadonlyStatusHandlerImpl)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArrayList (java.util.ArrayList)1