diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java index 6546f40d7bd2..30a95e5d9d35 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java @@ -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 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 list = new ArrayList(); @@ -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(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.java index 72ed7cb91557..0c9aa4e11379 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.java @@ -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() { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchNameChecker.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchNameChecker.java index a4263be19c96..935747ecfe84 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchNameChecker.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/PatchNameChecker.java @@ -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; }