IDEA-69174 User should be able to save patch to existing file.

This commit is contained in:
irengrig
2012-07-27 18:21:09 +04:00
parent cb9c422e20
commit 808b7d8cf7
3 changed files with 34 additions and 5 deletions
@@ -36,6 +36,7 @@ import com.intellij.openapi.vcs.*;
import com.intellij.openapi.vcs.changes.*;
import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager;
import com.intellij.util.WaitForProgressToShow;
import com.intellij.util.ui.UIUtil;
import org.jdom.Element;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
@@ -161,9 +162,28 @@ public class CreatePatchCommitExecutor extends LocalCommitExecutor implements Pr
public void execute(Collection<Change> changes, String commitMessage) {
if (! myPanel.isOkToExecute()) {
Messages.showErrorDialog(myProject, VcsBundle.message("create.patch.error.title", myPanel.getError()), CommonBundle.getErrorTitle());
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
Messages
.showErrorDialog(myProject, VcsBundle.message("create.patch.error.title", myPanel.getError()), CommonBundle.getErrorTitle());
}
});
return;
}
final String fileName = myPanel.getFileName();
final File file = new File(fileName).getAbsoluteFile();
if (file.exists()) {
final int[] result = new int[1];
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
result[0] = Messages.showYesNoDialog(myProject, "File " + file.getName() + " (" + file.getParent() + ")" +
" already exists.\nDo you want to overwrite it?", CommonBundle.getWarningTitle(), Messages.getWarningIcon());
}
});
if (Messages.NO == result[0]) return;
}
myPanel.onOk();
myCommitContext.putUserData(BaseRevisionTextPatchEP.ourPutBaseRevisionTextKey, myPanel.isStoreTexts());
final List<FilePath> list = new ArrayList<FilePath>();
@@ -188,8 +208,6 @@ public class CreatePatchCommitExecutor extends LocalCommitExecutor implements Pr
return;
}
try {
final String fileName = myPanel.getFileName();
final File file = new File(fileName).getAbsoluteFile();
VcsConfiguration.getInstance(myProject).acceptLastCreatedPatchName(file.getName());
PATCH_PATH = file.getParent();
final boolean reversePatch = myPanel.isReversePatch();
@@ -71,6 +71,7 @@ public class CreatePatchConfigurationPanel {
private SelectFilesToAddTextsToPatchPanel mySelectFilesToAddTextsToPatchPanel;
private HideableTitledPanel myHideableTitledPanel;
private JPanel myPanelWithSelectedFiles;
private boolean myExecute;
public CreatePatchConfigurationPanel(final Project project) {
myProject = project;
@@ -212,8 +213,9 @@ public class CreatePatchConfigurationPanel {
else {
myErrorLabel.setText(patchNameChecker.getError());
}
myExecute = patchNameChecker.nameOk() || !patchNameChecker.isPreventsOk();
if (myOkEnabledListener != null) {
myOkEnabledListener.consume(patchNameChecker.nameOk());
myOkEnabledListener.consume(myExecute);
}
}
@@ -258,7 +260,7 @@ public class CreatePatchConfigurationPanel {
}
public boolean isOkToExecute() {
return myErrorLabel.getText() == null || myErrorLabel.getText().length() == 0;
return myExecute;
}
public String getError() {
@@ -20,28 +20,37 @@ import java.io.File;
public class PatchNameChecker {
public final static int MAX = 100;
private final String myName;
private boolean myPreventsOk;
private String myError;
private final String myPath;
public PatchNameChecker(final String name) {
myPath = name;
myName = new File(name).getName();
myPreventsOk = false;
}
public boolean nameOk() {
if (myName == null || myName.length() == 0) {
myError = "File name cannot be empty";
myPreventsOk = true;
return false;
} else if (myName.length() > MAX) {
myError = "File name length cannot exceed " + MAX + " characters";
myPreventsOk = true;
return false;
} else if (new File(myPath).exists()) {
myError = "File with the same name already exists";
myPreventsOk = false;
return false;
}
return true;
}
public boolean isPreventsOk() {
return myPreventsOk;
}
public String getError() {
return myError;
}