diff --git a/jabgui/src/main/java/org/jabref/gui/newentry/NewEntryPreferences.java b/jabgui/src/main/java/org/jabref/gui/newentry/NewEntryPreferences.java index 99a75ab7904..978f78c7fb8 100644 --- a/jabgui/src/main/java/org/jabref/gui/newentry/NewEntryPreferences.java +++ b/jabgui/src/main/java/org/jabref/gui/newentry/NewEntryPreferences.java @@ -7,7 +7,10 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +import org.jabref.logic.importer.fetcher.DoiFetcher; +import org.jabref.logic.importer.plaincitation.PlainCitationParserChoice; import org.jabref.model.entry.types.EntryType; +import org.jabref.model.entry.types.StandardEntryType; public class NewEntryPreferences { private final ObjectProperty latestApproach; @@ -37,6 +40,34 @@ public NewEntryPreferences(NewEntryDialogTab approach, this.latestInterpretParserName = new SimpleStringProperty(interpretParserName); } + private NewEntryPreferences() { + this( + NewEntryDialogTab.CHOOSE_ENTRY_TYPE, // Default latest approach + true, // Default expanded recommended + false, // Default expanded other + true, // Default expanded custom + StandardEntryType.Article, // Default immediate type + true, // Default Id lookup guessing + DoiFetcher.NAME, // Default fetcher + PlainCitationParserChoice.RULE_BASED_GENERAL.getLocalizedName() // Default parser + ); + } + + public static NewEntryPreferences getDefault() { + return new NewEntryPreferences(); + } + + public void setAll(NewEntryPreferences other) { + this.latestApproach.set(other.getLatestApproach()); + this.typesRecommendedExpanded.set(other.getTypesRecommendedExpanded()); + this.typesOtherExpanded.set(other.getTypesOtherExpanded()); + this.typesCustomExpanded.set(other.getTypesCustomExpanded()); + this.latestImmediateType.set(other.getLatestImmediateType()); + this.idLookupGuessing.set(other.getIdLookupGuessing()); + this.latestIdFetcherName.set(other.getLatestIdFetcher()); + this.latestInterpretParserName.set(other.getLatestInterpretParser()); + } + public NewEntryDialogTab getLatestApproach() { return latestApproach.get(); } diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java b/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java index 7c7feef8f2d..8bebd6bc266 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java @@ -55,8 +55,6 @@ import org.jabref.logic.exporter.SelfContainedSaveConfiguration; import org.jabref.logic.externalfiles.DateRange; import org.jabref.logic.externalfiles.ExternalFileSorter; -import org.jabref.logic.importer.fetcher.DoiFetcher; -import org.jabref.logic.importer.plaincitation.PlainCitationParserChoice; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.TextBasedPreviewLayout; @@ -362,17 +360,6 @@ private JabRefGuiPreferences() { defaults.put(ASK_FOR_INCLUDING_CROSS_REFERENCES, Boolean.TRUE); defaults.put(INCLUDE_CROSS_REFERENCES, Boolean.FALSE); - - // region NewEntryUnifierPreferences - defaults.put(CREATE_ENTRY_APPROACH, List.of(NewEntryDialogTab.values()).indexOf(NewEntryDialogTab.CHOOSE_ENTRY_TYPE)); - defaults.put(CREATE_ENTRY_EXPAND_RECOMMENDED, true); - defaults.put(CREATE_ENTRY_EXPAND_OTHER, false); - defaults.put(CREATE_ENTRY_EXPAND_CUSTOM, true); - defaults.put(CREATE_ENTRY_IMMEDIATE_TYPE, StandardEntryType.Article.getDisplayName()); - defaults.put(CREATE_ENTRY_ID_LOOKUP_GUESSING, true); - defaults.put(CREATE_ENTRY_ID_FETCHER_NAME, DoiFetcher.NAME); - defaults.put(CREATE_ENTRY_INTERPRET_PARSER_NAME, PlainCitationParserChoice.RULE_BASED_GENERAL.getLocalizedName()); - // endregion } /** @@ -410,6 +397,7 @@ public void clear() throws BackingStoreException { getWorkspacePreferences().setAll(WorkspacePreferences.getDefault()); getGuiPreferences().setAll(CoreGuiPreferences.getDefault()); getDonationPreferences().setAll(DonationPreferences.getDefault()); + getNewEntryPreferences().setAll(NewEntryPreferences.getDefault()); } @Override @@ -420,6 +408,7 @@ public void importPreferences(Path file) throws JabRefException { getWorkspacePreferences().setAll(getWorkspacePreferencesFromBackingStore(getWorkspacePreferences())); getGuiPreferences().setAll(getCoreGuiPreferencesFromBackingStore(getGuiPreferences())); getDonationPreferences().setAll(getDonationPreferencesFromBackingStore(getDonationPreferences())); + getNewEntryPreferences().setAll(getNewEntryPreferencesFromBackingStore(getNewEntryPreferences())); } // region EntryEditorPreferences @@ -1173,12 +1162,27 @@ public NewEntryPreferences getNewEntryPreferences() { return newEntryPreferences; } - final int approachIndex = getInt(CREATE_ENTRY_APPROACH); + newEntryPreferences = getNewEntryPreferencesFromBackingStore(NewEntryPreferences.getDefault()); + + EasyBind.listen(newEntryPreferences.latestApproachProperty(), (_, _, newValue) -> putInt(CREATE_ENTRY_APPROACH, List.of(NewEntryDialogTab.values()).indexOf(newValue))); + EasyBind.listen(newEntryPreferences.typesRecommendedExpandedProperty(), (_, _, newValue) -> putBoolean(CREATE_ENTRY_EXPAND_RECOMMENDED, newValue)); + EasyBind.listen(newEntryPreferences.typesOtherExpandedProperty(), (_, _, newValue) -> putBoolean(CREATE_ENTRY_EXPAND_OTHER, newValue)); + EasyBind.listen(newEntryPreferences.typesCustomExpandedProperty(), (_, _, newValue) -> putBoolean(CREATE_ENTRY_EXPAND_CUSTOM, newValue)); + EasyBind.listen(newEntryPreferences.latestImmediateTypeProperty(), (_, _, newValue) -> put(CREATE_ENTRY_IMMEDIATE_TYPE, newValue.getDisplayName())); + EasyBind.listen(newEntryPreferences.idLookupGuessingProperty(), (_, _, newValue) -> putBoolean(CREATE_ENTRY_ID_LOOKUP_GUESSING, newValue)); + EasyBind.listen(newEntryPreferences.latestIdFetcherProperty(), (_, _, newValue) -> put(CREATE_ENTRY_ID_FETCHER_NAME, newValue)); + EasyBind.listen(newEntryPreferences.latestInterpretParserProperty(), (_, _, newValue) -> put(CREATE_ENTRY_INTERPRET_PARSER_NAME, newValue)); + + return newEntryPreferences; + } + + private NewEntryPreferences getNewEntryPreferencesFromBackingStore(NewEntryPreferences defaults) { + final int approachIndex = getInt(CREATE_ENTRY_APPROACH, List.of(NewEntryDialogTab.values()).indexOf(defaults.getLatestApproach())); NewEntryDialogTab approach = NewEntryDialogTab.values().length > approachIndex ? NewEntryDialogTab.values()[approachIndex] : NewEntryDialogTab.values()[0]; - final String immediateTypeName = get(CREATE_ENTRY_IMMEDIATE_TYPE); + final String immediateTypeName = get(CREATE_ENTRY_IMMEDIATE_TYPE, defaults.getLatestImmediateType().getDisplayName()); EntryType immediateType = StandardEntryType.Article; for (StandardEntryType type : StandardEntryType.values()) { if (type.getDisplayName().equals(immediateTypeName)) { @@ -1187,26 +1191,16 @@ public NewEntryPreferences getNewEntryPreferences() { } } - newEntryPreferences = new NewEntryPreferences( + return new NewEntryPreferences( approach, - getBoolean(CREATE_ENTRY_EXPAND_RECOMMENDED), - getBoolean(CREATE_ENTRY_EXPAND_OTHER), - getBoolean(CREATE_ENTRY_EXPAND_CUSTOM), + getBoolean(CREATE_ENTRY_EXPAND_RECOMMENDED, defaults.getTypesRecommendedExpanded()), + getBoolean(CREATE_ENTRY_EXPAND_OTHER, defaults.getTypesOtherExpanded()), + getBoolean(CREATE_ENTRY_EXPAND_CUSTOM, defaults.getTypesCustomExpanded()), immediateType, - getBoolean(CREATE_ENTRY_ID_LOOKUP_GUESSING), - get(CREATE_ENTRY_ID_FETCHER_NAME), - get(CREATE_ENTRY_INTERPRET_PARSER_NAME)); - - EasyBind.listen(newEntryPreferences.latestApproachProperty(), (_, _, newValue) -> putInt(CREATE_ENTRY_APPROACH, List.of(NewEntryDialogTab.values()).indexOf(newValue))); - EasyBind.listen(newEntryPreferences.typesRecommendedExpandedProperty(), (_, _, newValue) -> putBoolean(CREATE_ENTRY_EXPAND_RECOMMENDED, newValue)); - EasyBind.listen(newEntryPreferences.typesOtherExpandedProperty(), (_, _, newValue) -> putBoolean(CREATE_ENTRY_EXPAND_OTHER, newValue)); - EasyBind.listen(newEntryPreferences.typesCustomExpandedProperty(), (_, _, newValue) -> putBoolean(CREATE_ENTRY_EXPAND_CUSTOM, newValue)); - EasyBind.listen(newEntryPreferences.latestImmediateTypeProperty(), (_, _, newValue) -> put(CREATE_ENTRY_IMMEDIATE_TYPE, newValue.getDisplayName())); - EasyBind.listen(newEntryPreferences.idLookupGuessingProperty(), (_, _, newValue) -> putBoolean(CREATE_ENTRY_ID_LOOKUP_GUESSING, newValue)); - EasyBind.listen(newEntryPreferences.latestIdFetcherProperty(), (_, _, newValue) -> put(CREATE_ENTRY_ID_FETCHER_NAME, newValue)); - EasyBind.listen(newEntryPreferences.latestInterpretParserProperty(), (_, _, newValue) -> put(CREATE_ENTRY_INTERPRET_PARSER_NAME, newValue)); - - return newEntryPreferences; + getBoolean(CREATE_ENTRY_ID_LOOKUP_GUESSING, defaults.getIdLookupGuessing()), + get(CREATE_ENTRY_ID_FETCHER_NAME, defaults.getLatestIdFetcher()), + get(CREATE_ENTRY_INTERPRET_PARSER_NAME, defaults.getLatestInterpretParser()) + ); } // region Donation preferences