[patch]: rollback dialog should inform user about binaries if needed

This commit is contained in:
Nadya Zabrodina
2016-01-25 17:05:21 +03:00
parent 9f3fa47ab7
commit e977efb6bb
2 changed files with 25 additions and 5 deletions
@@ -29,6 +29,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vcs.*;
@@ -306,6 +307,12 @@ public class PatchApplier<BinaryType extends FilePatch> {
return applier.getFailedPatches();
}
});
boolean shouldInformAboutBinaries = ContainerUtil.exists(group, new Condition<PatchApplier>() {
@Override
public boolean value(PatchApplier applier) {
return !applier.getBinaryPatches().isEmpty();
}
});
UndoApplyPatchDialog.rollbackApplyPatch(project, ContainerUtil.map(allFailed, new Function<FilePatch, FilePath>() {
@Override
public FilePath fun(FilePatch filePatch) {
@@ -315,7 +322,7 @@ public class PatchApplier<BinaryType extends FilePatch> {
: filePatch.getAfterName();
return VcsUtil.getFilePath(path);
}
}), beforeLabel);
}), beforeLabel, shouldInformAboutBinaries);
}
protected void addSkippedItems(final TriggerAdditionOrDeletion trigger) {
@@ -23,6 +23,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.changes.ui.FilePathChangesTreeList;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -36,14 +37,19 @@ class UndoApplyPatchDialog extends DialogWrapper {
private final List<FilePath> myFailedFilePaths;
private final Label myBeforeLabel;
private final Project myProject;
private final boolean myShouldInformAboutBinaries;
private UndoApplyPatchDialog(@NotNull Project project, @NotNull List<FilePath> filePaths, @NotNull Label beforeLabel) {
private UndoApplyPatchDialog(@NotNull Project project,
@NotNull List<FilePath> filePaths,
@NotNull Label beforeLabel,
boolean shouldInformAboutBinaries) {
super(project, true);
myProject = project;
setTitle("Patch Applying Partly Failed");
setOKButtonText("Rollback");
myFailedFilePaths = filePaths;
myBeforeLabel = beforeLabel;
myShouldInformAboutBinaries = shouldInformAboutBinaries;
init();
}
@@ -52,9 +58,16 @@ class UndoApplyPatchDialog extends DialogWrapper {
protected JComponent createCenterPanel() {
final JPanel panel = new JPanel(new BorderLayout());
int numFiles = myFailedFilePaths.size();
JPanel labelsPanel = new JPanel(new BorderLayout());
String detailedText = numFiles == 0 ? "" : String.format("Failed to apply %s below. ", StringUtil.pluralize("file", numFiles));
final JLabel infoLabel = new JBLabel(detailedText + "Would you like to rollback all applied?");
panel.add(infoLabel, BorderLayout.NORTH);
labelsPanel.add(infoLabel, BorderLayout.NORTH);
if (myShouldInformAboutBinaries) {
JLabel warningLabel = new JLabel("Rollback doesn't affect binaries");
warningLabel.setIcon(UIUtil.getBalloonWarningIcon());
labelsPanel.add(warningLabel, BorderLayout.CENTER);
}
panel.add(labelsPanel, BorderLayout.NORTH);
if (numFiles > 0) {
FilePathChangesTreeList browser = new FilePathChangesTreeList(myProject, myFailedFilePaths, false, false, null, null) {
@Override
@@ -80,7 +93,7 @@ class UndoApplyPatchDialog extends DialogWrapper {
}
static void rollbackApplyPatch(@NotNull Project project, @NotNull List<FilePath> filePaths,
@NotNull Label historyLabel) {
new UndoApplyPatchDialog(project, filePaths, historyLabel).show();
@NotNull Label historyLabel, boolean shouldInformAboutBinaries) {
new UndoApplyPatchDialog(project, filePaths, historyLabel, shouldInformAboutBinaries).show();
}
}