fix(gui): trim trailing spaces in input files (#2244)

This commit is contained in:
Skylot
2024-08-10 00:31:25 +01:00
parent 280f3870a9
commit 015876b790
3 changed files with 16 additions and 4 deletions
@@ -343,6 +343,18 @@ public class FileUtils {
return Stream.of(files).map(File::toPath).collect(Collectors.toList());
}
public static List<Path> toPathsWithTrim(File[] files) {
return Stream.of(files).map(FileUtils::toPathWithTrim).collect(Collectors.toList());
}
public static Path toPathWithTrim(File file) {
return Path.of(file.getPath().stripTrailing());
}
public static Path toPathWithTrim(String file) {
return Path.of(file.stripTrailing());
}
public static List<Path> fileNamesToPaths(List<String> fileNames) {
return fileNames.stream().map(Paths::get).collect(Collectors.toList());
}
@@ -56,11 +56,11 @@ class CustomFileChooser extends JFileChooser {
data.setCurrentDir(getCurrentDirectory().toPath());
File[] selectedFiles = getSelectedFiles();
if (selectedFiles.length != 0) {
return FileUtils.toPaths(selectedFiles);
return FileUtils.toPathsWithTrim(selectedFiles);
}
File chosenFile = getSelectedFile();
if (chosenFile != null) {
return Collections.singletonList(chosenFile.toPath());
return Collections.singletonList(FileUtils.toPathWithTrim(chosenFile));
}
return Collections.emptyList();
}
@@ -37,10 +37,10 @@ class CustomFileDialog {
File[] selectedFiles = fileDialog.getFiles();
if (!Utils.isEmpty(selectedFiles)) {
data.setCurrentDir(Paths.get(fileDialog.getDirectory()));
return FileUtils.toPaths(selectedFiles);
return FileUtils.toPathsWithTrim(selectedFiles);
}
if (fileDialog.getFile() != null) {
return Collections.singletonList(Paths.get(fileDialog.getFile()));
return Collections.singletonList(FileUtils.toPathWithTrim(fileDialog.getFile()));
}
return Collections.emptyList();
}