-
-
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
Merged
+286
−4
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1618eec
Add a suggestions text field
priyanshu16095 7597467
Improve text field and make use of CitationKeyPattern record
priyanshu16095 1b819f9
Fix the check
priyanshu16095 b8527aa
Change a comment
priyanshu16095 88965e9
Make the fields private
priyanshu16095 40ce160
Make remaining fields private
priyanshu16095 948a495
Fix the check
priyanshu16095 b874dfd
Make fields public again
priyanshu16095 fac8fbc
Fix the UI issue
priyanshu16095 7a61dad
Update CitationKeyPattern.java
priyanshu16095 ed42bcc
Define the MAX_ENTRIES variable
priyanshu16095 43292ba
Merge branch 'main' into addDropdown
subhramit 249229b
Add submenu and improve suggestions
priyanshu16095 4dff9f2
Add pattern in Java record
priyanshu16095 10522b4
Fix the check
priyanshu16095 58ef2f4
Add setOnAction on menu item
priyanshu16095 539c1fd
Add a CHANGELOG.md entry
priyanshu16095 6f235c9
Fix the issue
priyanshu16095 353f1bd
Add keys in JabRef_en.properties
priyanshu16095 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternSuggestionCell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.jabref.gui.commonfxcontrols; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.scene.control.ListView; | ||
import javafx.scene.control.TextField; | ||
import javafx.scene.control.cell.TextFieldTableCell; | ||
import javafx.stage.Popup; | ||
|
||
public class CitationKeyPatternSuggestionCell extends TextFieldTableCell<CitationKeyPatternsPanelItemModel, String> { | ||
private final TextField searchField = new TextField(); | ||
private final ListView<String> suggestionList = new ListView<>(); | ||
private final Popup popup = new Popup(); | ||
|
||
private final List<String> fullData; | ||
|
||
public CitationKeyPatternSuggestionCell(List<String> fullData) { | ||
this.fullData = fullData; | ||
popup.getContent().add(suggestionList); | ||
popup.setAutoHide(true); | ||
|
||
searchField.textProperty().addListener((obs, oldVal, newVal) -> { | ||
List<String> filtered = fullData.stream() | ||
.filter(item -> item.toLowerCase().contains(newVal.toLowerCase())) | ||
.collect(Collectors.toList()); | ||
|
||
suggestionList.setItems(FXCollections.observableArrayList(filtered)); | ||
if (!filtered.isEmpty()) { | ||
popup.show(searchField, searchField.localToScreen(0, searchField.getHeight()).getX(), | ||
searchField.localToScreen(0, searchField.getHeight() * 2).getY()); | ||
} else { | ||
popup.hide(); | ||
} | ||
}); | ||
|
||
suggestionList.setOnMouseClicked(event -> { | ||
String selected = suggestionList.getSelectionModel().getSelectedItem(); | ||
if (selected != null) { | ||
searchField.setText(selected); | ||
popup.hide(); | ||
} | ||
}); | ||
|
||
searchField.setOnAction(event -> commitEdit(searchField.getText())); | ||
} | ||
|
||
@Override | ||
public void startEdit() { | ||
super.startEdit(); | ||
searchField.setText(getItem()); | ||
setGraphic(searchField); | ||
searchField.requestFocus(); | ||
} | ||
|
||
@Override | ||
public void cancelEdit() { | ||
super.cancelEdit(); | ||
setGraphic(null); | ||
popup.hide(); | ||
} | ||
|
||
@Override | ||
public void commitEdit(String newValue) { | ||
super.commitEdit(newValue); | ||
getTableView().getItems().get(getIndex()).setPattern(newValue); | ||
setGraphic(null); | ||
} | ||
|
||
@Override | ||
public void updateItem(String item, boolean empty) { | ||
super.updateItem(item, empty); | ||
if (empty || item == null) { | ||
setGraphic(null); | ||
setText(null); | ||
} else { | ||
setText(item); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
.//region - citation key patterns offered. for any new pattern, add them here
and// endregion
below.getAllPatterns
, see if this works (I chatgpt'd this snippet - make any modifications needed):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!