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 editing typo with double clicking on field name in custom entry type #9977

Merged
merged 15 commits into from
Jun 8, 2023
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,23 @@ private void setupFieldsTable() {
fieldNameColumn.setEditable(true);
fieldNameColumn.setOnEditCommit(
(TableColumn.CellEditEvent<FieldViewModel, String> event) -> {
// This makes the displayed name consistent to org.jabref.model.entry.field.Field #getDisplayName()
String newFieldValue = StringUtil.capitalizeFirst(event.getNewValue());
DinjerChang marked this conversation as resolved.
Show resolved Hide resolved
UnknownField field = (UnknownField) event.getRowValue().getField();
EntryTypeViewModel selectedEntryType = viewModel.selectedEntryTypeProperty().get();
ObservableList<FieldViewModel> entryFields = selectedEntryType.fields();
// The second predicate will check if the user input the original field name or doesn't edit anything after double click
boolean fieldExists = entryFields.stream().anyMatch(fieldViewModel ->
fieldViewModel.nameProperty().getValue().equalsIgnoreCase(newFieldValue));
fieldViewModel.nameProperty().getValue().equalsIgnoreCase(newFieldValue) && !newFieldValue.equals(field.getDisplayName()));
Copy link
Member

Choose a reason for hiding this comment

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

The new condition does not make use of ´fieldViewModel `

I think, following code matches your intention:

boolean fieldExists = !newFieldValue.equals(field.getDisplayName()) && entryFields.stream().anyMatch(fieldViewModel ->
                            fieldViewModel.nameProperty().getValue().equalsIgnoreCase(newFieldValue));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I shouldn't put it in the anyMatch() method when streaming


if (!fieldExists) {
event.getRowValue().setField(newFieldValue);
field.setName(newFieldValue);
} else {
if (fieldExists) {
dialogService.notify(Localization.lang("Duplicate fields: You added field \"%0\" twice. Only one will be kept.", newFieldValue));
event.getTableView().edit(-1, null);
event.getTableView().refresh();
} else {
event.getRowValue().setField(newFieldValue);
field.setName(newFieldValue);
event.getTableView().refresh();
}
});

Expand Down