From eb3d45c769008bab1237e5bba8d4b9ddb25d6dcd Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 15 Nov 2010 12:06:50 +0300 Subject: [PATCH] IDEA-51182: GitRevert now shows the common confirmation dialog for revert. --- .../src/git4idea/actions/GitRevert.java | 70 +++---------------- 1 file changed, 10 insertions(+), 60 deletions(-) diff --git a/plugins/git4idea/src/git4idea/actions/GitRevert.java b/plugins/git4idea/src/git4idea/actions/GitRevert.java index 2ff27828898b..6661eb396326 100644 --- a/plugins/git4idea/src/git4idea/actions/GitRevert.java +++ b/plugins/git4idea/src/git4idea/actions/GitRevert.java @@ -15,87 +15,37 @@ */ package git4idea.actions; -import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.FileStatus; import com.intellij.openapi.vcs.FileStatusManager; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.changes.ChangeListManager; -import com.intellij.openapi.vcs.changes.ContentRevision; -import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; -import com.intellij.openapi.vcs.rollback.RollbackProgressListener; +import com.intellij.openapi.vcs.changes.ui.RollbackChangesDialog; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.Consumer; -import git4idea.GitUtil; import git4idea.GitVcs; import git4idea.i18n.GitBundle; -import git4idea.rollback.GitRollbackEnvironment; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; /** * Git "revert" action */ public class GitRevert extends BasicAction { - /** - * {@inheritDoc} - */ + @Override - public boolean perform(@NotNull final Project project, - GitVcs vcs, - @NotNull final List exceptions, - @NotNull VirtualFile[] affectedFiles) { - saveAll(); - final ChangeListManager changeManager = ChangeListManager.getInstance(project); - final List changes = new ArrayList(); - final HashSet files = new HashSet(); - try { - for (VirtualFile f : affectedFiles) { - Change ch = changeManager.getChange(f); - if (ch != null) { - files.add(GitUtil.getGitRoot(f)); - changes.add(ch); - } + public boolean perform(@NotNull final Project project, GitVcs vcs, @NotNull final List exceptions, @NotNull VirtualFile[] affectedFiles) { + final List changes = new ArrayList(affectedFiles.length); + for (VirtualFile f : affectedFiles) { + Change ch = ChangeListManager.getInstance(project).getChange(f); + if (ch != null) { + changes.add(ch); } } - catch (VcsException ex) { - exceptions.add(ex); - return true; - } - return toBackground(project, vcs, affectedFiles, exceptions, new Consumer() { - public void consume(ProgressIndicator pi) { - pi.setIndeterminate(true); - GitRollbackEnvironment re = GitRollbackEnvironment.getInstance(project); - re.rollbackChanges(changes, exceptions, RollbackProgressListener.EMPTY); - if (changes.size() == 1) { - Change c = changes.get(0); - ContentRevision r = c.getAfterRevision(); - if (r == null) { - r = c.getBeforeRevision(); - assert r != null; - } - pi.setText2(r.getFile().getPath()); - } - else { - pi.setText2(GitBundle.message("revert.reverting.mulitple", changes.size())); - } - final VcsDirtyScopeManager mgr = VcsDirtyScopeManager.getInstance(project); - for (Change c : changes) { - ContentRevision before = c.getBeforeRevision(); - if (before != null) { - mgr.fileDirty(before.getFile()); - } - ContentRevision after = c.getAfterRevision(); - if (after != null) { - mgr.fileDirty(after.getFile()); - } - } - } - }); + RollbackChangesDialog.rollbackChanges(project, changes); + return false; } @Override