mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-136862 (Creating new files in HOME directory: ~/tmp/foo.py should work)
This commit is contained in:
+12
-2
@@ -30,6 +30,7 @@ import com.intellij.openapi.ui.InputValidatorEx;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiFileSystemItem;
|
||||
@@ -75,7 +76,7 @@ public class CreateDirectoryOrPackageHandler implements InputValidatorEx {
|
||||
public boolean checkInput(String inputString) {
|
||||
final StringTokenizer tokenizer = new StringTokenizer(inputString, myDelimiters);
|
||||
VirtualFile vFile = myDirectory.getVirtualFile();
|
||||
|
||||
boolean firstToken = true;
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
final String token = tokenizer.nextToken();
|
||||
if (!tokenizer.hasMoreTokens() && (token.equals(".") || token.equals(".."))) {
|
||||
@@ -83,7 +84,15 @@ public class CreateDirectoryOrPackageHandler implements InputValidatorEx {
|
||||
return false;
|
||||
}
|
||||
if (vFile != null) {
|
||||
if ("..".equals(token)) {
|
||||
if (firstToken && "~".equals(token)) {
|
||||
final VirtualFile userHomeDir = VfsUtil.getUserHomeDir();
|
||||
if (userHomeDir == null) {
|
||||
myErrorText = "User home directory not found";
|
||||
return false;
|
||||
}
|
||||
vFile = userHomeDir;
|
||||
}
|
||||
else if ("..".equals(token)) {
|
||||
vFile = vFile.getParent();
|
||||
if (vFile == null) {
|
||||
myErrorText = "Not a valid directory";
|
||||
@@ -114,6 +123,7 @@ public class CreateDirectoryOrPackageHandler implements InputValidatorEx {
|
||||
myErrorText = "Not a valid package name, it will not be possible to create a class inside";
|
||||
return true;
|
||||
}
|
||||
firstToken = false;
|
||||
}
|
||||
myErrorText = null;
|
||||
return true;
|
||||
|
||||
@@ -30,10 +30,12 @@ import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -95,8 +97,16 @@ public class CreateFileAction extends CreateElementActionBase implements DumbAwa
|
||||
if (newName.contains("/")) {
|
||||
final List<String> subDirs = StringUtil.split(newName, "/");
|
||||
newName = subDirs.remove(subDirs.size() - 1);
|
||||
boolean firstToken = true;
|
||||
for (String dir : subDirs) {
|
||||
if ("..".equals(dir)) {
|
||||
if (firstToken && "~".equals(dir)) {
|
||||
final VirtualFile userHomeDir = VfsUtil.getUserHomeDir();
|
||||
if (userHomeDir == null) throw new IncorrectOperationException("User home directory not found");
|
||||
final PsiDirectory directory1 = directory.getManager().findDirectory(userHomeDir);
|
||||
if (directory1 == null) throw new IncorrectOperationException("User home directory not found");
|
||||
directory = directory1;
|
||||
}
|
||||
else if ("..".equals(dir)) {
|
||||
final PsiDirectory parentDirectory = directory.getParentDirectory();
|
||||
if (parentDirectory == null) throw new IncorrectOperationException("Not a valid directory");
|
||||
directory = parentDirectory;
|
||||
@@ -105,6 +115,7 @@ public class CreateFileAction extends CreateElementActionBase implements DumbAwa
|
||||
final PsiDirectory sub = directory.findSubdirectory(dir);
|
||||
directory = sub == null ? directory.createSubdirectory(dir) : sub;
|
||||
}
|
||||
firstToken = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +162,7 @@ public class CreateFileAction extends CreateElementActionBase implements DumbAwa
|
||||
public boolean checkInput(String inputString) {
|
||||
final StringTokenizer tokenizer = new StringTokenizer(inputString, "\\/");
|
||||
VirtualFile vFile = getDirectory().getVirtualFile();
|
||||
boolean firstToken = true;
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
final String token = tokenizer.nextToken();
|
||||
if ((token.equals(".") || token.equals("..")) && !tokenizer.hasMoreTokens()) {
|
||||
@@ -158,7 +170,15 @@ public class CreateFileAction extends CreateElementActionBase implements DumbAwa
|
||||
return false;
|
||||
}
|
||||
if (vFile != null) {
|
||||
if ("..".equals(token)) {
|
||||
if (firstToken && "~".equals(token)) {
|
||||
final VirtualFile userHomeDir = VfsUtil.getUserHomeDir();
|
||||
if (userHomeDir == null) {
|
||||
myErrorText = "User home directory not found";
|
||||
return false;
|
||||
}
|
||||
vFile = userHomeDir;
|
||||
}
|
||||
else if ("..".equals(token)) {
|
||||
vFile = vFile.getParent();
|
||||
if (vFile == null) {
|
||||
myErrorText = "Not a valid directory";
|
||||
@@ -184,6 +204,7 @@ public class CreateFileAction extends CreateElementActionBase implements DumbAwa
|
||||
myErrorText = "'" + token + "' is an ignored name (Settings | Editor | File Types | Ignore files and folders)";
|
||||
return true;
|
||||
}
|
||||
firstToken = false;
|
||||
}
|
||||
myErrorText = null;
|
||||
return true;
|
||||
|
||||
@@ -19,10 +19,12 @@ package com.intellij.ide.util;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.StringTokenizer;
|
||||
@@ -96,10 +98,19 @@ public class DirectoryUtil {
|
||||
public static PsiDirectory createSubdirectories(final String subDirName, PsiDirectory baseDirectory, final String delim) throws IncorrectOperationException {
|
||||
StringTokenizer tokenizer = new StringTokenizer(subDirName, delim);
|
||||
PsiDirectory dir = baseDirectory;
|
||||
boolean firstToken = true;
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String dirName = tokenizer.nextToken();
|
||||
if (tokenizer.hasMoreTokens()) {
|
||||
if ("..".equals(dirName)) {
|
||||
if (firstToken && "~".equals(dirName)) {
|
||||
final VirtualFile userHomeDir = VfsUtil.getUserHomeDir();
|
||||
if (userHomeDir == null) throw new IncorrectOperationException("User home directory not found");
|
||||
final PsiDirectory directory1 = baseDirectory.getManager().findDirectory(userHomeDir);
|
||||
if (directory1 == null) throw new IncorrectOperationException("User home directory not found");
|
||||
dir = directory1;
|
||||
continue;
|
||||
}
|
||||
else if ("..".equals(dirName)) {
|
||||
dir = dir.getParentDirectory();
|
||||
if (dir == null) throw new IncorrectOperationException("Not a valid directory");
|
||||
continue;
|
||||
@@ -114,6 +125,7 @@ public class DirectoryUtil {
|
||||
}
|
||||
}
|
||||
dir = dir.createSubdirectory(dirName);
|
||||
firstToken = false;
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user