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

Enable casing for entry types #9883

Closed
wants to merge 6 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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)

### 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.getDisplayName2());

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.getDisplayName2()),
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.getDisplayName2()));

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.getDisplayName2()));
}
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.getDisplayName2());
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.getDisplayName2();
} 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 getDisplayName2() {
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 getDisplayName2() {
StringJoiner joiner = new StringJoiner("/");
for (Field field : this) {
joiner.add(field.getDisplayName2());
}
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.getDisplayName2()));

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.getDisplayName2()));

viewModel.showInputFieldNameDialog();
}
private void removeField(Field field) {
when(dialogService.showConfirmationDialogAndWait(
Localization.lang("Remove field name"),
Expand Down
22 changes: 22 additions & 0 deletions sxkeychain erase
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
credential.helper=osxkeychain
init.defaultbranch=main
user.name=eric052199
[email protected]
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.upstream.url=https://github.com/JabRef/jabref.git
remote.upstream.fetch=+refs/heads/main:refs/remotes/upstream/main
branch.main.remote=upstream
branch.main.merge=refs/heads/main
remote.origin.url=https://github.com/eric052199/jabref.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.eric-dev.remote=origin
branch.eric-dev.merge=refs/heads/eric-dev
Comment on lines +1 to +22
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be an artifact of you working on your PR?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, i'm not really sure what this is about. Do i need to remove this?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, remove this