-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Refine "File exists" warning #13491
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
Refine "File exists" warning #13491
Changes from 8 commits
26636e2
5fd2a8c
8e7591d
06674e5
fb8f718
6059ffe
70455bc
6bb7287
865f839
eada06a
560174e
6b0c081
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 |
|---|---|---|
|
|
@@ -18,6 +18,11 @@ | |
| import javafx.beans.property.SimpleDoubleProperty; | ||
| import javafx.beans.property.StringProperty; | ||
| import javafx.scene.Node; | ||
| import javafx.scene.control.Button; | ||
| import javafx.scene.control.ButtonBar; | ||
| import javafx.scene.control.ButtonType; | ||
| import javafx.scene.control.Dialog; | ||
| import javafx.scene.control.Tooltip; | ||
|
|
||
| import org.jabref.gui.AbstractViewModel; | ||
| import org.jabref.gui.DialogService; | ||
|
|
@@ -37,6 +42,7 @@ | |
| import org.jabref.logic.externalfiles.LinkedFileHandler; | ||
| import org.jabref.logic.l10n.Localization; | ||
| import org.jabref.logic.util.TaskExecutor; | ||
| import org.jabref.logic.util.io.FileNameUniqueness; | ||
| import org.jabref.logic.util.io.FileUtil; | ||
| import org.jabref.model.database.BibDatabaseContext; | ||
| import org.jabref.model.entry.BibEntry; | ||
|
|
@@ -268,20 +274,54 @@ private void performRenameWithConflictCheck(String targetFileName) { | |
| boolean overwriteFile = false; | ||
|
|
||
| if (existingFile.isPresent()) { | ||
| overwriteFile = dialogService.showConfirmationDialogAndWait( | ||
| Localization.lang("File exists"), | ||
| Localization.lang("'%0' exists. Overwrite file?", targetFileName), | ||
| Localization.lang("Overwrite")); | ||
| // Get existing file path and its directory | ||
| Path existingFilePath = existingFile.get(); | ||
| Path targetDirectory = existingFilePath.getParent(); | ||
|
|
||
| // Suggest a non-conflicting file name | ||
| String suggestedFileName = FileNameUniqueness.getNonOverWritingFileName(targetDirectory, targetFileName); | ||
|
|
||
| // Define available dialog options | ||
| ButtonType Replace = new ButtonType(Localization.lang("Replace"), ButtonBar.ButtonData.OTHER); | ||
| ButtonType keepBoth = new ButtonType(Localization.lang("Keep both"), ButtonBar.ButtonData.OTHER); | ||
| ButtonType provideAlternative = new ButtonType(Localization.lang("Provide alternative file name"), ButtonBar.ButtonData.OTHER); | ||
| ButtonType cancel = new ButtonType(Localization.lang("Cancel"), ButtonBar.ButtonData.OTHER); | ||
|
|
||
| // Build the dialog window | ||
| Dialog<ButtonType> dialog = new Dialog<>(); | ||
|
||
| dialog.setTitle(Localization.lang("File already exists")); | ||
| dialog.setContentText(Localization.lang("File name: \n'%0'", targetFileName)); | ||
| dialog.getDialogPane().getButtonTypes().addAll(Replace, keepBoth, provideAlternative, cancel); | ||
|
||
|
|
||
| // Add tooltip to "Keep both" button with the suggested name | ||
| Button keepBothButton = (Button) dialog.getDialogPane().lookupButton(keepBoth); | ||
| if (keepBothButton != null) { | ||
| keepBothButton.setTooltip(new Tooltip(Localization.lang("New filename: %0", suggestedFileName))); | ||
| } | ||
|
|
||
| if (!overwriteFile) { | ||
| // Show dialog and handle user response | ||
| Optional<ButtonType> result = dialog.showAndWait(); | ||
|
|
||
| if (result.isEmpty() || result.get() == cancel) { | ||
| return; // User canceled | ||
| } else if (result.get() == Replace) { | ||
| overwriteFile = true; | ||
| } else if (result.get() == keepBoth) { | ||
| targetFileName = suggestedFileName; | ||
| } else if (result.get() == provideAlternative) { | ||
| askForNameAndRename(); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| // Attempt the rename operation | ||
| linkedFileHandler.renameToName(targetFileName, overwriteFile); | ||
| } catch (IOException e) { | ||
| dialogService.showErrorDialogAndWait(Localization.lang("Rename failed"), Localization.lang("JabRef cannot access the file because it is being used by another process.")); | ||
| // Display an error dialog if file is locked or inaccessible | ||
| dialogService.showErrorDialogAndWait( | ||
| Localization.lang("Rename failed"), | ||
| Localization.lang("JabRef cannot access the file because it is being used by another process.")); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,6 +252,12 @@ Do\ not\ abbreviate\ names=Do not abbreviate names | |
|
|
||
| Do\ not\ wrap\ when\ saving=Do not wrap when saving | ||
|
|
||
| File\ already\ exists=File already exists | ||
|
Member
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. Pleae group to line 2999 (there is |
||
| File\ name\:\ \n'%0'=File name: \n'%0' | ||
|
Member
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. There should be no space before newline Maybe you can submit a follow-up PR? |
||
| New\ filename\:\ %0=New filename: %0 | ||
| Provide\ alternative\ file\ name=Provide alternative file name | ||
|
|
||
|
|
||
| Download\ file=Download file | ||
|
|
||
| Download\ '%0'\ was\ a\ HTML\ file.\ Removed.=Download '%0' was a HTML file. Removed. | ||
|
|
||
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.
should be cancel close for button data