diff --git a/CHANGELOG.md b/CHANGELOG.md index fe7c548e02f..3755fa4c39c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java index d063c3c0994..ab51c2f7390 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java @@ -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; @@ -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(); @@ -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 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); } diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java index cc85bf98c87..7a4973cf8e2 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java @@ -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()); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 51561772656..2b7f8ecc5bd 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -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 @@ -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?