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

Fixed duplicate fields assigned to entry types #8391

Merged
merged 8 commits into from
Jan 12, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where clicking on headings in the entry preview could lead to an exception. [#8292](https://github.com/JabRef/jabref/issues/8292)
- We fixed an issue where IntegrityCheck used the system's character encoding instead of the one set by the library or in preferences [#8022](https://github.com/JabRef/jabref/issues/8022)
- We fixed an issue about empty metadata in library properties when called from the right click menu. [#8358](https://github.com/JabRef/jabref/issues/8358)
- We fixed an issue where someone could add a duplicate field in the customize entry type dialog. [#8194](https://github.com/JabRef/jabref/issues/8194)
- We fixed a typo in the library properties tab: "String constants". There, one can configure [BibTeX string constants](https://docs.jabref.org/advanced/strings).

### Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javafx.collections.ObservableList;
import javafx.util.StringConverter;

import org.jabref.gui.DialogService;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntryType;
Expand Down Expand Up @@ -59,14 +60,16 @@ public Field fromString(String string) {

private final PreferencesService preferencesService;
private final BibEntryTypesManager entryTypesManager;
private final DialogService dialogService;

private final Validator entryTypeValidator;
private final Validator fieldValidator;

public CustomEntryTypeDialogViewModel(BibDatabaseMode mode, PreferencesService preferencesService, BibEntryTypesManager entryTypesManager) {
public CustomEntryTypeDialogViewModel(BibDatabaseMode mode, PreferencesService preferencesService, BibEntryTypesManager entryTypesManager, DialogService dialogService) {
this.mode = mode;
this.preferencesService = preferencesService;
this.entryTypesManager = entryTypesManager;
this.dialogService = dialogService;

addAllTypes();

Expand Down Expand Up @@ -126,7 +129,14 @@ public String toString() {
public void addNewField() {
Field field = newFieldToAdd.getValue();
FieldViewModel model = new FieldViewModel(field, true, FieldPriority.IMPORTANT);
this.selectedEntryType.getValue().addField(model);
ObservableList<FieldViewModel> entryFields = this.selectedEntryType.getValue().fields();
boolean fieldExists = entryFields.stream().anyMatch(fieldViewModel -> fieldViewModel.fieldName().getValue().equals(field.getDisplayName()));

if (!fieldExists) {
this.selectedEntryType.getValue().addField(model);
} else {
dialogService.showWarningDialogAndWait(Localization.lang("Duplicate fields"), Localization.lang("Warning: You added field \"%0\" twice. Only one will be kept.", field.getDisplayName()));
}
newFieldToAddProperty().setValue(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void initialize() {
// As the state manager gets injected it's not available in the constructor
this.localDragboard = stateManager.getLocalDragboard();

viewModel = new CustomEntryTypeDialogViewModel(mode, preferencesService, entryTypesManager);
viewModel = new CustomEntryTypeDialogViewModel(mode, preferencesService, entryTypesManager, dialogService);
setupTable();

addNewEntryTypeButton.disableProperty().bind(viewModel.entryTypeValidationStatus().validProperty().not());
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ Downloaded\ website\ as\ an\ HTML\ file.=Downloaded website as an HTML file.

duplicate\ removal=duplicate removal

Duplicate\ fields=Duplicate fields

Duplicate\ string\ name=Duplicate string name

Duplicates\ found=Duplicates found
Expand Down Expand Up @@ -902,6 +904,8 @@ Warning=Warning

Warnings=Warnings

Warning\:\ You\ added\ field\ "%0"\ twice.\ Only\ one\ will\ be\ kept.=Warning: You added field "%0" twice. Only one will be kept.

web\ link=web link

What\ do\ you\ want\ to\ do?=What do you want to do?
Expand Down