mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
create file from template action supports separators in file path (WEB-6260)
This commit is contained in:
@@ -74,18 +74,30 @@ public class CreateFileAction extends CreateElementActionBase implements DumbAwa
|
||||
|
||||
@NotNull
|
||||
protected PsiElement[] create(String newName, PsiDirectory directory) throws Exception {
|
||||
if (SystemInfo.isWindows) {
|
||||
newName = newName.replace('\\', '/');
|
||||
}
|
||||
if (newName.contains("/")) {
|
||||
final List<String> subDirs = StringUtil.split(newName, "/");
|
||||
newName = subDirs.remove(subDirs.size() - 1);
|
||||
for (String dir : subDirs) {
|
||||
final PsiDirectory sub = directory.findSubdirectory(dir);
|
||||
directory = sub == null ? directory.createSubdirectory(dir) : sub;
|
||||
MkDirs mkdirs = new MkDirs(newName, directory);
|
||||
return new PsiElement[]{mkdirs.directory.createFile(getFileName(mkdirs.newName))};
|
||||
}
|
||||
|
||||
public static class MkDirs {
|
||||
public final String newName;
|
||||
public final PsiDirectory directory;
|
||||
|
||||
public MkDirs(String newName, PsiDirectory directory) {
|
||||
if (SystemInfo.isWindows) {
|
||||
newName = newName.replace('\\', '/');
|
||||
}
|
||||
if (newName.contains("/")) {
|
||||
final List<String> subDirs = StringUtil.split(newName, "/");
|
||||
newName = subDirs.remove(subDirs.size() - 1);
|
||||
for (String dir : subDirs) {
|
||||
final PsiDirectory sub = directory.findSubdirectory(dir);
|
||||
directory = sub == null ? directory.createSubdirectory(dir) : sub;
|
||||
}
|
||||
}
|
||||
|
||||
this.newName = newName;
|
||||
this.directory = directory;
|
||||
}
|
||||
return new PsiElement[]{directory.createFile(getFileName(newName))};
|
||||
}
|
||||
|
||||
protected String getActionName(PsiDirectory directory, String newName) {
|
||||
|
||||
@@ -52,6 +52,9 @@ public abstract class CreateFileFromTemplateAction extends CreateFromTemplateAct
|
||||
@NotNull FileTemplate template,
|
||||
@NotNull PsiDirectory dir,
|
||||
@Nullable String defaultTemplateProperty) {
|
||||
CreateFileAction.MkDirs mkdirs = new CreateFileAction.MkDirs(name, dir);
|
||||
name = mkdirs.newName;
|
||||
dir = mkdirs.directory;
|
||||
PsiElement element;
|
||||
Project project = dir.getProject();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user