Skip to content

Commit 5ca1ad8

Browse files
DinjerChangkoppor
andauthored
Enable editing typo with double clicking on field name in custom entry type (#9977)
Co-authored-by: Oliver Kopp <[email protected]>
1 parent d1aa6ed commit 5ca1ad8

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
3232
- We added support for parsing MathML in the Medline importer. [#4273](https://github.com/JabRef/jabref/issues/4273)
3333
- We added the ability to search for a DOI directly from 'Web Search'. [#9674](https://github.com/JabRef/jabref/issues/9674)
3434
- We added a cleanup activity that identifies a URL in the `note` field and moves it to the `url` field. [koppor#216](https://github.com/koppor/jabref/issues/216)
35+
- We enabled the user to change the name of a field in a custom entry type by double-clicking on it. [#9840](https://github.com/JabRef/jabref/issues/9840)
36+
3537

3638
### Changed
3739

src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTab.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import javafx.application.Platform;
44
import javafx.beans.property.ReadOnlyStringWrapper;
5+
import javafx.collections.ObservableList;
56
import javafx.fxml.FXML;
67
import javafx.scene.Group;
78
import javafx.scene.control.Button;
@@ -12,6 +13,7 @@
1213
import javafx.scene.control.TableView;
1314
import javafx.scene.control.TextField;
1415
import javafx.scene.control.cell.CheckBoxTableCell;
16+
import javafx.scene.control.cell.TextFieldTableCell;
1517
import javafx.scene.input.ClipboardContent;
1618
import javafx.scene.input.DragEvent;
1719
import javafx.scene.input.Dragboard;
@@ -33,6 +35,8 @@
3335
import org.jabref.model.database.BibDatabaseMode;
3436
import org.jabref.model.entry.BibEntryTypesManager;
3537
import org.jabref.model.entry.field.Field;
38+
import org.jabref.model.entry.field.UnknownField;
39+
import org.jabref.model.strings.StringUtil;
3640

3741
import com.airhacks.afterburner.views.ViewLoader;
3842
import com.tobiasdiez.easybind.EasyBind;
@@ -143,6 +147,29 @@ private void setupEntryTypesTable() {
143147

144148
private void setupFieldsTable() {
145149
fieldNameColumn.setCellValueFactory(item -> item.getValue().nameProperty());
150+
fieldNameColumn.setCellFactory(TextFieldTableCell.forTableColumn());
151+
fieldNameColumn.setEditable(true);
152+
fieldNameColumn.setOnEditCommit(
153+
(TableColumn.CellEditEvent<FieldViewModel, String> event) -> {
154+
// This makes the displayed name consistent to org.jabref.model.entry.field.Field #getDisplayName()
155+
String newFieldValue = StringUtil.capitalizeFirst(event.getNewValue());
156+
UnknownField field = (UnknownField) event.getRowValue().getField();
157+
EntryTypeViewModel selectedEntryType = viewModel.selectedEntryTypeProperty().get();
158+
ObservableList<FieldViewModel> entryFields = selectedEntryType.fields();
159+
// The first predicate will check if the user input the original field name or doesn't edit anything after double click
160+
boolean fieldExists = !newFieldValue.equals(field.getDisplayName()) && entryFields.stream().anyMatch(fieldViewModel ->
161+
fieldViewModel.nameProperty().getValue().equalsIgnoreCase(newFieldValue));
162+
163+
if (fieldExists) {
164+
dialogService.notify(Localization.lang("Unable to change field name. \"%0\" already in use.", newFieldValue));
165+
event.getTableView().edit(-1, null);
166+
event.getTableView().refresh();
167+
} else {
168+
event.getRowValue().setField(newFieldValue);
169+
field.setName(newFieldValue);
170+
event.getTableView().refresh();
171+
}
172+
});
146173

147174
fieldTypeColumn.setCellFactory(CheckBoxTableCell.forTableColumn(fieldTypeColumn));
148175
fieldTypeColumn.setCellValueFactory(item -> item.getValue().requiredProperty());

src/main/java/org/jabref/gui/preferences/customentrytypes/FieldViewModel.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public FieldPriority getPriority() {
7070
return priorityProperty.getValue();
7171
}
7272

73+
public void setField(String field) {
74+
this.fieldName.setValue(field);
75+
}
76+
7377
public BibField toBibField() {
7478
return new BibField(field, priorityProperty.getValue());
7579
}

src/main/java/org/jabref/model/entry/field/UnknownField.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.Set;
77

88
public class UnknownField implements Field {
9-
private final String name;
9+
private String name;
1010
private final Set<FieldProperty> properties;
1111

1212
public UnknownField(String name) {
@@ -29,6 +29,10 @@ public String getName() {
2929
return name;
3030
}
3131

32+
public void setName(String name) {
33+
this.name = name;
34+
}
35+
3236
@Override
3337
public boolean isStandardField() {
3438
return false;

src/main/resources/l10n/JabRef_en.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ duplicate\ removal=duplicate removal
275275

276276
Duplicate\ fields=Duplicate fields
277277

278+
Unable\ to\ change\ field\ name\.\ "%0"\ already\ in\ use.=Unable to change field name. "%0" already in use.
279+
278280
Duplicate\ string\ name=Duplicate string name
279281

280282
Duplicates\ found=Duplicates found

0 commit comments

Comments
 (0)