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 selection box for content selectors next to keyword field #2

Open
wants to merge 2 commits into
base: jabrefmain
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where opening the menu 'Library properties' marked the library as modified [#6451](https://github.com/JabRef/jabref/issues/6451)
- We fixed an issue when importing resulted in an exception [#7343](https://github.com/JabRef/jabref/issues/7343)
- We fixed an issue where the field in the Field formatter dropdown selection were sorted in random order. [#7710](https://github.com/JabRef/jabref/issues/7710)
- We added a selection box next to the keywords field, The list is filled with the contents of the content selectors, excluding existing keywords. [#10560](https://github.com/JabRef/jabref/issues/10560)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static FieldEditorFX getForField(final Field field,
} else if (fieldProperties.contains(FieldProperty.PERSON_NAMES)) {
return new PersonsEditor(field, suggestionProvider, preferences, fieldCheckers, isMultiLine, undoManager);
} else if (StandardField.KEYWORDS == field) {
return new KeywordsEditor(field, suggestionProvider, fieldCheckers, preferences, undoManager);
return new KeywordsEditor(field, suggestionProvider, fieldCheckers, preferences, undoManager, databaseContext);
} else if (field == InternalField.KEY_FIELD) {
return new CitationKeyEditor(field, suggestionProvider, fieldCheckers, databaseContext);
} else {
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/org/jabref/gui/fieldeditors/KeywordsEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,39 @@

import javax.swing.undo.UndoManager;

import javafx.scene.control.ComboBox;

import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.logic.integrity.FieldCheckers;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;
import org.jabref.preferences.PreferencesService;

public class KeywordsEditor extends SimpleEditor implements FieldEditorFX {

private final BibDatabaseContext databaseContext;
private ComboBox<String> keywordsComboBox;
public KeywordsEditor(Field field,
SuggestionProvider<?> suggestionProvider,
FieldCheckers fieldCheckers,
PreferencesService preferences,
UndoManager undoManager) {
UndoManager undoManager,
BibDatabaseContext databaseContext) {
super(field, suggestionProvider, fieldCheckers, preferences, undoManager);
this.databaseContext = databaseContext;
this.keywordsComboBox = createKeywordsComboBox();
this.getChildren().add(keywordsComboBox);
}

@Override
public double getWeight() {
return 2;
}

private ComboBox<String> createKeywordsComboBox() {
ComboBox<String> comboBox = new ComboBox<>();
comboBox.getItems().addAll(databaseContext.getMetaData().getContentSelectorValuesForField(StandardField.KEYWORDS));
return comboBox;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private void removeFieldName() {
@FXML
private void addNewKeyword() {
getSelectedField().ifPresent(viewModel::showInputKeywordDialog);

}

@FXML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ void showInputKeywordDialog(Field selectedField) {
.ifPresent(newKeyword -> addKeywordIfUnique(selectedField, newKeyword));
}


private void addKeywordIfUnique(Field field, String keywordToAdd) {
boolean exists = fieldKeywordsMap.get(field).contains(keywordToAdd);
if (exists) {
Expand Down