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

Copy to option #12374

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Conversation

priyanshu16095
Copy link

@priyanshu16095 priyanshu16095 commented Jan 9, 2025

Fixes #12341

This PR introduces a 'Copy to' context menu option with features for cross-reference inclusion/exclusion, as well as the ability to save user preferences.

THE CHANGES MADE

  • Implemented a 'Copy to' context menu that displays the names of currently opened libraries as checkable menu items.
  • After selecting the libraries, a dialog is shown allowing users to include or exclude cross-references.
  • Added functionality to save user preferences for cross-reference inclusion/exclusion, ensuring a personalized experience for future use.

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.
    a
    b

@priyanshu16095 priyanshu16095 marked this pull request as draft January 9, 2025 23:24
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.

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

In case of issues with the import order, double check that you activated Auto Import.
You can trigger fixing imports by pressing Ctrl+Alt+O to trigger Optimize Imports.

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.

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

In case of issues with the import order, double check that you activated Auto Import.
You can trigger fixing imports by pressing Ctrl+Alt+O to trigger Optimize Imports.

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.

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

In case of issues with the import order, double check that you activated Auto Import.
You can trigger fixing imports by pressing Ctrl+Alt+O to trigger Optimize Imports.

@priyanshu16095
Copy link
Author

Please review it and provide any suggestions.

@Siedlerchr
Copy link
Member

Siedlerchr commented Jan 11, 2025 via email

@priyanshu16095
Copy link
Author

Apologies, and thanks for the update! I understand, and I really appreciate your time.

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.

Comments on first look.

public void execute() {
Logger logger = LoggerFactory.getLogger(CopyTo.class);

BibDatabaseContext databaseContext = new BibDatabaseContext();
Copy link
Member

Choose a reason for hiding this comment

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

Not needed here.

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I will remove them, considering it is a draft PR. I left them for explanatory purposes.

Comment on lines 63 to 68
for (String title: titles) {
logger.info("Selected Entreis: " + title);
}
for (String checkedPath: checkedPaths) {
logger.info("Selected Libraries to copy: " + checkedPath);
}
Copy link
Member

Choose a reason for hiding this comment

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

Remove (loops with no utility apart from logging)

Copy link
Member

Choose a reason for hiding this comment

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

Logic for copying the cross ref stuff is missing But I think @HoussemNasri splitted that task?

Copy link
Member

Choose a reason for hiding this comment

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

No, the copying of cross-ref stuff is the ticket assigned to @priyanshu16095.

#12339 is the ticket for creating the "copy to" menu; it is assigned to someone else, but since @priyanshu16095 already started working on it we agreed to have a draft pull request that might eventually be considered for merge in case of inactivity from the current assignee of that issue.

The issues/tasks are tightly coupled and meant to be done in a certain order. This pull request might or might not be merged depending on whether we receive any activities from the assignee of #12339, but IMO the work done here could be reused later to tackle #12341.

Copy link
Member

Choose a reason for hiding this comment

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

Logic for copying the cross ref stuff is missing But I think @HoussemNasri splitted that task?

Actually, #12340 was meant to be tackled before the one mentioned in PR description #12341, so yes logic for copy cross references is for another task or could be handled in this PR since both issues are assigned to @priyanshu16095.

Comment on lines 73 to 77
if (preferences.getCopyToPreferences().getShouldIncludeCrossReferences()) {
logger.info("Include Cross References");
} else {
logger.info("Exclude Cross References");
}
Copy link
Member

Choose a reason for hiding this comment

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

Either decrease log noise or remove.

optOut -> preferences.getCopyToPreferences().setShouldAskForIncludingCrossReferences(!optOut)
);
} else {
return preferences.getCopyToPreferences().getShouldIncludeCrossReferences();
Copy link
Member

Choose a reason for hiding this comment

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

See if you can improve abstraction - pass preferences.getCopyToPreferences() via constructor instead of entire GuiPreferences

if (!openDatabases.isEmpty()) {
openDatabases.forEach(library -> {
String path = library.getDatabasePath().get().toString();
String name = path.substring(path.lastIndexOf('\\') + 1);
Copy link
Member

@subhramit subhramit Jan 12, 2025

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Yeah we also use that code part in

Optional<String> dbOpt = Optional.empty();
if (database.getDatabasePath().isPresent()) {
dbOpt = FileUtil.getUniquePathFragment(stateManager.collectAllDatabasePaths(), database.getDatabasePath().get());
}
if (database.getLocation() == DatabaseLocation.SHARED) {
return database.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") + "]";
}
return dbOpt.orElseGet(() -> Localization.lang("untitled"));

We should add this somewhere more central

@subhramit
Copy link
Member

Please also fix the Checkstyle, Openrewrite and Unit tests. The FAQ page will help you.

this.shouldAskForIncludingCrossReferences.set(shouldAskForIncludingCrossReferences);
}

public boolean getShouldIncludeCrossReferences() {
Copy link
Member

Choose a reason for hiding this comment

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

How about shouldIncludeCrossReferences? It reads better.

Copy link
Author

Choose a reason for hiding this comment

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

Is it in line 17 or 14?

Copy link
Member

Choose a reason for hiding this comment

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

The method name. It is a nitpick so feel free to ignore.


@Override
public void execute() {
Logger logger = LoggerFactory.getLogger(CopyTo.class);
Copy link
Member

Choose a reason for hiding this comment

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

Each class should declare the logger only once. Refer to the logging usage in other classes for guidance.

Copy link
Author

@priyanshu16095 priyanshu16095 Jan 12, 2025

Choose a reason for hiding this comment

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

Oh, I used it for temporary purposes, but forgot to remove it.

@priyanshu16095
Copy link
Author

I have fixed the Checkstyle, OpenRewrite, and Unit tests errors and made changes based on the reviews.

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.

Add an option to remember user decision of inclusion or exclusion of cross-referenced entries when copying
4 participants