-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Consider directory pattern when checking if a file can be moved #8244
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
Changes from 9 commits
9fb9533
b8da9cf
fcbc66f
b18bbef
b5a1656
2498240
ced2753
66a8a7e
3e6e977
a81205e
4f4739f
836819e
4d710ba
03dbdb9
da804bd
c071548
f9630b6
ec98c2f
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -60,7 +60,7 @@ | |||||||||||||||||||
| import org.jabref.model.entry.LinkedFile; | ||||||||||||||||||||
| import org.jabref.model.strings.StringUtil; | ||||||||||||||||||||
| import org.jabref.model.util.FileHelper; | ||||||||||||||||||||
| import org.jabref.model.util.OptionalUtil; | ||||||||||||||||||||
| import org.jabref.preferences.FilePreferences; | ||||||||||||||||||||
| import org.jabref.preferences.PreferencesService; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; | ||||||||||||||||||||
|
|
@@ -332,9 +332,29 @@ public boolean isGeneratedNameSameAsOriginal() { | |||||||||||||||||||
| * @return true if suggested filepath is same as existing filepath. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| public boolean isGeneratedPathSameAsOriginal() { | ||||||||||||||||||||
| Optional<Path> newDir = databaseContext.getFirstExistingFileDir(preferences.getFilePreferences()); | ||||||||||||||||||||
| FilePreferences filePreferences = preferences.getFilePreferences(); | ||||||||||||||||||||
| Optional<Path> newDir = databaseContext.getFirstExistingFileDir(filePreferences); | ||||||||||||||||||||
| if (newDir.isEmpty()) { | ||||||||||||||||||||
| // could not find default path | ||||||||||||||||||||
| return false; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
||||||||||||||||||||
| return OptionalUtil.equals(newDir, currentDir, equality); |
and if both
linkedFile.findIn(databaseContext, preferences.getFilePreferences())databaseContext.getFirstExistingFileDir(preferences.getFilePreferences()
are empty we return
jabref/src/main/java/org/jabref/model/util/OptionalUtil.java
Lines 25 to 26 in 69467d3
| if (!left.isPresent()) { | |
| return !right.isPresent(); |
true.
which means the two options would be disabled
wouldn't this mean that they are enabled since it gets negated later on?
| && !linkedFile.isGeneratedPathSameAsOriginal(), |
P.S, that would be an awesome test case 😃
Huge thanks for addressing all the nitpicks and yet again, sorry about the delayed response. I'll try to be more responsive if you have follow up questions about this :/
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.
I realized I dodged your question a bit, the short(ish) answer to
I'm also trying to understand the logic here.
is that I believe the separation of concern can be improved upon in the original method
| public boolean isGeneratedPathSameAsOriginal() { |
In my opinion, the "correct" method signature should be public Optional<Boolean> isGeneratedPathSameAsOriginal() {
because the two cases you bring up don't match very well with a true or false value to the question "is the generated path the same as the original path" (since there doesn't exist a generated path or an original path). That is part of what I hoped to bring up in the follow-up issue 😛
In my opinion the check for
if the user did not set default path in preference
and
Similarly, in line 351-354,
if(currentDir.isEmpty())
provides improved separation of concern if they are done in
jabref/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java
Lines 302 to 305 in 69467d3
| case MOVE_FILE_TO_FOLDER -> Bindings.createBooleanBinding( | |
| () -> !linkedFile.getFile().isOnlineLink() | |
| && linkedFile.getFile().findIn(databaseContext, preferencesService.getFilePreferences()).isPresent() | |
| && !linkedFile.isGeneratedPathSameAsOriginal(), |
So that those lines read
- is it an online link?
- is there a linked file?
- can we generate a path?
- is the generated path the same as the current path (or does this question not make sense, in which case we are getting an
Optional.empty)?
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.
As I am writing this I realize that this is probably quite a bit into the nitpicking territory.
Imo the main thing a PR should do is improve on the code, which your PR does, so view this as a nitpick, would you like to address it otherwise we merge this PR as-is as soon as you get back to us
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.
Addressing the nitpick could either be to change the method signature or to match the true/false behavior of the unmodified method (in which case changing the method signature will be part of the follow-up issue when I have time to write it)
Imo you would match the behavior of the unmodified method if you remove the two if statements
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.
Hi @k3KAW8Pnf7mkmdSMPHz27, I now apologize for my delayed response. Thanks a lot for the detailed explanation. I realized I confused myself a bit earlier.
For the part you quoted, it means if the user did not set default path in preference, this function would return false, which means the two options would be disabled.
This would actually be the opposite to what I previously said. Simply with isGeneratedPathSameAsOriginal() equal to false would mean the two options being enabled rather than disabled.
I'm now getting what you would like to address here and I agree true/false is not a perfect answer to these two cases.
My apology for not responding earlier, but since the PR has been merged, I would be happy to take a look at the follow-up issue when I have time. :)
Uh oh!
There was an error while loading. Please reload this page.