-
Notifications
You must be signed in to change notification settings - Fork 922
优化投影管理文件夹已存在提示 #6664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
优化投影管理文件夹已存在提示 #6664
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,7 @@ | |
| import java.nio.file.NoSuchFileException; | ||
| import java.nio.file.Path; | ||
| import java.util.*; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.jackhuang.hmcl.ui.FXUtils.onEscPressed; | ||
|
|
@@ -161,10 +162,25 @@ public void onCreateDirectory() { | |
| return; | ||
|
|
||
| Path parent = currentDirectory.path; | ||
|
|
||
| Set<String> existingFolders; | ||
|
|
||
| try (var list = Files.list(parent)) { | ||
| existingFolders = list.map(Path::getFileName) | ||
| .map(Path::toString) | ||
| .collect(Collectors.toSet()); | ||
| } catch (IOException e) { | ||
| LOG.warning("Failed to list folders in " + parent, e); | ||
| existingFolders = Set.of(); | ||
| } | ||
|
|
||
| Set<String> finalExistingFolders = existingFolders; | ||
|
|
||
| Controllers.prompt( | ||
| i18n("schematics.create_directory.prompt"), | ||
| (result, handler) -> { | ||
| Path targetDir = parent.resolve(result); | ||
|
|
||
| if (Files.exists(targetDir)) { | ||
| handler.reject(i18n("schematics.create_directory.failed.already_exists")); | ||
| return; | ||
|
|
@@ -178,7 +194,7 @@ public void onCreateDirectory() { | |
| LOG.warning("Failed to create directory: " + targetDir, e); | ||
| handler.reject(i18n("schematics.create_directory.failed", targetDir)); | ||
| } | ||
| }, "", new RequiredValidator(), new Validator(i18n("schematics.create_directory.failed.invalid_name"), FileUtils::isNameValid)); | ||
| }, "", new RequiredValidator(), new Validator(i18n("schematics.create_directory.failed.invalid_name"), FileUtils::isNameValid), new Validator(i18n("schematics.create_directory.failed.already_exists"), (it) -> !finalExistingFolders.contains(it))); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The validator only checks a case-sensitive snapshot captured before the prompt opens. If another process creates the directory while the dialog is open, or on a case-insensitive filesystem the user enters different casing for an existing name, validation succeeds and Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| private DirItem loadAll(Path dir, @Nullable DirItem parent) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要删除这一处检查?