diff --git a/src/main/java/org/jabref/preferences/GeneralPreferences.java b/src/main/java/org/jabref/preferences/GeneralPreferences.java index 1383e6c11b4..30c24d58ed7 100644 --- a/src/main/java/org/jabref/preferences/GeneralPreferences.java +++ b/src/main/java/org/jabref/preferences/GeneralPreferences.java @@ -28,6 +28,27 @@ public GeneralPreferences(BibDatabaseMode defaultBibDatabaseMode, this.showAdvancedHints = new SimpleBooleanProperty(showAdvancedHints); } + /** + * Creates Object with default values + */ + public GeneralPreferences() { + this(BibDatabaseMode.BIBTEX, + true, + true, + false, + true + ); + } + + public void setDefaults() { + GeneralPreferences defaults = new GeneralPreferences(); + this.defaultBibDatabaseMode.setValue(defaults.getDefaultBibDatabaseMode()); + this.warnAboutDuplicatesInInspection.setValue(defaults.shouldWarnAboutDuplicatesInInspection()); + this.confirmDelete.setValue(shouldConfirmDelete()); + this.memoryStickMode.setValue(defaults.isMemoryStickMode()); + this.showAdvancedHints.setValue(defaults.shouldShowAdvancedHints()); + } + public BibDatabaseMode getDefaultBibDatabaseMode() { return defaultBibDatabaseMode.get(); } @@ -40,11 +61,11 @@ public void setDefaultBibDatabaseMode(BibDatabaseMode defaultBibDatabaseMode) { this.defaultBibDatabaseMode.set(defaultBibDatabaseMode); } - public boolean warnAboutDuplicatesInInspection() { + public boolean shouldWarnAboutDuplicatesInInspection() { return warnAboutDuplicatesInInspection.get(); } - public BooleanProperty isWarnAboutDuplicatesInInspectionProperty() { + public BooleanProperty warnAboutDuplicatesInInspectionProperty() { return warnAboutDuplicatesInInspection; } @@ -87,4 +108,41 @@ public BooleanProperty showAdvancedHintsProperty() { public void setShowAdvancedHints(boolean showAdvancedHints) { this.showAdvancedHints.set(showAdvancedHints); } + + public static class Builder { + private final GeneralPreferences toBuild; + + public Builder() { + toBuild = new GeneralPreferences(); + } + + public Builder withDefaultBibDatabaseMode(BibDatabaseMode defaultBibDatabaseMode) { + toBuild.setDefaultBibDatabaseMode(defaultBibDatabaseMode); + return this; + } + + public Builder withWarnAboutDuplicatesInInspection(boolean warnAboutDuplicatesInInspection) { + toBuild.setWarnAboutDuplicatesInInspection(warnAboutDuplicatesInInspection); + return this; + } + + public Builder withConfirmDelete(boolean confirmDelete) { + toBuild.setConfirmDelete(confirmDelete); + return this; + } + + public Builder withMemoryStickMode(boolean memoryStickMode) { + toBuild.setMemoryStickMode(memoryStickMode); + return this; + } + + public Builder withShowAdvancedHints(boolean showAdvancedHints) { + toBuild.setShowAdvancedHints(showAdvancedHints); + return this; + } + + public GeneralPreferences build() { + return toBuild; + } + } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 52c9746abba..1fee446e412 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -496,8 +496,6 @@ private JabRefPreferences() { defaults.put(PUSH_VIM_SERVER, "vim"); defaults.put(PUSH_EMACS_ADDITIONAL_PARAMETERS, "-n -e"); - defaults.put(BIBLATEX_DEFAULT_MODE, Boolean.FALSE); - // Set DOI to be the default ID entry generator defaults.put(ID_ENTRY_GENERATOR, DoiFetcher.NAME); @@ -601,10 +599,7 @@ private JabRefPreferences() { defaults.put(DISPLAY_GROUP_COUNT, Boolean.TRUE); defaults.put(GROUP_INTERSECT_UNION_VIEW_MODE, GroupViewMode.INTERSECTION.name()); defaults.put(KEYWORD_SEPARATOR, ", "); - defaults.put(DEFAULT_ENCODING, StandardCharsets.UTF_8.name()); defaults.put(DEFAULT_OWNER, System.getProperty("user.name")); - defaults.put(MEMORY_STICK_MODE, Boolean.FALSE); - defaults.put(SHOW_ADVANCED_HINTS, Boolean.TRUE); defaults.put(EXTRA_FILE_COLUMNS, Boolean.FALSE); @@ -637,13 +632,11 @@ private JabRefPreferences() { defaults.put(OVERWRITE_OWNER, Boolean.FALSE); defaults.put(AVOID_OVERWRITING_KEY, Boolean.FALSE); defaults.put(WARN_BEFORE_OVERWRITING_KEY, Boolean.TRUE); - defaults.put(CONFIRM_DELETE, Boolean.TRUE); defaults.put(DEFAULT_CITATION_KEY_PATTERN, "[auth][year]"); defaults.put(UNWANTED_CITATION_KEY_CHARACTERS, "-`สน:!;?^+"); defaults.put(RESOLVE_STRINGS_FOR_FIELDS, "author;booktitle;editor;editora;editorb;editorc;institution;issuetitle;journal;journalsubtitle;journaltitle;mainsubtitle;month;publisher;shortauthor;shorteditor;subtitle;titleaddon"); defaults.put(DO_NOT_RESOLVE_STRINGS, Boolean.FALSE); defaults.put(NON_WRAPPABLE_FIELDS, "pdf;ps;url;doi;file;isbn;issn"); - defaults.put(WARN_ABOUT_DUPLICATES_IN_INSPECTION, Boolean.TRUE); defaults.put(ADD_CREATION_DATE, Boolean.FALSE); defaults.put(ADD_MODIFICATION_DATE, Boolean.FALSE); @@ -959,6 +952,9 @@ public void clear() throws BackingStoreException { clearCitationKeyPatterns(); clearTruststoreFromCustomCertificates(); prefs.clear(); + + generalPreferences.setDefaults(); + new SharedDatabasePreferences().clear(); } @@ -1309,15 +1305,16 @@ public GeneralPreferences getGeneralPreferences() { return generalPreferences; } - generalPreferences = new GeneralPreferences( - getBoolean(BIBLATEX_DEFAULT_MODE) ? BibDatabaseMode.BIBLATEX : BibDatabaseMode.BIBTEX, - getBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION), - getBoolean(CONFIRM_DELETE), - getBoolean(MEMORY_STICK_MODE), - getBoolean(SHOW_ADVANCED_HINTS)); + generalPreferences = new GeneralPreferences.Builder() + .withDefaultBibDatabaseMode(getBoolean(BIBLATEX_DEFAULT_MODE) ? BibDatabaseMode.BIBLATEX : BibDatabaseMode.BIBTEX) + .withWarnAboutDuplicatesInInspection(getBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION)) + .withConfirmDelete(getBoolean(CONFIRM_DELETE)) + .withMemoryStickMode(getBoolean(MEMORY_STICK_MODE)) + .withShowAdvancedHints(getBoolean(SHOW_ADVANCED_HINTS)) + .build(); EasyBind.listen(generalPreferences.defaultBibDatabaseModeProperty(), (obs, oldValue, newValue) -> putBoolean(BIBLATEX_DEFAULT_MODE, (newValue == BibDatabaseMode.BIBLATEX))); - EasyBind.listen(generalPreferences.isWarnAboutDuplicatesInInspectionProperty(), (obs, oldValue, newValue) -> putBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION, newValue)); + EasyBind.listen(generalPreferences.warnAboutDuplicatesInInspectionProperty(), (obs, oldValue, newValue) -> putBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION, newValue)); EasyBind.listen(generalPreferences.confirmDeleteProperty(), (obs, oldValue, newValue) -> putBoolean(CONFIRM_DELETE, newValue)); EasyBind.listen(generalPreferences.memoryStickModeProperty(), (obs, oldValue, newValue) -> putBoolean(MEMORY_STICK_MODE, newValue)); EasyBind.listen(generalPreferences.showAdvancedHintsProperty(), (obs, oldValue, newValue) -> putBoolean(SHOW_ADVANCED_HINTS, newValue));