-
-
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
Add drop down for citation key patterns #12516
Conversation
Screenshot? |
Recording.2025-02-16.mp4The positioning of list is not perfect, it comes on top of it, else works fine and the list of patterns is hardcoded. |
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 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]"); |
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.
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.
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.
We should either think how to auto-populate this list - or add a Java comment on how to populate the list manually.
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.
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
.
- Modify it to make it a final class.
- 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. - 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());
- 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).
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.
Actually no need to even change the class type. You can add the method in the record itself.
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.
Sure! Great suggestions, thanks!
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.
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".
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.
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.
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. |
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 With this, we could even recommend certain citation key paterns. |
src/main/java/org/jabref/logic/citationkeypattern/CitationKeyPattern.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Subhramit Basu Bhowmick <[email protected]>
|
||
private void populatePopup(List<String> searchResult) { | ||
List<CustomMenuItem> menuItems = new ArrayList<>(); | ||
int maxEntries = 7; |
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.
Move this to a class-level constant with a brief comment explaining its use and the value
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.
Tested it, works fine.
Code-wise too I can see everything I asked for.
Someone a bit deeper into javafx should take a closer look at the gui
files.
I found this solution on Stack Overflow for GUI. |
Update - tested a case - in case of compound patterns like |
Will do. I'll ensure [auth]_[year] triggers the dropdown. |
This pattern [auth]_[year] does not exist in the Java record. |
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.
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.
Wow this is a really epic feature! Looks great! |
Please add a changelog entry! |
Head branch was pushed to by a user without write access
Yes, it is not supposed to, it is a compound pattern - what I meant was (as per #12502 (comment)) - the individual components of a compound pattern should trigger a dropdown. I have given an example. I like your solution more though, and hardcoding it into the record works as it's a common pattern. Any less used pattern can be manually typed anyway. The sub-dropdowns are an icing on the cake, so really good work. JabRef users will love this. |
Thanks for the clarification! I will try it in a follow-up PR. |
Not a priority right now, maybe when you can't find things more striking to work on. Also, to clarify:
I was referring to what you did, not what is left :) |
Fixes #12502
This PR introduces a functionality to display a drop-down list of matching suggestions when typing a citation key pattern.
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if change is visible to the user)