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
Show file tree
Hide file tree
Changes from 8 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 @@ -96,6 +96,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixen an issue under Linux where under some systems the file instead of the folder was openend [#9607](https://github.com/JabRef/jabref/issues/9607)
- We fixed an issue where an Automatic Keyword Group could not be deleted in the UI. [#9778](https://github.com/JabRef/jabref/issues/9778)
- We fixed an issue where the citation key pattern `[edtrN_M]` returned the wrong editor. [#9946](https://github.com/JabRef/jabref/pull/9946)
- We fixed an issue where allow user to update the value of field in custom entry type with double-clicking it. [#9840](https://github.com/JabRef/jabref/issues/9840)


### Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javafx.application.Platform;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.Group;
import javafx.scene.control.Button;
Expand All @@ -12,6 +13,7 @@
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.CheckBoxTableCell;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
Expand All @@ -33,6 +35,8 @@
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.UnknownField;
import org.jabref.model.strings.StringUtil;

import com.airhacks.afterburner.views.ViewLoader;
import com.tobiasdiez.easybind.EasyBind;
Expand Down Expand Up @@ -143,6 +147,26 @@ private void setupEntryTypesTable() {

private void setupFieldsTable() {
fieldNameColumn.setCellValueFactory(item -> item.getValue().nameProperty());
fieldNameColumn.setCellFactory(TextFieldTableCell.forTableColumn());
fieldNameColumn.setEditable(true);
fieldNameColumn.setOnEditCommit(
(TableColumn.CellEditEvent<FieldViewModel, String> event) -> {
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();
boolean fieldExists = entryFields.stream().anyMatch(fieldViewModel ->
fieldViewModel.nameProperty().getValue().equalsIgnoreCase(newFieldValue));

if (!fieldExists) {
event.getRowValue().setField(newFieldValue);
field.setName(newFieldValue);
} else {
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();
}
DinjerChang marked this conversation as resolved.
Show resolved Hide resolved
});

fieldTypeColumn.setCellFactory(CheckBoxTableCell.forTableColumn(fieldTypeColumn));
fieldTypeColumn.setCellValueFactory(item -> item.getValue().requiredProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public FieldPriority getPriority() {
return priorityProperty.getValue();
}

public void setField(String field) {
this.fieldName.setValue(field);
}

public BibField toBibField() {
return new BibField(field, priorityProperty.getValue());
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/model/entry/field/UnknownField.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Set;

public class UnknownField implements Field {
private final String name;
private String name;
private final Set<FieldProperty> properties;

public UnknownField(String name) {
Expand All @@ -29,6 +29,10 @@ public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public boolean isStandardField() {
return false;
Expand Down
2 changes: 2 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 @@ duplicate\ removal=duplicate removal

Duplicate\ fields=Duplicate fields

Duplicate\ fields\:\ You\ added\ field\ "%0"\ twice.\ Only\ one\ will\ be\ kept.=Duplicate fields: You added field "%0" twice. Only one will be kept.

Duplicate\ string\ name=Duplicate string name

Duplicates\ found=Duplicates found
Expand Down