mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-67609 VCS Create patch has only *.patch extension as default one
Remember what standard extension - patch or diff - was last used. Check that file doesn't exist - before patch creation
This commit is contained in:
@@ -28,6 +28,8 @@ import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.util.DefaultJDOMExternalizer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -54,6 +56,10 @@ public final class VcsConfiguration implements PersistentStateComponent<Element>
|
||||
@NonNls private static final String VALUE_ATTR = "value";
|
||||
@NonNls private static final String CONFIRM_MOVE_TO_FAILED_COMMIT_ELEMENT = "confirmMoveToFailedCommit";
|
||||
@NonNls private static final String CONFIRM_REMOVE_EMPTY_CHANGELIST_ELEMENT = "confirmRemoveEmptyChangelist";
|
||||
|
||||
@NonNls public static final String PATCH = "patch";
|
||||
@NonNls public static final String DIFF = "diff";
|
||||
|
||||
private Project myProject;
|
||||
|
||||
public boolean OFFER_MOVE_TO_ANOTHER_CHANGELIST_ON_PARTIAL_COMMIT = true;
|
||||
@@ -73,6 +79,7 @@ public final class VcsConfiguration implements PersistentStateComponent<Element>
|
||||
public int CHANGED_ON_SERVER_INTERVAL = 60;
|
||||
public boolean SHOW_ONLY_CHANGED_IN_SELECTION_DIFF = true;
|
||||
public boolean CHECK_COMMIT_MESSAGE_SPELLING = true;
|
||||
public String DEFAULT_PATCH_EXTENSION = PATCH;
|
||||
|
||||
public enum StandardOption {
|
||||
ADD(VcsBundle.message("vcs.command.name.add")),
|
||||
@@ -346,4 +353,17 @@ public final class VcsConfiguration implements PersistentStateComponent<Element>
|
||||
|
||||
}
|
||||
|
||||
public String getPatchFileExtension() {
|
||||
return DEFAULT_PATCH_EXTENSION;
|
||||
}
|
||||
|
||||
public void acceptLastCreatedPatchName(final String string) {
|
||||
if (StringUtil.isEmptyOrSpaces(string)) return;
|
||||
final String extension = FileUtil.getExtension(string);
|
||||
if (DIFF.equalsIgnoreCase(extension)) {
|
||||
DEFAULT_PATCH_EXTENSION = DIFF;
|
||||
} else if (PATCH.equalsIgnoreCase(extension)) {
|
||||
DEFAULT_PATCH_EXTENSION = PATCH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -29,6 +29,7 @@ import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.JDOMExternalizable;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.vcs.VcsBundle;
|
||||
import com.intellij.openapi.vcs.VcsConfiguration;
|
||||
import com.intellij.openapi.vcs.changes.*;
|
||||
import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager;
|
||||
import com.intellij.util.WaitForProgressToShow;
|
||||
@@ -118,7 +119,7 @@ public class CreatePatchCommitExecutor implements CommitExecutorWithHelp, Projec
|
||||
if (PATCH_PATH.length() == 0) {
|
||||
PATCH_PATH = myProject.getBaseDir().getPresentableUrl();
|
||||
}
|
||||
myPanel.setFileName(ShelveChangesManager.suggestPatchName(commitMessage, new File(PATCH_PATH)));
|
||||
myPanel.setFileName(ShelveChangesManager.suggestPatchName(myProject, commitMessage, new File(PATCH_PATH), null));
|
||||
myPanel.setReversePatch(REVERSE_PATCH);
|
||||
return myPanel.getPanel();
|
||||
}
|
||||
@@ -150,6 +151,7 @@ public class CreatePatchCommitExecutor implements CommitExecutorWithHelp, Projec
|
||||
try {
|
||||
final String fileName = myPanel.getFileName();
|
||||
final File file = new File(fileName).getAbsoluteFile();
|
||||
VcsConfiguration.getInstance(myProject).acceptLastCreatedPatchName(file.getName());
|
||||
PATCH_PATH = file.getParent();
|
||||
REVERSE_PATCH = myPanel.isReversePatch();
|
||||
|
||||
|
||||
+1
-1
@@ -141,7 +141,7 @@ public class CreatePatchConfigurationPanel {
|
||||
}
|
||||
|
||||
public boolean isOkToExecute() {
|
||||
return myErrorLabel.getText() == null || myErrorLabel.getText().length() == 0;
|
||||
return myErrorLabel.getText() == null || myErrorLabel.getText().length() == 0;
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
|
||||
@@ -21,8 +21,10 @@ public class PatchNameChecker {
|
||||
public final static int MAX = 100;
|
||||
private final String myName;
|
||||
private String myError;
|
||||
private final String myPath;
|
||||
|
||||
public PatchNameChecker(final String name) {
|
||||
myPath = name;
|
||||
myName = new File(name).getName();
|
||||
}
|
||||
|
||||
@@ -33,6 +35,9 @@ public class PatchNameChecker {
|
||||
} else if (myName.length() > MAX) {
|
||||
myError = "File name length cannot exceed " + MAX + " characters";
|
||||
return false;
|
||||
} else if (new File(myPath).exists()) {
|
||||
myError = "File with the same name already exists";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
+6
-10
@@ -37,10 +37,7 @@ import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.FilePathImpl;
|
||||
import com.intellij.openapi.vcs.VcsBundle;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.*;
|
||||
import com.intellij.openapi.vcs.changes.*;
|
||||
import com.intellij.openapi.vcs.changes.patch.PatchNameChecker;
|
||||
import com.intellij.openapi.vcs.changes.ui.RollbackWorker;
|
||||
@@ -65,8 +62,6 @@ import java.util.*;
|
||||
public class ShelveChangesManager implements ProjectComponent, JDOMExternalizable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager");
|
||||
|
||||
@NonNls private static final String PATCH_EXTENSION = "patch";
|
||||
|
||||
public static ShelveChangesManager getInstance(Project project) {
|
||||
return PeriodicalTasksCloser.getInstance().safeGetComponent(project, ShelveChangesManager.class);
|
||||
}
|
||||
@@ -286,16 +281,17 @@ public class ShelveChangesManager implements ProjectComponent, JDOMExternalizabl
|
||||
file.mkdirs();
|
||||
}
|
||||
|
||||
return suggestPatchName(commitMessage.length() > PatchNameChecker.MAX ? (commitMessage.substring(0, PatchNameChecker.MAX)) :
|
||||
commitMessage, file);
|
||||
return suggestPatchName(myProject, commitMessage.length() > PatchNameChecker.MAX ? (commitMessage.substring(0, PatchNameChecker.MAX)) :
|
||||
commitMessage, file, VcsConfiguration.PATCH);
|
||||
}
|
||||
|
||||
public static File suggestPatchName(final String commitMessage, final File file) {
|
||||
public static File suggestPatchName(Project project, final String commitMessage, final File file, String extension) {
|
||||
@NonNls String defaultPath = PathUtil.suggestFileName(commitMessage);
|
||||
if (defaultPath.length() == 0) {
|
||||
defaultPath = "unnamed";
|
||||
}
|
||||
return FileUtil.findSequentNonexistentFile(file, defaultPath, PATCH_EXTENSION);
|
||||
return FileUtil.findSequentNonexistentFile(file, defaultPath,
|
||||
extension == null ? VcsConfiguration.getInstance(project).getPatchFileExtension() : extension);
|
||||
}
|
||||
|
||||
public void unshelveChangeList(final ShelvedChangeList changeList, @Nullable final List<ShelvedChange> changes,
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.openapi.vcs.impl;
|
||||
|
||||
import com.intellij.openapi.fileTypes.FileTypeFactory;
|
||||
import com.intellij.openapi.fileTypes.FileTypeConsumer;
|
||||
import com.intellij.openapi.vcs.VcsConfiguration;
|
||||
import com.intellij.openapi.vcs.changes.patch.PatchFileType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -25,6 +26,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class VcsFileTypeFactory extends FileTypeFactory {
|
||||
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
|
||||
consumer.consume(new PatchFileType(), "patch;diff");
|
||||
consumer.consume(new PatchFileType(), VcsConfiguration.PATCH + ";" + VcsConfiguration.DIFF);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user