提交 bafc6e8b 编写于 作者: R rupashka

6351074: JFileChooser removes leading space in filename

Summary: Removed trimming of leading spaces in filename
Reviewed-by: alexp
上级 363ab66c
......@@ -36,6 +36,7 @@ import java.awt.datatransfer.*;
import java.beans.*;
import java.io.*;
import java.util.*;
import java.util.List;
import java.util.regex.*;
import sun.awt.shell.ShellFolder;
import sun.swing.*;
......@@ -829,11 +830,17 @@ public class BasicFileChooserUI extends FileChooserUI {
File dir = chooser.getCurrentDirectory();
if (filename != null) {
// Remove whitespace from beginning and end of filename
filename = filename.trim();
// Remove whitespaces from end of filename
int i = filename.length() - 1;
while (i >=0 && filename.charAt(i) <= ' ') {
i--;
}
filename = filename.substring(0, i + 1);
}
if (filename == null || filename.equals("")) {
if (filename == null || filename.length() == 0) {
// no file selected, multiple selection off, therefore cancel the approve action
resetGlobFilter();
return;
......@@ -842,7 +849,6 @@ public class BasicFileChooserUI extends FileChooserUI {
File selectedFile = null;
File[] selectedFiles = null;
if (filename != null && !filename.equals("")) {
// Unix: Resolve '~' to user's home directory
if (File.separatorChar == '/') {
if (filename.startsWith("~/")) {
......@@ -852,25 +858,18 @@ public class BasicFileChooserUI extends FileChooserUI {
}
}
if (chooser.isMultiSelectionEnabled() && filename.startsWith("\"")) {
ArrayList<File> fList = new ArrayList<File>();
if (chooser.isMultiSelectionEnabled() && filename.length() > 1 &&
filename.charAt(0) == '"' && filename.charAt(filename.length() - 1) == '"') {
List<File> fList = new ArrayList<File>();
String[] files = filename.substring(1, filename.length() - 1).split("\" \"");
// Optimize searching files by names in "children" array
Arrays.sort(files);
filename = filename.substring(1);
if (filename.endsWith("\"")) {
filename = filename.substring(0, filename.length()-1);
}
File[] children = null;
int childIndex = 0;
do {
String str;
int i = filename.indexOf("\" \"");
if (i > 0) {
str = filename.substring(0, i);
filename = filename.substring(i+3);
} else {
str = filename;
filename = "";
}
for (String str : files) {
File file = fs.createFileObject(str);
if (!file.isAbsolute()) {
if (children == null) {
......@@ -887,14 +886,15 @@ public class BasicFileChooserUI extends FileChooserUI {
}
}
fList.add(file);
} while (filename.length() > 0);
if (fList.size() > 0) {
}
if (!fList.isEmpty()) {
selectedFiles = fList.toArray(new File[fList.size()]);
}
resetGlobFilter();
} else {
selectedFile = fs.createFileObject(filename);
if(!selectedFile.isAbsolute()) {
if (!selectedFile.isAbsolute()) {
selectedFile = fs.getChild(dir, filename);
}
// check for wildcard pattern
......@@ -935,7 +935,7 @@ public class BasicFileChooserUI extends FileChooserUI {
selectedFile = null;
}
}
}
if (selectedFiles != null || selectedFile != null) {
if (selectedFiles != null || chooser.isMultiSelectionEnabled()) {
if (selectedFiles == null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册