Skip to content

Commit

Permalink
Merge branch 'fix-7757' into bibtex-month-not-deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Dec 18, 2022
2 parents 4ad9b65 + e6b4bed commit 771c16c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed


- The tab "deprecated fields" is shown in biblatex-mode only. [#7757](https://github.com/JabRef/jabref/issues/7757)



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.jabref.model.entry.field.Field;
import org.jabref.preferences.PreferencesService;

import com.tobiasdiez.easybind.EasyBind;

public class DeprecatedFieldsTab extends FieldsEditorTab {

private final BibEntryTypesManager entryTypesManager;
Expand All @@ -45,7 +47,13 @@ public DeprecatedFieldsTab(BibDatabaseContext databaseContext,
this.entryTypesManager = entryTypesManager;

setText(Localization.lang("Deprecated fields"));
setTooltip(new Tooltip(Localization.lang("Show deprecated BibTeX fields")));
EasyBind.subscribe(preferences.getGeneralPreferences().showAdvancedHintsProperty(), advancedHints -> {
if (advancedHints) {
setTooltip(new Tooltip(Localization.lang("Shows fields having a successor in biblatex.\nFor instance, the publication month should be part of the date field.\nUse the Cleanup Entries functionality to convert the entry to biblatex.")));
} else {
setTooltip(new Tooltip(Localization.lang("Shows fields having a successor in biblatex.")));
}
});
setGraphic(IconTheme.JabRefIcons.OPTIONAL.getGraphicNode());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ConvertToBiblatexCleanup implements CleanupJob {
@Override
public List<FieldChange> cleanup(BibEntry entry) {
List<FieldChange> changes = new ArrayList<>();
for (Map.Entry<Field, Field> alias : EntryConverter.FIELD_ALIASES_TEX_TO_LTX.entrySet()) {
for (Map.Entry<Field, Field> alias : EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX.entrySet()) {
Field oldField = alias.getKey();
Field newField = alias.getValue();
entry.getField(oldField).ifPresent(oldValue -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public List<FieldChange> cleanup(BibEntry entry) {
}
});

for (Map.Entry<Field, Field> alias : EntryConverter.FIELD_ALIASES_TEX_TO_LTX.entrySet()) {
for (Map.Entry<Field, Field> alias : EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX.entrySet()) {
Field oldField = alias.getValue();
Field newField = alias.getKey();
entry.getField(oldField).ifPresent(oldValue -> {
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/jabref/model/entry/BibEntryType.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ public Set<Field> getDeprecatedFields(BibDatabaseMode mode) {
deprecatedFields = new LinkedHashSet<>(EntryConverter.FIELD_ALIASES_LTX_TO_TEX.keySet());
}

// Only the optional fields which are mapped to another BibLaTeX name should be shown as "deprecated"
deprecatedFields.retainAll(getOptionalFieldsAndAliases());

// BibLaTeX aims for that field "date" is used
// Thus, year + month is deprecated
// However, year is used in the wild very often, so we do not mark that as default as deprecated
deprecatedFields.add(StandardField.MONTH);

return deprecatedFields;
}

Expand All @@ -105,14 +111,14 @@ public Set<Field> getSecondaryOptionalNotDeprecatedFields(BibDatabaseMode mode)
}

/**
* Get list of all optional fields of this entry and their aliases.
* Get list of all optional fields of this entry and all fields being source for a BibTeX to BibLaTeX conversion.
*/
private Set<Field> getOptionalFieldsAndAliases() {
Set<Field> optionalFieldsAndAliases = new LinkedHashSet<>(getOptionalFields().size());
for (BibField field : getOptionalFields()) {
optionalFieldsAndAliases.add(field.getField());
if (EntryConverter.FIELD_ALIASES_LTX_TO_TEX.containsKey(field.getField())) {
optionalFieldsAndAliases.add(EntryConverter.FIELD_ALIASES_LTX_TO_TEX.get(field.getField()));
if (EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX.containsKey(field.getField())) {
optionalFieldsAndAliases.add(field.getField());
}
}
return optionalFieldsAndAliases;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public InternalEntryTypes(List<BibEntryType> standardTypes) {

/**
* This method returns the BibtexEntryType for the name of a type,
* or null if it does not exist.
* or an empty optional if it does not exist.
*/
public Optional<BibEntryType> enrich(EntryType type) {
Optional<BibEntryType> enrichedType = customOrModifiedType.stream()
Expand Down
28 changes: 13 additions & 15 deletions src/main/java/org/jabref/model/entry/EntryConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,32 @@
*/
public class EntryConverter {

// BibTeX to biblatex
public static Map<Field, Field> FIELD_ALIASES_TEX_TO_LTX;
public static Map<Field, Field> FIELD_ALIASES_BIBTEX_TO_BIBLATEX;

// biblatex to BibTeX
public static Map<Field, Field> FIELD_ALIASES_LTX_TO_TEX;
public static Map<Field, Field> FIELD_ALIASES_BIBLATEX_TO_BIBTEX;

// All aliases
public static Map<Field, Field> FIELD_ALIASES;

static {
EntryConverter.FIELD_ALIASES_TEX_TO_LTX = new HashMap<>();
EntryConverter.FIELD_ALIASES_TEX_TO_LTX.put(StandardField.ADDRESS, StandardField.LOCATION);
EntryConverter.FIELD_ALIASES_TEX_TO_LTX.put(StandardField.ANNOTE, StandardField.ANNOTATION);
EntryConverter.FIELD_ALIASES_TEX_TO_LTX.put(StandardField.ARCHIVEPREFIX, StandardField.EPRINTTYPE);
EntryConverter.FIELD_ALIASES_TEX_TO_LTX.put(StandardField.JOURNAL, StandardField.JOURNALTITLE);
EntryConverter.FIELD_ALIASES_TEX_TO_LTX.put(StandardField.KEY, StandardField.SORTKEY);
EntryConverter.FIELD_ALIASES_TEX_TO_LTX.put(StandardField.PRIMARYCLASS, StandardField.EPRINTCLASS);
EntryConverter.FIELD_ALIASES_TEX_TO_LTX.put(StandardField.SCHOOL, StandardField.INSTITUTION);
EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX = new HashMap<>();
EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX.put(StandardField.ADDRESS, StandardField.LOCATION);
EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX.put(StandardField.ANNOTE, StandardField.ANNOTATION);
EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX.put(StandardField.ARCHIVEPREFIX, StandardField.EPRINTTYPE);
EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX.put(StandardField.JOURNAL, StandardField.JOURNALTITLE);
EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX.put(StandardField.KEY, StandardField.SORTKEY);
EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX.put(StandardField.PRIMARYCLASS, StandardField.EPRINTCLASS);
EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX.put(StandardField.SCHOOL, StandardField.INSTITUTION);

// inverse map
EntryConverter.FIELD_ALIASES_LTX_TO_TEX = EntryConverter.FIELD_ALIASES_TEX_TO_LTX
EntryConverter.FIELD_ALIASES_BIBLATEX_TO_BIBTEX = EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX
.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));

// all aliases
FIELD_ALIASES = new HashMap<>();
FIELD_ALIASES.putAll(EntryConverter.FIELD_ALIASES_TEX_TO_LTX);
FIELD_ALIASES.putAll(EntryConverter.FIELD_ALIASES_LTX_TO_TEX);
FIELD_ALIASES.putAll(EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX);
FIELD_ALIASES.putAll(EntryConverter.FIELD_ALIASES_BIBLATEX_TO_BIBTEX);
}

private EntryConverter() {
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,10 @@ Convert\ to\ biblatex\ format\ (e.g.,\ store\ publication\ date\ in\ date\ field
Convert\ to\ BibTeX\ format\ (e.g.,\ store\ publication\ date\ in\ year\ and\ month\ fields)=Convert to BibTeX format (e.g., store publication date in year and month fields)

Deprecated\ fields=Deprecated fields
Shows\ fields\ having\ a\ successor\ in\ biblatex.=Shows fields having a successor in biblatex.
Shows\ fields\ having\ a\ successor\ in\ biblatex.\nFor\ instance,\ the\ publication\ month\ should\ be\ part\ of\ the\ date\ field.\nUse\ the\ Cleanup\ Entries\ functionality\ to\ convert\ the\ entry\ to\ biblatex.=Shows fields having a successor in biblatex.\nFor instance, the publication month should be part of the date field.\n Use the Cleanup Entries functionality to convert the entry to biblatex.


No\ read\ status\ information=No read status information
Printed=Printed
Read\ status=Read status
Expand All @@ -1291,7 +1295,6 @@ Read\ status\ skimmed=Read status skimmed
Save\ selected\ as\ plain\ BibTeX...=Save selected as plain BibTeX...
Set\ read\ status\ to\ read=Set read status to read
Set\ read\ status\ to\ skimmed=Set read status to skimmed
Show\ deprecated\ BibTeX\ fields=Show deprecated BibTeX fields

Opens\ JabRef's\ GitHub\ page=Opens JabRef's GitHub page
Opens\ JabRef's\ Twitter\ page=Opens JabRef's Twitter page
Expand Down

0 comments on commit 771c16c

Please sign in to comment.