Skip to content

Show compound patterns in the dropdown for citation key patterns #12580

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

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

Conversation

priyanshu16095
Copy link
Contributor

@priyanshu16095 priyanshu16095 commented Feb 27, 2025

Follow-up for #12516

This PR enhances the citation key dropdown feature by adding a submenu for compound patterns.

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-28.mp4

}

public List<String> generateCompoundPatterns(String enteredText) {
List<String> patterns = List.of("auth", "edtr", "year", "title", "date");
Copy link
Contributor Author

@priyanshu16095 priyanshu16095 Feb 27, 2025

Choose a reason for hiding this comment

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

@subhramit I used this list as I don’t have much knowledge about the fields and can you explain more about compound patterns?

Copy link
Member

Choose a reason for hiding this comment

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

Please use the constants of org.jabref.model.entry.field.StandardField here.

The fields can be read about at BibLaTeX documentation at https://ctan.org/pkg/biblatex.

Copy link
Member

Choose a reason for hiding this comment

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

I think, the list should be manually crafted instead of just combinding all fields

The description at #12502 (comment) talks about auto completion

That would be nice.

If this is not possible, some pre-selected combinations should be doable.

I think, it needs to be a separate pop up then - even if multiple modals are not a good style ^^

Grammar: [{pattern}](_[{pattern}])*

  1. A user can select a pattern.
  2. Then, the user can select "+"
  3. Then, JabRef adds "_" and offers another dropdown to select (the one selected before is NOT offered)

Reason: A user wants to use AuthEtAl together with year typically.

@priyanshu16095 Think of this as autogenerated (!) human-readable-primary-key in databases. MAybe this helps. -- Another thing: Either data of a BibEntry can be used directly or some processing of JabRef can be used. The former is ensured by CAPITAL LETTERS (first paragraph at https://docs.jabref.org/setup/citationkeypatterns#citation-key-patterns). The latter is described in the other text.

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.

@priyanshu16095
Copy link
Contributor Author

priyanshu16095 commented Feb 28, 2025

Recording.2025-02-28.mp4

@koppor Thanks for your insights! I’ve come up with a different solution that addresses the concerns and removes the overhead of an algorithm, maintaining it, and making it more efficient.
Instead, I used a UI-based solution (similar to your modal solution) that provides a much better approach, as the user doesn't have to type different keywords to find a pattern.
The UX is perfect, for a two-click process—it takes only two clicks.

@priyanshu16095
Copy link
Contributor Author

priyanshu16095 commented Feb 28, 2025

Another improvement in the code:
For better UX, the position of the sub-menu items under 'All patterns' and 'Create compound pattern' has been fixed, as it was not fixed before.

Before:

before

After:

after

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.

@priyanshu16095 priyanshu16095 marked this pull request as ready for review March 3, 2025 10:24
@subhramit
Copy link
Member

subhramit commented Mar 3, 2025

Sorry, I am a little low on time to test this - What does the menu "Create compound pattern" do? Why is it needed if we can create compound patterns by taking patterns from the "All patterns" list? As far as I understand, only thing it does is add underscores in between patterns - the choice of that separator can be arbitrary for a user. @koppor do we wish to make underscore a default for this? Or is it a wider convention? This user, for example, was using colons (:) as a separator.

Also:
image

@priyanshu16095 Can you move the black arrows of the first menu (first two items having sublists) to the extreme right of the cell (like in the sublist menu)?

(Updated)

@priyanshu16095
Copy link
Contributor Author

Just like a dropdown that shows generated compound patterns, it allows the user to create any pattern on their own.
Regarding your concern about symbols, it could have a submenu displaying symbols that can be added or, by default - can be used.

@priyanshu16095
Copy link
Contributor Author

Screenshot (188)

The width of the menu cannot be set in JavaFX, as it is managed by the system. However, I can change the width of the labels instead.

@subhramit
Copy link
Member

Sorry, I am a little low on time to test this - What does the menu "Create compound pattern" do? Why is it needed if we can create compound patterns by taking patterns from the "All patterns" list? As far as I understand, only thing it does is add underscores in between patterns - the choice of that separator can be arbitrary for a user. @koppor do we wish to make underscore a default for this? Or is it a wider convention? This user, for example, was using colons (:) as a separator.

@koppor ping

@koppor
Copy link
Member

koppor commented Mar 7, 2025

Just like a dropdown that shows generated compound patterns, it allows the user to create any pattern on their own. Regarding your concern about symbols, it could have a submenu displaying symbols that can be added or, by default - can be used.

Good idea! _ can be the default.

@ryan-carpenter
Copy link

ryan-carpenter commented Mar 13, 2025

Just like a dropdown that shows generated compound patterns, it allows the user to create any pattern on their own. Regarding your concern about symbols, it could have a submenu displaying symbols that can be added or, by default - can be used.

The functionality is unclear because of the wording. The options need to be "parallel", like this:

Example 1

Choose pattern ⏵
Build pattern ⏵

Example 2

Basic pattern ⏵
Advanced pattern ⏵

Example 3

Simple pattern ⏵
Complex pattern ⏵

What about modifiers? These could be available after the first field or field marker has been selected, maybe like this.

Example 4

[title]
Add to pattern ⏵ ...
Add modifier ⏵ :abbr
               :lower
               :upper
               :titlecase

Another possibility for modifiers and even more detail would be to include an "expert" option linking to documentation or just add View documentation 🔗 to the list. I don't think JabRef already has a convention for context-sensitive help on menus, but I could be wrong.

@priyanshu16095
Copy link
Contributor Author

priyanshu16095 commented Mar 14, 2025

@ryan-carpenter I was unable to convey this properly. What I mean to say is that, without writing much additional code and by simply adding a few lines in the UI, it significantly improves the user experience. This is because there's no need to read any documentation or manually reopen the dropdown.
I will improve this based on the review.

@priyanshu16095 priyanshu16095 marked this pull request as draft March 20, 2025 01:52
@priyanshu16095
Copy link
Contributor Author

What is described in the comment is too complex to be implemented with context menu. If adding a submenu for other symbols and an expert linked to documentation is sufficient, or else I should use any other thing for UI.

@priyanshu16095
Copy link
Contributor Author

I am okay with doing what is described in the comment. Just want to know thoughts on this.

@subhramit
Copy link
Member

subhramit commented Apr 2, 2025

I am okay with doing what is described in the comment. Just want to know thoughts on this.

Lets do a follow-up on that in a separate PR.
Is this otherwise ready? If it is, please resolve the merge conflicts and mark it ready for review.

@priyanshu16095
Copy link
Contributor Author

Done, resolved the conflicts, and it is ready.

@priyanshu16095
Copy link
Contributor Author

priyanshu16095 commented Apr 2, 2025

Does it also require a changelog.md entry?

@jabref-machine
Copy link
Collaborator

Note that your PR will not be reviewed/accepted until you have gone through the mandatory checks in the description and marked each of them them exactly in the format of [x] (done), [ ] (not done yet) or [/] (not applicable).

@priyanshu16095
Copy link
Contributor Author

Fixing the checks...

@subhramit
Copy link
Member

Does it also require a changelog.md entry?

No, if the previous one mentions "dropdowns". Else, you can edit it.

private int heightOfMenuItem;
private final StringBuilder selectedPatterns = new StringBuilder();
Copy link

Choose a reason for hiding this comment

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

StringBuilder is used for concatenating strings, which can be replaced with StringJoiner for better readability and maintainability.

CitationKeyPattern.Category.BIBENTRY_FIELDS, Localization.lang("Entry fields")
);
Map<CitationKeyPattern.Category, String> categoryNames = new LinkedHashMap<>();
categoryNames.put(CitationKeyPattern.Category.AUTHOR_RELATED, Localization.lang("Author related"));
Copy link

Choose a reason for hiding this comment

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

The localization strings should be prefixed with % for proper localization handling in JabRef.

@@ -131,7 +149,8 @@ private void populatePopup(List<String> searchResult) {
}

suggestionsList.getItems().clear();
suggestionsList.getItems().add(createPatternsSubMenu());
suggestionsList.getItems().add(ALL_PATTERNS_POSITION, createPatternsSubMenu());
Copy link

Choose a reason for hiding this comment

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

The use of magic numbers like ALL_PATTERNS_POSITION should be avoided. Consider using a more descriptive constant or comment.

@jabref-machine
Copy link
Collaborator

You ticked that you modified CHANGELOG.md, but no new entry was found there.

If you made changes that are visible to the user, please add a brief description along with the issue number to the CHANGELOG.md file. If you did not, please replace the cross ([x]) by a slash ([/]) to indicate that no CHANGELOG.md entry is necessary. More details can be found in our Developer Documentation about the changelog.

@priyanshu16095
Copy link
Contributor Author

It's ready. Please take a look at the trag bot review and let me know what needs to be done in the follow-up.

@subhramit subhramit marked this pull request as ready for review April 4, 2025 17:05
Comment on lines +117 to +119
if (!newValue) {
suggestionsList.hide();
}
Copy link

Choose a reason for hiding this comment

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

The code should follow the fail-fast principle by immediately handling invalid states and returning early instead of nesting logic inside else branches.

@priyanshu16095
Copy link
Contributor Author

This is complete.

@priyanshu16095
Copy link
Contributor Author

@subhramit This is complete.

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.

For any user-visible change, there should be a CHANGELOG.md entry.

Counter-Intuitive for me

context menu (right-click) does not show any suggestions:

image

When pressing a letter, the menu is shown.

image

Why empty?

image

--

The number of entries at compound-patterns is not limited, thus [author]_[title]_[year] is also valid

I think, more intuitive would be:

  1. Show only "All patterns" during completion.
  2. Show completion also after _
    image
  3. Show completion also at right click
  4. Remove "Compound pattern"

Future work: context menu INSIDE a pattern shows the available modifiers.

positionCaret(selectedPatterns.length());
suggestionsList.hide();
selectionCount = 0;
selectedPatterns.setLength(0);
Copy link
Member

Choose a reason for hiding this comment

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

Not understandable at first sight - comment needed.

suggestionsList.show(this, screenX, screenY);
}
} else if (selectionCount == 1) {
selectedPatterns.append("_").append(pattern.stringRepresentation());
Copy link
Member

Choose a reason for hiding this comment

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

Not sure how this whole things works. Somewhere, it should be explained, how selectedPatterns is inteded to be sued.

@koppor
Copy link
Member

koppor commented Apr 19, 2025

@ryan-carpenter I was unable to convey this properly. What I mean to say is that, without writing much additional code and by simply adding a few lines in the UI, it significantly improves the user experience. This is because there's no need to read any documentation or manually reopen the dropdown.

I think, my review even improves usability more - and should not be much code, either.

What ryan also mentioned are the modifiers - which I also mentioned in my comment. On the one hand, this is really advanced JabRef usage - and could be done in a follow up. On the other hand, if you start implementing context menus, this could be "easily" doable maybe.

@ryan-carpenter
Copy link

ryan-carpenter commented May 24, 2025

@ryan-carpenter I was unable to convey this properly. What I mean to say is that, without writing much additional code and by simply adding a few lines in the UI, it significantly improves the user experience. This is because there's no need to read any documentation or manually reopen the dropdown.

I think, my review even improves usability more - and should not be much code, either.

What ryan also mentioned are the modifiers - which I also mentioned in my comment. On the one hand, this is really advanced JabRef usage - and could be done in a follow up. On the other hand, if you start implementing context menus, this could be "easily" doable maybe.

My main intent was to point out that the wording "All patterns" and "Create compound pattern" could be improved. The first is a noun phrase and the second is a verb phrase, which takes a little longer to process than if they are both the same. Example 1 is a suggestion that uses only verb-phrases while Examples 2 and 3 are alternatives that using only noun-phrases.

I also noticed that it might not be clear that "Create compound pattern" would need to be used repeatedly to create the pattern. If I recall correctly the phrase "Add to pattern" would not make sense because the user needs to first pick an initial pattern, then repeat the action to append to it.

Example 4 was an additional idea for potentially extending the proposal from priyanshu to become a "complete" pattern builder without requiring a dedicated window/form (because the proposal is already so close to providing this). I agree that if this is to be done, it can be a follow-up issue.

Edit: These ideas are also covered in a practical way by koppor's remarks in #12580 (review)

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.

5 participants