Skip to content
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

Fix adding files with illegal characters #10205

Merged
merged 6 commits into from
Aug 24, 2023
Merged

Conversation

Siedlerchr
Copy link
Member

@Siedlerchr Siedlerchr commented Aug 23, 2023

Fixes #10182

Also supported for drag and drop

(The FilenameCleanerTest can be converted to parameterized test, bu this can be an easy student task)

grafik

Display a dialog with auto-renaming option

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

Fixes #10182


Display a dialog with auto renaming option
@github-actions
Copy link
Contributor

Your code currently does not meet JabRef's code guidelines. The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR. Please carefully follow the setup guide for the codestyle. Afterwards, please run checkstyle locally and fix the issues.

More information on code quality in JabRef is available at https://devdocs.jabref.org/getting-into-the-code/development-strategy.html.

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 23, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 23, 2023

The build for this PR is no longer available. Please visit https://builds.jabref.org/main/ for the latest build.

@calixtus
Copy link
Member

calixtus commented Aug 24, 2023

I suggest rephrasing the right button "Rename and add" and remove the two sentences describing sentences in the dialog text.

Comment on lines +114 to +140
private List<Path> getValidFileNames(List<Path> filesToAdd) {
List<Path> validFileNames = new ArrayList<>();

for (Path fileToAdd : filesToAdd) {
if (FileUtil.detectBadFileName(fileToAdd.toString())) {
String newFilename = FileNameCleaner.cleanFileName(fileToAdd.getFileName().toString());

boolean correctButtonPressed = dialogService.showConfirmationDialogAndWait(Localization.lang("File \"%0\" cannot be added!", fileToAdd.getFileName()),
Localization.lang("Illegal characters in the file name detected.\nFile will be renamed to \"%0\" and added.", newFilename),
Localization.lang("Rename and add"));

if (correctButtonPressed) {
Path correctPath = fileToAdd.resolveSibling(newFilename);
try {
Files.move(fileToAdd, correctPath);
validFileNames.add(correctPath);
} catch (IOException ex) {
LOGGER.error("Error moving file", ex);
dialogService.showErrorDialogAndWait(ex);
}
}
} else {
validFileNames.add(fileToAdd);
}
}
return validFileNames;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of code duplication to LinkedFilesEditorViewModel, but fine for a hotfix. Maybe an followup PR should clean this up.

@Siedlerchr Siedlerchr merged commit 908c389 into main Aug 24, 2023
@Siedlerchr Siedlerchr deleted the fixAddingFilesWithIllegal branch August 24, 2023 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
2 participants