Skip to content

Commit

Permalink
Fixed duplicate fields assigned to entry types (#8391)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrisdimos00 authored Jan 12, 2022
1 parent 9e3506f commit 9b8f17b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
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

0 comments on commit 9b8f17b

Please sign in to comment.