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

Bibtex month not deprecated #9404

Merged
merged 9 commits into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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
16 changes: 13 additions & 3 deletions src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
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 @@ -44,15 +47,22 @@ 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());
}

@Override
protected Set<Field> determineFieldsToShow(BibEntry entry) {
Optional<BibEntryType> entryType = entryTypesManager.enrich(entry.getType(), databaseContext.getMode());
BibDatabaseMode mode = databaseContext.getMode();
Optional<BibEntryType> entryType = entryTypesManager.enrich(entry.getType(), mode);
if (entryType.isPresent()) {
return entryType.get().getDeprecatedFields().stream().filter(field -> !entry.getField(field).isEmpty()).collect(Collectors.toSet());
return entryType.get().getDeprecatedFields(mode).stream().filter(field -> !entry.getField(field).isEmpty()).collect(Collectors.toSet());
} else {
// Entry type unknown -> treat all fields as required
return Collections.emptySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
Expand Down Expand Up @@ -61,12 +62,13 @@ public OptionalFieldsTabBase(String title,

@Override
protected Set<Field> determineFieldsToShow(BibEntry entry) {
Optional<BibEntryType> entryType = entryTypesManager.enrich(entry.getType(), databaseContext.getMode());
BibDatabaseMode mode = databaseContext.getMode();
Optional<BibEntryType> entryType = entryTypesManager.enrich(entry.getType(), mode);
if (entryType.isPresent()) {
if (isPrimaryOptionalFields) {
return entryType.get().getPrimaryOptionalFields();
} else {
return entryType.get().getSecondaryOptionalNotDeprecatedFields();
return entryType.get().getSecondaryOptionalNotDeprecatedFields(mode);
}
} else {
// Entry type unknown -> treat all fields as required
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/jabref/gui/entryeditor/OtherFieldsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
Expand Down Expand Up @@ -67,12 +68,13 @@ public OtherFieldsTab(BibDatabaseContext databaseContext,

@Override
protected Set<Field> determineFieldsToShow(BibEntry entry) {
Optional<BibEntryType> entryType = entryTypesManager.enrich(entry.getType(), databaseContext.getMode());
BibDatabaseMode mode = databaseContext.getMode();
Optional<BibEntryType> entryType = entryTypesManager.enrich(entry.getType(), mode);
if (entryType.isPresent()) {
Set<Field> allKnownFields = entryType.get().getAllFields();
Set<Field> otherFields = entry.getFields().stream().filter(field -> !allKnownFields.contains(field)).collect(Collectors.toCollection(LinkedHashSet::new));

otherFields.removeAll(entryType.get().getDeprecatedFields());
otherFields.removeAll(entryType.get().getDeprecatedFields(mode));
otherFields.removeAll(entryType.get().getOptionalFields().stream().map(BibField::getField).collect(Collectors.toSet()));
otherFields.remove(InternalField.KEY_FIELD);
otherFields.removeAll(customTabFieldNames);
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
26 changes: 17 additions & 9 deletions src/main/java/org/jabref/model/entry/BibEntryType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.field.BibField;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldPriority;
Expand Down Expand Up @@ -82,31 +83,38 @@ public Set<Field> getSecondaryOptionalFields() {
.collect(Collectors.toCollection(LinkedHashSet::new));
}

public Set<Field> getDeprecatedFields() {
Set<Field> deprecatedFields = new LinkedHashSet<>(EntryConverter.FIELD_ALIASES_TEX_TO_LTX.keySet());
deprecatedFields.add(StandardField.YEAR);
deprecatedFields.add(StandardField.MONTH);
public Set<Field> getDeprecatedFields(BibDatabaseMode mode) {
if (mode == BibDatabaseMode.BIBTEX) {
return Collections.emptySet();
}
Set<Field> deprecatedFields = new LinkedHashSet<>(EntryConverter.FIELD_ALIASES_BIBTEX_TO_BIBLATEX.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;
}

public Set<Field> getSecondaryOptionalNotDeprecatedFields() {
public Set<Field> getSecondaryOptionalNotDeprecatedFields(BibDatabaseMode mode) {
Set<Field> optionalFieldsNotPrimaryOrDeprecated = new LinkedHashSet<>(getSecondaryOptionalFields());
optionalFieldsNotPrimaryOrDeprecated.removeAll(getDeprecatedFields());
optionalFieldsNotPrimaryOrDeprecated.removeAll(getDeprecatedFields(mode));
return optionalFieldsNotPrimaryOrDeprecated;
}

/**
* 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());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the intention here? Now, for each optional field, we first add it to optionalFieldsAndAliases, and if it is contained in FIELD_ALIASES_BIBTEX_TO_BIBLATEX, then we add it a second time.

}
}
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.\nUse 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