IDEA-94641 Save Project As Template: impossible to overwrite the existing template

This commit is contained in:
Dmitry Avdeev
2013-02-07 15:08:48 +04:00
parent 9cd2ca74fa
commit 8bf32e5f49
@@ -21,7 +21,9 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
@@ -113,8 +115,22 @@ public class SaveProjectAsTemplateDialog extends DialogWrapper {
if (StringUtil.isEmpty(myName.getText())) {
return new ValidationInfo("Template name should not be empty");
}
return null;
}
@Override
protected void doOKAction() {
File file = getTemplateFile();
return file.exists() ? new ValidationInfo("Template already exists") : null;
if (file.exists()) {
if (Messages.showYesNoDialog(myPanel,
FileUtil.getNameWithoutExtension(file) + " exists already.\n" +
"Do you want to replace it with the new one?", "Template Already Exists",
Messages.getWarningIcon()) == Messages.NO) {
return;
}
file.delete();
}
super.doOKAction();
}
File getTemplateFile() {