Skip to content

Commit

Permalink
Fix "Other fields" tab respecting custom tabs (#11012)
Browse files Browse the repository at this point in the history
* The entry editor respects the configured additional tabs when showing "Other fields".

* Streamline code of OtherFieldsTab#determineFieldsToShow

* Fix wording

* Update CHANGELOG.md
  • Loading branch information
koppor authored Mar 12, 2024
1 parent 4c64706 commit 6f57cfe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where the preview panel showing the wrong entry (an entry that is not selected in the entry table). [#9172](https://github.com/JabRef/jabref/issues/9172)
- We fixed an issue where HTML-reserved characters like '&' and '<', in addition to HTML entities like '&amp;' were not rendered correctly in entry preview. [#10677](https://github.com/JabRef/jabref/issues/10677)
- The last page of a PDF is now indexed by the full text search. [#10193](https://github.com/JabRef/jabref/issues/10193)
- The entry editor respects the configured custom tabs when showing "Other fields". [#11012](https://github.com/JabRef/jabref/pull/11012)
- The default owner of an entry can be changed again. [#10924](https://github.com/JabRef/jabref/issues/10924)
- We fixed an issue where the duplicate check did not take umlauts or other LaTeX-encoded characters into account. [#10744](https://github.com/JabRef/jabref/pull/10744)
- We fixed the colors of the icon on hover for unset special fields. [#10431](https://github.com/JabRef/jabref/issues/10431)
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/org/jabref/gui/entryeditor/OtherFieldsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.BibField;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.InternalField;
import org.jabref.model.entry.field.StandardField;
Expand All @@ -36,7 +35,7 @@
public class OtherFieldsTab extends FieldsEditorTab {

public static final String NAME = "Other fields";
private final List<Field> customTabFieldNames;
private final List<Field> customTabsFieldNames;
private final BibEntryTypesManager entryTypesManager;

public OtherFieldsTab(BibDatabaseContext databaseContext,
Expand All @@ -63,8 +62,8 @@ public OtherFieldsTab(BibDatabaseContext databaseContext,
indexingTaskManager);

this.entryTypesManager = entryTypesManager;
this.customTabFieldNames = new ArrayList<>();
preferences.getEntryEditorPreferences().getDefaultEntryEditorTabs().values().forEach(customTabFieldNames::addAll);
this.customTabsFieldNames = new ArrayList<>();
preferences.getEntryEditorPreferences().getEntryEditorTabs().values().forEach(customTabsFieldNames::addAll);

setText(Localization.lang("Other fields"));
setTooltip(new Tooltip(Localization.lang("Show remaining fields")));
Expand All @@ -76,15 +75,21 @@ protected SequencedSet<Field> determineFieldsToShow(BibEntry entry) {
BibDatabaseMode mode = databaseContext.getMode();
Optional<BibEntryType> entryType = entryTypesManager.enrich(entry.getType(), mode);
if (entryType.isPresent()) {
// Get all required and optional fields configured for the entry
Set<Field> allKnownFields = entryType.get().getAllFields();
// Remove all fields being required or optional
SequencedSet<Field> otherFields = entry.getFields().stream()
.filter(field -> !allKnownFields.contains(field) &&
!(field.equals(StandardField.COMMENT) || field instanceof UserSpecificCommentField))
.filter(field -> !allKnownFields.contains(field))
.collect(Collectors.toCollection(LinkedHashSet::new));
otherFields.removeAll(entryType.get().getDeprecatedFields(mode));
otherFields.removeAll(entryType.get().getOptionalFields().stream().map(BibField::field).toList());
// The key field is in the required tab, but has a special treatment
otherFields.remove(InternalField.KEY_FIELD);
customTabFieldNames.forEach(otherFields::remove);
// Remove all fields contained in JabRef's tab "Deprecated"
otherFields.removeAll(entryType.get().getDeprecatedFields(mode));
// Remove all fields contained in the custom tabs
customTabsFieldNames.forEach(otherFields::remove);
// Remove all user-comment fields (tab org.jabref.gui.entryeditor.CommentsTab)
otherFields.removeIf(field -> field.equals(StandardField.COMMENT));
otherFields.removeIf(field -> field instanceof UserSpecificCommentField);
return otherFields;
} else {
// Entry type unknown -> treat all fields as required (thus no other fields)
Expand Down

0 comments on commit 6f57cfe

Please sign in to comment.