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: Usage of "Copy to" option preference #12503

Merged
merged 3 commits into from
Feb 16, 2025

Conversation

priyanshu16095
Copy link
Contributor

@priyanshu16095 priyanshu16095 commented Feb 14, 2025

Fixes #12500

This fix ensures that the "Copy to" option follows the chosen preference correctly.

Mandatory checks

  • I own the copyright of the code submitted and I licence it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • 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.
Recording.2025-02-15.mp4

@priyanshu16095 priyanshu16095 changed the title Fix the bug "Copy to" option follows the choosen preference correctly Feb 14, 2025
Copy link
Contributor

@github-actions github-actions bot left a 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.

Copy link
Member

@subhramit subhramit left a 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:

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()) {
Copy link
Member

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()?

Copy link
Contributor Author

@priyanshu16095 priyanshu16095 Feb 14, 2025

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.

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.

@subhramit subhramit changed the title "Copy to" option follows the choosen preference correctly Fix: Usage of "Copy to" option preference Feb 14, 2025
@subhramit
Copy link
Member

subhramit commented Feb 14, 2025

The failing unit tests would also need to be looked at.

@priyanshu16095
Copy link
Contributor Author

priyanshu16095 commented Feb 14, 2025

@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 will try to improve this, in the same PR.

@subhramit
Copy link
Member

subhramit commented Feb 14, 2025

@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 would not say that's a good way to do it - especially if a user is working with a large number of entries.

I will try to improve this, in the same PR.

🚀

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.

Siedlerchr
Siedlerchr previously approved these changes Feb 15, 2025
@Siedlerchr
Copy link
Member

Please chekc the failing unit tests, otherwise it looks good

@Siedlerchr
Copy link
Member

Is this ready now?

@priyanshu16095
Copy link
Contributor Author

priyanshu16095 commented Feb 16, 2025

Yes, Please review.

@Siedlerchr Siedlerchr added this pull request to the merge queue Feb 16, 2025
Copy link
Member

@koppor koppor left a 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.

Merged via the queue into JabRef:main with commit dce41e6 Feb 16, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Copy To" option does not follow the preferences
4 participants