mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-51182: GitRevert now shows the common confirmation dialog for revert.
This commit is contained in:
@@ -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<VcsException> exceptions,
|
||||
@NotNull VirtualFile[] affectedFiles) {
|
||||
saveAll();
|
||||
final ChangeListManager changeManager = ChangeListManager.getInstance(project);
|
||||
final List<Change> changes = new ArrayList<Change>();
|
||||
final HashSet<VirtualFile> files = new HashSet<VirtualFile>();
|
||||
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<VcsException> exceptions, @NotNull VirtualFile[] affectedFiles) {
|
||||
final List<Change> changes = new ArrayList<Change>(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<ProgressIndicator>() {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user