Skip to content

Enable casing for adding fields for entry types #9945

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

Closed
wants to merge 7 commits into from
Closed
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We moved the option to run JabRef in memory stick mode into the preferences dialog toolbar. [#9866](https://github.com/JabRef/jabref/pull/9866)
- In case the library contains empty entries, they are not written to disk. [#8645](https://github.com/JabRef/jabref/issues/8645)
- The formatter `remove_unicode_ligatures` is now called `replace_unicode_ligatures`. [#9890](https://github.com/JabRef/jabref/pull/9890)

- We enabled casing when adding custom field for entry type. [#9840](https://github.com/JabRef/jabref/issues/9840)

### Fixed

Expand Down Expand Up @@ -318,6 +318,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We replaced the [OttoBib](https://en.wikipedia.org/wiki/OttoBib) fetcher by a fetcher by [OpenLibrary](https://openlibrary.org/dev/docs/api/books). [#8652](https://github.com/JabRef/jabref/issues/8652)
- We first fetch ISBN data from OpenLibrary, if nothing found, ebook.de is tried.
- We now only show a warning when exiting for tasks that will not be recovered automatically upon relaunch of JabRef. [#8468](https://github.com/JabRef/jabref/issues/8468)
- We enabled casing when adding field for entry type. [#9840](https://github.com/JabRef/jabref/issues/9840)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please no two entries for the same fix. Decide for fix or feature. I think, feature is enough.


### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import org.jabref.model.entry.field.InternalField;
import org.jabref.model.entry.field.SpecialField;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UnknownField;
import org.jabref.model.strings.StringUtil;

public class FieldNameLabel extends Label {

public FieldNameLabel(Field field) {
super(field.getDisplayName());
super(field.getDisplayNameForField());

setPadding(new Insets(4, 0, 0, 0));
setAlignment(Pos.CENTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public String getDisplayName() {
return fields.getDisplayName();
}


private ObservableValue<String> getFieldValue(BibEntryTableViewModel entry) {
if (fields.isEmpty()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public CustomEntryTypesTabViewModel(BibDatabaseMode mode,
ValidationMessage.error(Localization.lang("Entry type cannot be empty. Please enter a name.")));
fieldValidator = new FunctionBasedValidator<>(
newFieldToAdd,
input -> input != null && StringUtil.isNotBlank(input.getDisplayName()),
input -> input != null && StringUtil.isNotBlank(input.getDisplayNameForField()),
ValidationMessage.error(Localization.lang("Field cannot be empty. Please enter a name.")));
}

Expand Down Expand Up @@ -146,7 +146,7 @@ public void addNewField() {
Field field = newFieldToAdd.getValue();
ObservableList<FieldViewModel> entryFields = this.selectedEntryType.getValue().fields();
boolean fieldExists = entryFields.stream().anyMatch(fieldViewModel ->
fieldViewModel.nameProperty().getValue().equals(field.getDisplayName()));
fieldViewModel.nameProperty().getValue().equals(field.getDisplayNameForField()));

if (!fieldExists) {
this.selectedEntryType.getValue().addField(new FieldViewModel(
Expand All @@ -157,7 +157,7 @@ public void addNewField() {
} else {
dialogService.showWarningDialogAndWait(
Localization.lang("Duplicate fields"),
Localization.lang("Warning: You added field \"%0\" twice. Only one will be kept.", field.getDisplayName()));
Localization.lang("Warning: You added field \"%0\" twice. Only one will be kept.", field.getDisplayNameForField()));
}
newFieldToAddProperty().setValue(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public FieldViewModel(Field field,
FieldPriority priorityProperty,
boolean multiline) {
this.field = field;
this.fieldName.setValue(field.getDisplayName());
this.fieldName.setValue(field.getDisplayNameForField());
this.required.setValue(required == Mandatory.REQUIRED);
this.priorityProperty.setValue(priorityProperty);
this.multiline.setValue(multiline);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/util/FieldsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FieldsUtil {
@Override
public String toString(Field object) {
if (object != null) {
return object.getDisplayName();
return object.getDisplayNameForField();
} else {
return "";
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/model/entry/field/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ default String getDisplayName() {
return StringUtil.capitalizeFirst(getName());
}

default String getDisplayNameForField() {
return getName();
}

String getName();

boolean isStandardField();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/jabref/model/entry/field/OrFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public String getDisplayName() {
return joiner.toString();
}

public String getDisplayNameForField() {
StringJoiner joiner = new StringJoiner("/");
for (Field field : this) {
joiner.add(field.getDisplayNameForField());
}
return joiner.toString();
}
public Field getPrimary() {
return this.iterator().next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ void addsNewField() {
assertTrue(fieldsContainTestValue);
}

@Test
void addsNewFieldWithCaseInsensitiveName() {
UnknownField testField = new UnknownField("tEst");
addFieldForUnknownField(testField);

ListProperty<Field> fields = viewModel.getFieldNamesBackingList();
boolean fieldsContainTestValue = fields.stream().anyMatch(field -> "tEst".equals(field.getDisplayNameForField()));

assertTrue(fieldsContainTestValue);
}

@Test
void removesField() {
UnknownField testField = new UnknownField("Test");
Expand Down Expand Up @@ -153,6 +164,13 @@ private void addField(Field field) {
viewModel.showInputFieldNameDialog();
}

private void addFieldForUnknownField(Field field) {
when(dialogService.showInputDialogAndWait(
Localization.lang("Add new field name"), Localization.lang("Field name:")))
.thenReturn(Optional.of(field.getDisplayNameForField()));

viewModel.showInputFieldNameDialog();
}
private void removeField(Field field) {
when(dialogService.showConfirmationDialogAndWait(
Localization.lang("Remove field name"),
Expand Down