-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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: Usage of "Copy to" option preference #12503
Fix: Usage of "Copy to" option preference #12503
Conversation
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.
JUnit tests are failing. In the area "Some checks were not successful", locate "Tests / Unit tests (pull_request)" and click on "Details". This brings you to the test output.
You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.
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 didn't go through this thoroughly before so trying to gather context:
jabref/src/main/java/org/jabref/gui/edit/CopyTo.java
Lines 48 to 64 in 19df622
public void execute() { | |
// we need to operate on a copy otherwise we might get ConcurrentModification issues | |
List<BibEntry> selectedEntries = stateManager.getSelectedEntries().stream().toList(); | |
boolean includeCrossReferences = false; | |
boolean showDialogBox = copyToPreferences.getShouldAskForIncludingCrossReferences(); | |
for (BibEntry bibEntry : selectedEntries) { | |
if (bibEntry.hasField(StandardField.CROSSREF) && showDialogBox) { | |
includeCrossReferences = askForCrossReferencedEntries(); | |
copyToPreferences.setShouldIncludeCrossReferences(includeCrossReferences); | |
} | |
} | |
if (includeCrossReferences) { | |
copyEntriesWithCrossRef(selectedEntries, targetDatabaseContext); | |
} else { |
Correct me if I'm wrong, the preference is independent of entries, and if the preference is enabled, we should check for cross references in entries. Why then are we setting the preference for each entry with a cross reference (with each iteration)?
if (includeCrossReferences) { | ||
if (copyToPreferences.getShouldIncludeCrossReferences()) { |
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'm having a bit of trouble understanding this due to the naming.
What does the field includeCrossReferences
do?
And why is it's state different from copyToPreferences.getShouldIncludeCrossReferences()
?
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.
The state of includeCrossReferences
is different because every time the execute()
method is called, it initializes to false.
It updates only when this code executes.
jabref/src/main/java/org/jabref/gui/edit/CopyTo.java
Lines 55 to 60 in 19df622
for (BibEntry bibEntry : selectedEntries) { | |
if (bibEntry.hasField(StandardField.CROSSREF) && showDialogBox) { | |
includeCrossReferences = askForCrossReferencedEntries(); | |
copyToPreferences.setShouldIncludeCrossReferences(includeCrossReferences); | |
} | |
} |
If
showDialogBox
is false, it will never update and will remain false, which is the cause of the bug.
The failing unit tests would also need to be looked at. |
@subhramit At that time, I tried it in a way that if the user had selected multiple entries, it would individually ask for confirmation for each entry that had cross-referenced entries. I've seen this behavior multiple times in Windows. |
I would not say that's a good way to do it - especially if a user is working with a large number of entries.
🚀 Change the title as well to "Improve Copy to option + fix usage of preference" or something (and mark draft till done) if you plan to do that. A separate PR is also fine, up to you. |
Please chekc the failing unit tests, otherwise it looks good |
Is this ready now? |
Yes, Please review. |
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.
Looked at it. OK. Next time, add some Java Comment -> the "break" took me 30 seconds to understand without any comment.
Fixes #12500
This fix ensures that the "Copy to" option follows the chosen preference correctly.
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if change is visible to the user)Recording.2025-02-15.mp4