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

Add drop down for citation key patterns #12516

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

priyanshu16095
Copy link
Contributor

@priyanshu16095 priyanshu16095 commented Feb 16, 2025

Fixes #12502

This PR introduces a functionality to display a drop-down list of matching suggestions when typing a citation key pattern.

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.

Screenshot (109)

@koppor
Copy link
Member

koppor commented Feb 16, 2025

Screenshot?

@priyanshu16095
Copy link
Contributor Author

priyanshu16095 commented Feb 16, 2025

Recording.2025-02-16.mp4

The positioning of list is not perfect, it comes on top of it, else works fine and the list of patterns is hardcoded.

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 know it's a draft, but requesting a minor change.
Really good work so far! Thanks for picking this up.

ObservableList<String> fullData = FXCollections.observableArrayList(
"[auth]", "[authFirstFull]", "[authForeIni]", "[auth.etal]", "[authEtAl]",
"[auth.auth.ea]", "[authors]", "[authorsN]", "[authIniN]", "[authN]", "[authN_M]",
"[authorIni]", "[authshort]", "[authorsAlpha]");
Copy link
Member

@subhramit subhramit Feb 16, 2025

Choose a reason for hiding this comment

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

Also add [authorsAlphaLNI] (added in #12499).
Also, the issue asks for special field markers, which also includes Editor-related field markers, Title-related field markers, Other field markers and Bibentry fields apart from the author-related ones. Please add them as well.

Copy link
Member

Choose a reason for hiding this comment

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

We should either think how to auto-populate this list - or add a Java comment on how to populate the list manually.

Copy link
Member

@subhramit subhramit Feb 17, 2025

Choose a reason for hiding this comment

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

Yes, @priyanshu16095 - lets make this neat.
This is what I brainstormed, need a second opinion from @Siedlerchr and @koppor so that we know this is the best way and doesn't break things:
There is a record class, CitationKeyPatterns.java.

  1. Modify it to make it a final class.
  2. Hardcode the patterns as constants there. Leave proper comments with //region - citation key patterns offered. for any new pattern, add them here and // endregion below.
  3. Make a public static function getAllPatterns, see if this works (I chatgpt'd this snippet - make any modifications needed):
Arrays.stream(CitationKeyPatterns.class.getDeclaredFields())
             .filter(field -> {
                 int modifiers = field.getModifiers();
                 return Modifier.isPublic(modifiers) && 
                        Modifier.isStatic(modifiers) && 
                        Modifier.isFinal(modifiers) &&
                        field.getType() == CitationKeyPattern.class &&
                        field != CitationKeyPattern.NULL_CITATION_KEY_PATTERN;
             })
             .map(field -> {
                 try {
                     return (CitationKeyPattern) field.get(null);
                 } catch (IllegalAccessException e) {
                     throw new RuntimeException("Could not access field", e);
                 }
             })
             .collect(Collectors.toList());
  1. Use that list returned in your observable array list

This way, the developer has to just change one line when adding a new pattern, without the overhead of finding the list where patterns are populated, or just using raw strings or using constants (you have to put them everywhere otherwise).

Copy link
Member

Choose a reason for hiding this comment

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

Actually no need to even change the class type. You can add the method in the record itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! Great suggestions, thanks!

@priyanshu16095
Copy link
Contributor Author

priyanshu16095 commented Feb 17, 2025

Recording.2025-02-18.mp4

For CitationKeyPatternSuggestionCell, I found this solution on Stack Overflow and a similar gist on Github Gist and modified it.

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 OpenRewrite to ensure "modern" Java coding practices. The issues found can be automatically fixed. Please execute the gradle task rewriteRun, check the results, commit, and push.
You can check the detailed error output by navigating to your pull request, selecting the tab "Checks", section "Tests" (on the left), subsection "OpenRewrite".

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
Contributor Author

There is a problem with using the context menu because when it reaches the bottom of the screen, it shifts upward, making the UI buggy.
Instead, we can use a VBox or any other suggestions?

@koppor
Copy link
Member

koppor commented Feb 18, 2025

There is a problem with using the context menu because when it reaches the bottom of the screen, it shifts upward, making the UI buggy. Instead, we can use a VBox or any other suggestions?

If you don't get an answer quickly, just assume that nobody has a clue and will need invest time to investigate. Thus, go ahead and try.

Note that we could accept a different UI using a popup and buttons -similar to "Select entry type" -- if this works better

grafik


With this, we could even recommend certain citation key paterns.

@priyanshu16095
Copy link
Contributor Author

Screenshot (126)

The feature is now complete.
For the last element, it works fine, and the context menu does not change its position.

@subhramit subhramit marked this pull request as ready for review February 20, 2025 19:19
Co-authored-by: Subhramit Basu Bhowmick <[email protected]>
@subhramit subhramit added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers component: citationkey-generator labels Feb 20, 2025

private void populatePopup(List<String> searchResult) {
List<CustomMenuItem> menuItems = new ArrayList<>();
int maxEntries = 7;
Copy link
Member

@subhramit subhramit Feb 20, 2025

Choose a reason for hiding this comment

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

Move this to a class-level constant with a brief comment explaining its use and the value

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.

Tested it, works fine.
Code-wise too I can see everything I asked for.

Someone a bit deeper than me into javafx should take a closer look at the gui files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: citationkey-generator status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add dropdown for selecting citation key pattern
3 participants