Implemented issue #3229#3233
Conversation
|
Hi @derebaba Thanks for your pull request! Your contribution is certainly very welcome and looks good overall. I still have two points that should be addressed:
|
|
Hi @lenhard Thanks for your feedback. Are the keys ordered in any way in properties file? Or should I add new keys at the end? |
|
@derebaba You should first check if there is already a key with the same/or similar text which you can reuse. Otherwise add it to the end and. |
|
I synchronized the keys and removed the check which used the old api. However, |
| return Files.move(fromFile, fromFile.resolveSibling(toFile)) != null; | ||
| } | ||
| } catch (IOException e) { | ||
| DIALOGSERVICE.showErrorDialogAndWait( |
There was a problem hiding this comment.
That is not a good idea, as you are now violating the architecture: https://github.com/JabRef/jabref/wiki/High-Level-Documentation
You are having gui components in a logic method. This FileUtil method is used in many places.
So I suggest you create a method which throws the exception
There was a problem hiding this comment.
I think we need to help @derebaba here a bit (since architectural questions are probably not a good start into a project).
It is also not possible to simply move the dialog service stuff to RenamePdfCleanup since this class also resides in logic. Thus I would propose the following:
- Extract the body of the
FileUtil.renameFilemethod to a new methodFileUtil.renameFileWithException
jabref/src/main/java/org/jabref/logic/util/io/FileUtil.java
Lines 194 to 199 in c47d2a4
- Similarly, extract the body of the cleanup method to a new method
cleanupWithException(which then uses the newrenameFileWithExceptionmethod) - Catch the exception and show the error dialog in the gui:
It's a bit complicated but the best I can come up with (especially since the FileUtil and CleanupJob classes are designed to hide exceptions instead of to expose them). @JabRef/developers what do you think?
There was a problem hiding this comment.
Thanks for the comprehensive explanation. I got a little confused at first. Check out my latest commit. It should do the trick if I understand correctly.
There was a problem hiding this comment.
Thanks for the quick implementation! The code is exactly how I meant it, good job!
The only problem left is the code duplication from the old methods and the new ones that throw an exception. But this should be easy to fix by calling the withException method in the original one; along the following lines:
public static boolean renameFile(Path fromFile, Path toFile, boolean replaceExisting) {
try {
return renameFileWithException(fromFile, toFile, replaceExisting);
} catch (IOException e) {
LOGGER.error("Renaming Files failed", e);
return false;
}
}Similarly for the cleanup method. If this is changed as well, I give my 👍 for merge.
There was a problem hiding this comment.
I removed the duplicate code as you explained. It is my first contribution ever to an open source project. Thank you for being so helpful.
Siedlerchr
left a comment
There was a problem hiding this comment.
Yeah! That looks good now! Thanks for your contribution!
We are looking forward to see more from you ;)
* upstream/master: (113 commits) Open statistics dialog from correct thread (#3272) Fix for issue 2811: bibtexkey generator does not use crossref information (#3248) Fix for issue 3143: Import entry from clipboard in different formats (#3243) French translation correction (#3262) Wait to ask to collect anonymous statistics in JabRefExecutorService to allow jvm to terminate (#3266) Directory pattern bracketed expressions (#3238) Show development information Release v4.0 add another author to mailmap moved changelog entry to the right category update new AUTHORS info Update log4j from 2.9.0 -> 2.9.1 fix dblp fetcher Add missing Turkish translation Add "-console" parameter for Windows launcher (#3242) Path check converted to if statement Changelog updated Fixed renaming files which are not in main directory. Only use last name for auto completion in search bar. Fixes JabRef#253 Implemented issue #3229 (#3233) ...
Added an error dialog if the file is open in another process and cannot be renamed. [#3229]. This is my first contribution. Please give me feedback if you see any problems.