From b3fd154649ebdca4d5e8f8912e18f10586d75317 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage Date: Sat, 6 Nov 2021 10:05:38 +0100 Subject: [PATCH 1/4] Migrated SearchPreferences to new preferences model --- src/main/java/org/jabref/gui/JabRefFrame.java | 2 +- .../jabref/gui/search/GlobalSearchBar.java | 22 ++--- .../GlobalSearchResultDialogViewModel.java | 10 +- .../jabref/preferences/JabRefPreferences.java | 28 ++++-- .../preferences/PreferencesService.java | 2 - .../jabref/preferences/SearchPreferences.java | 95 +++++++++---------- 6 files changed, 79 insertions(+), 80 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 7a262d5981b..edbadbd77e0 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -595,7 +595,7 @@ public void init() { // Subscribe to the search EasyBind.subscribe(stateManager.activeSearchQueryProperty(), query -> { - if (prefs.getSearchPreferences().isKeepSearchString()) { + if (prefs.getSearchPreferences().shouldKeepSearchString()) { for (LibraryTab tab : getLibraryTabs()) { tab.setCurrentSearchQuery(query); } diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index ab2343e69ac..da016e1f219 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -2,6 +2,7 @@ import java.lang.reflect.Field; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -59,6 +60,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.logic.search.SearchQuery; import org.jabref.model.entry.Author; +import org.jabref.model.search.rules.SearchRules; import org.jabref.preferences.PreferencesService; import org.jabref.preferences.SearchPreferences; @@ -99,7 +101,7 @@ public class GlobalSearchBar extends HBox { private final Validator regexValidator; private final UndoManager undoManager; - private SearchPreferences searchPreferences; + private final SearchPreferences searchPreferences; private final BooleanProperty globalSearchActive = new SimpleBooleanProperty(false); private GlobalSearchResultDialog globalSearchResultDialog; @@ -204,8 +206,7 @@ private void initSearchModifierButtons() { regularExpressionButton.setTooltip(new Tooltip(Localization.lang("regular expression"))); initSearchModifierButton(regularExpressionButton); regularExpressionButton.setOnAction(event -> { - searchPreferences = searchPreferences.withRegularExpression(regularExpressionButton.isSelected()); - preferencesService.storeSearchPreferences(searchPreferences); + searchPreferences.setSearchFlag(SearchRules.SearchFlags.REGULAR_EXPRESSION, regularExpressionButton.isSelected()); performSearch(); }); @@ -213,8 +214,7 @@ private void initSearchModifierButtons() { caseSensitiveButton.setTooltip(new Tooltip(Localization.lang("Case sensitive"))); initSearchModifierButton(caseSensitiveButton); caseSensitiveButton.setOnAction(event -> { - searchPreferences = searchPreferences.withCaseSensitive(caseSensitiveButton.isSelected()); - preferencesService.storeSearchPreferences(searchPreferences); + searchPreferences.setSearchFlag(SearchRules.SearchFlags.CASE_SENSITIVE, caseSensitiveButton.isSelected()); performSearch(); }); @@ -222,17 +222,15 @@ private void initSearchModifierButtons() { fulltextButton.setTooltip(new Tooltip(Localization.lang("Fulltext search"))); initSearchModifierButton(fulltextButton); fulltextButton.setOnAction(event -> { - searchPreferences = searchPreferences.withFulltext(fulltextButton.isSelected()); - preferencesService.storeSearchPreferences(searchPreferences); + searchPreferences.setSearchFlag(SearchRules.SearchFlags.FULLTEXT, fulltextButton.isSelected()); performSearch(); }); - keepSearchString.setSelected(searchPreferences.isKeepSearchString()); + keepSearchString.setSelected(searchPreferences.shouldKeepSearchString()); keepSearchString.setTooltip(new Tooltip(Localization.lang("Keep search string across libraries"))); initSearchModifierButton(keepSearchString); keepSearchString.setOnAction(evt -> { - searchPreferences = searchPreferences.withKeepSearchString(keepSearchString.isSelected()); - preferencesService.storeSearchPreferences(searchPreferences); + searchPreferences.setSearchFlag(SearchRules.SearchFlags.KEEP_SEARCH_STRING, keepSearchString.isSelected()); performSearch(); }); @@ -390,7 +388,7 @@ public void setSearchTerm(String searchTerm) { DefaultTaskExecutor.runInJavaFXThread(() -> searchField.setText(searchTerm)); } - private class SearchPopupSkin implements Skin> { + private static class SearchPopupSkin implements Skin> { private final AutoCompletePopup control; private final ListView suggestionList; @@ -400,7 +398,7 @@ public SearchPopupSkin(AutoCompletePopup control) { this.control = control; this.suggestionList = new ListView<>(control.getSuggestions()); this.suggestionList.getStyleClass().add("auto-complete-popup"); - this.suggestionList.getStylesheets().add(AutoCompletionBinding.class.getResource("autocompletion.css").toExternalForm()); + this.suggestionList.getStylesheets().add(Objects.requireNonNull(AutoCompletionBinding.class.getResource("autocompletion.css")).toExternalForm()); this.suggestionList.prefHeightProperty().bind(Bindings.min(control.visibleRowCountProperty(), Bindings.size(this.suggestionList.getItems())).multiply(24).add(18)); this.suggestionList.setCellFactory(TextFieldListCell.forListView(control.getConverter())); this.suggestionList.prefWidthProperty().bind(control.prefWidthProperty()); diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchResultDialogViewModel.java b/src/main/java/org/jabref/gui/search/GlobalSearchResultDialogViewModel.java index caf3196472f..5f56ee04b5e 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchResultDialogViewModel.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchResultDialogViewModel.java @@ -13,17 +13,13 @@ public class GlobalSearchResultDialogViewModel { private final BibDatabaseContext searchDatabaseContext = new BibDatabaseContext(); private final BooleanProperty keepOnTop = new SimpleBooleanProperty(); - private SearchPreferences searchPreferences; public GlobalSearchResultDialogViewModel(PreferencesService preferencesService) { - searchPreferences = preferencesService.getSearchPreferences(); + SearchPreferences searchPreferences = preferencesService.getSearchPreferences(); - keepOnTop.set(searchPreferences.isKeepWindowOnTop()); + keepOnTop.set(searchPreferences.shouldKeepWindowOnTop()); - EasyBind.subscribe(this.keepOnTop, selected -> { - searchPreferences = searchPreferences.withKeepGlobalSearchDialogOnTop(selected); - preferencesService.storeSearchPreferences(searchPreferences); - }); + EasyBind.subscribe(this.keepOnTop, searchPreferences::setKeepWindowOnTop); } public BibDatabaseContext getSearchDatabaseContext() { diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index a4133ed6136..821a386de81 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -35,6 +35,7 @@ import java.util.stream.Stream; import javafx.beans.InvalidationListener; +import javafx.collections.SetChangeListener; import javafx.scene.control.TableColumn.SortType; import org.jabref.gui.Globals; @@ -108,6 +109,7 @@ import org.jabref.model.entry.types.EntryTypeFactory; import org.jabref.model.metadata.SaveOrderConfig; import org.jabref.model.push.PushToApplicationConstants; +import org.jabref.model.search.rules.SearchRules; import org.jabref.model.strings.StringUtil; import com.tobiasdiez.easybind.EasyBind; @@ -429,6 +431,7 @@ public class JabRefPreferences implements PreferencesService { private ProtectedTermsPreferences protectedTermsPreferences; private MrDlibPreferences mrDlibPreferences; private EntryEditorPreferences entryEditorPreferences; + private SearchPreferences searchPreferences; // The constructor is made private to enforce this as a singleton class: private JabRefPreferences() { @@ -2565,6 +2568,10 @@ public void clearEditedFiles() { @Override public SearchPreferences getSearchPreferences() { + if (Objects.nonNull(searchPreferences)) { + return searchPreferences; + } + SearchDisplayMode searchDisplayMode; try { searchDisplayMode = SearchDisplayMode.valueOf(get(SEARCH_DISPLAY_MODE)); @@ -2573,23 +2580,24 @@ public SearchPreferences getSearchPreferences() { searchDisplayMode = SearchDisplayMode.valueOf((String) defaults.get(SEARCH_DISPLAY_MODE)); } - return new SearchPreferences( + searchPreferences = new SearchPreferences( searchDisplayMode, getBoolean(SEARCH_CASE_SENSITIVE), getBoolean(SEARCH_REG_EXP), getBoolean(SEARCH_FULLTEXT), getBoolean(SEARCH_KEEP_SEARCH_STRING), getBoolean(SEARCH_KEEP_GLOBAL_WINDOW_ON_TOP)); - } - @Override - public void storeSearchPreferences(SearchPreferences preferences) { - put(SEARCH_DISPLAY_MODE, Objects.requireNonNull(preferences.getSearchDisplayMode()).toString()); - putBoolean(SEARCH_CASE_SENSITIVE, preferences.isCaseSensitive()); - putBoolean(SEARCH_REG_EXP, preferences.isRegularExpression()); - putBoolean(SEARCH_FULLTEXT, preferences.isFulltext()); - putBoolean(SEARCH_KEEP_SEARCH_STRING, preferences.isKeepSearchString()); - putBoolean(SEARCH_KEEP_GLOBAL_WINDOW_ON_TOP, preferences.isKeepWindowOnTop()); + EasyBind.listen(searchPreferences.searchDisplayModeProperty(), (obs, oldValue, newValue) -> put(SEARCH_DISPLAY_MODE, Objects.requireNonNull(searchPreferences.getSearchDisplayMode()).toString())); + searchPreferences.getObservableSearchFlags().addListener((SetChangeListener) c -> { + putBoolean(SEARCH_CASE_SENSITIVE, searchPreferences.getObservableSearchFlags().contains(SearchRules.SearchFlags.CASE_SENSITIVE)); + putBoolean(SEARCH_REG_EXP, searchPreferences.getObservableSearchFlags().contains(SearchRules.SearchFlags.REGULAR_EXPRESSION)); + putBoolean(SEARCH_FULLTEXT, searchPreferences.getObservableSearchFlags().contains(SearchRules.SearchFlags.FULLTEXT)); + putBoolean(SEARCH_KEEP_SEARCH_STRING, searchPreferences.getObservableSearchFlags().contains(SearchRules.SearchFlags.KEEP_SEARCH_STRING)); + }); + EasyBind.listen(searchPreferences.keepWindowOnTopProperty(), (obs, oldValue, newValue) -> putBoolean(SEARCH_KEEP_GLOBAL_WINDOW_ON_TOP, searchPreferences.shouldKeepWindowOnTop())); + + return searchPreferences; } //************************************************************************************************************* diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index cd098f23740..617af572793 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -335,8 +335,6 @@ public interface PreferencesService { SearchPreferences getSearchPreferences(); - void storeSearchPreferences(SearchPreferences preferences); - String getLastPreferencesExportPath(); void storeLastPreferencesExportPath(Path exportFile); diff --git a/src/main/java/org/jabref/preferences/SearchPreferences.java b/src/main/java/org/jabref/preferences/SearchPreferences.java index 036677de5b8..ea902bfe13b 100644 --- a/src/main/java/org/jabref/preferences/SearchPreferences.java +++ b/src/main/java/org/jabref/preferences/SearchPreferences.java @@ -2,20 +2,27 @@ import java.util.EnumSet; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableSet; + import org.jabref.gui.search.SearchDisplayMode; -import org.jabref.model.search.rules.SearchRules; import org.jabref.model.search.rules.SearchRules.SearchFlags; public class SearchPreferences { - private final SearchDisplayMode searchDisplayMode; - private final EnumSet searchFlags; - private final boolean keepWindowOnTop; + private final ObjectProperty searchDisplayMode; + private final ObservableSet searchFlags; + private final BooleanProperty keepWindowOnTop; public SearchPreferences(SearchDisplayMode searchDisplayMode, boolean isCaseSensitive, boolean isRegularExpression, boolean isFulltext, boolean isKeepSearchString, boolean keepWindowOnTop) { - this.searchDisplayMode = searchDisplayMode; - this.keepWindowOnTop = keepWindowOnTop; - searchFlags = EnumSet.noneOf(SearchFlags.class); + this.searchDisplayMode = new SimpleObjectProperty<>(searchDisplayMode); + this.keepWindowOnTop = new SimpleBooleanProperty(keepWindowOnTop); + + searchFlags = FXCollections.observableSet(EnumSet.noneOf(SearchFlags.class)); if (isCaseSensitive) { searchFlags.add(SearchFlags.CASE_SENSITIVE); } @@ -31,73 +38,65 @@ public SearchPreferences(SearchDisplayMode searchDisplayMode, boolean isCaseSens } public SearchPreferences(SearchDisplayMode searchDisplayMode, EnumSet searchFlags, boolean keepWindowOnTop) { - this.searchDisplayMode = searchDisplayMode; - this.searchFlags = searchFlags; - this.keepWindowOnTop = keepWindowOnTop; + this.searchDisplayMode = new SimpleObjectProperty<>(searchDisplayMode); + this.keepWindowOnTop = new SimpleBooleanProperty(keepWindowOnTop); + + this.searchFlags = FXCollections.observableSet(searchFlags); } - public SearchDisplayMode getSearchDisplayMode() { - return searchDisplayMode; + public EnumSet getSearchFlags() { + return EnumSet.copyOf(searchFlags); } - public boolean isCaseSensitive() { - return searchFlags.contains(SearchFlags.CASE_SENSITIVE); + protected ObservableSet getObservableSearchFlags() { + return searchFlags; } - public boolean isRegularExpression() { - return searchFlags.contains(SearchFlags.REGULAR_EXPRESSION); + public SearchDisplayMode getSearchDisplayMode() { + return searchDisplayMode.get(); } - public boolean isFulltext() { - return searchFlags.contains(SearchFlags.FULLTEXT); + public ObjectProperty searchDisplayModeProperty() { + return searchDisplayMode; } - public boolean isKeepSearchString() { - return searchFlags.contains(SearchFlags.KEEP_SEARCH_STRING); + public void setSearchDisplayMode(SearchDisplayMode searchDisplayMode) { + this.searchDisplayMode.set(searchDisplayMode); } - public boolean isKeepWindowOnTop() { - return keepWindowOnTop; + public boolean isCaseSensitive() { + return searchFlags.contains(SearchFlags.CASE_SENSITIVE); } - public EnumSet getSearchFlags() { - EnumSet searchFlags = EnumSet.noneOf(SearchFlags.class); - if (isCaseSensitive()) { - searchFlags.add(SearchRules.SearchFlags.CASE_SENSITIVE); - } - if (isRegularExpression()) { - searchFlags.add(SearchRules.SearchFlags.REGULAR_EXPRESSION); - } - if (isFulltext()) { - searchFlags.add(SearchRules.SearchFlags.FULLTEXT); - } - if (isKeepSearchString()) { - searchFlags.add(SearchRules.SearchFlags.KEEP_SEARCH_STRING); + public void setSearchFlag(SearchFlags flag, boolean value) { + if (searchFlags.contains(flag) && !value) { + searchFlags.remove(flag); + } else if (!searchFlags.contains(flag) && value) { + searchFlags.add(flag); } - return searchFlags; } - public SearchPreferences withSearchDisplayMode(SearchDisplayMode newSearchDisplayMode) { - return new SearchPreferences(newSearchDisplayMode, isCaseSensitive(), isRegularExpression(), isFulltext(), isKeepSearchString(), isKeepWindowOnTop()); + public boolean isRegularExpression() { + return searchFlags.contains(SearchFlags.REGULAR_EXPRESSION); } - public SearchPreferences withCaseSensitive(boolean newCaseSensitive) { - return new SearchPreferences(searchDisplayMode, newCaseSensitive, isRegularExpression(), isFulltext(), isKeepSearchString(), isKeepWindowOnTop()); + public boolean isFulltext() { + return searchFlags.contains(SearchFlags.FULLTEXT); } - public SearchPreferences withRegularExpression(boolean newRegularExpression) { - return new SearchPreferences(searchDisplayMode, isCaseSensitive(), newRegularExpression, isFulltext(), isKeepSearchString(), isKeepWindowOnTop()); + public boolean shouldKeepSearchString() { + return searchFlags.contains(SearchFlags.KEEP_SEARCH_STRING); } - public SearchPreferences withFulltext(boolean newFulltext) { - return new SearchPreferences(searchDisplayMode, isCaseSensitive(), isRegularExpression(), newFulltext, isKeepSearchString(), isKeepWindowOnTop()); + public boolean shouldKeepWindowOnTop() { + return keepWindowOnTop.get(); } - public SearchPreferences withKeepSearchString(boolean newKeepSearchString) { - return new SearchPreferences(searchDisplayMode, isCaseSensitive(), isRegularExpression(), isFulltext(), newKeepSearchString, isKeepWindowOnTop()); + public BooleanProperty keepWindowOnTopProperty() { + return keepWindowOnTop; } - public SearchPreferences withKeepGlobalSearchDialogOnTop(boolean keepWindowOnTop) { - return new SearchPreferences(searchDisplayMode, isCaseSensitive(), isRegularExpression(), isFulltext(), isKeepSearchString(), keepWindowOnTop); + public void setKeepWindowOnTop(boolean keepWindowOnTop) { + this.keepWindowOnTop.set(keepWindowOnTop); } } From 0b059686b7431fa51b93ee6f696a3501508dba6b Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage Date: Sat, 6 Nov 2021 13:43:39 +0100 Subject: [PATCH 2/4] Migrated AutoLinkPreferences to new preferences model --- .../org/jabref/gui/cleanup/CleanupAction.java | 3 +- .../linkedfiles/LinkedFilesTabViewModel.java | 15 ++--- .../logic/util/io/AutoLinkPreferences.java | 56 +++++++++++++++---- .../jabref/preferences/JabRefPreferences.java | 48 +++++++++------- .../preferences/PreferencesService.java | 2 - 5 files changed, 79 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java index abce5122c80..e9f3c634973 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java @@ -71,8 +71,7 @@ public void execute() { Localization.lang("Autogenerate PDF Names"), Localization.lang("Cancel"), Localization.lang("Do not ask again"), - optOut -> preferences.storeAutoLinkPreferences(preferences.getAutoLinkPreferences() - .withAskAutoNamingPdfs(!optOut))); + optOut -> preferences.getAutoLinkPreferences().setAskAutoNamingPdfs(!optOut)); if (!confirmed) { isCanceled = true; return; diff --git a/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java index 6cbb466c211..783f6069aca 100644 --- a/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java @@ -101,18 +101,15 @@ public void storeSettings() { filePreferences.setDownloadLinkedFiles(filePreferences.shouldDownloadLinkedFiles()); // set in ImportEntriesViewModel // Autolink preferences - AutoLinkPreferences.CitationKeyDependency citationKeyDependency = AutoLinkPreferences.CitationKeyDependency.START; - if (autolinkFileExactBibtexProperty.getValue()) { - citationKeyDependency = AutoLinkPreferences.CitationKeyDependency.EXACT; + if (autolinkFileStartsBibtexProperty.getValue()) { + preferences.getAutoLinkPreferences().setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.START); + } else if (autolinkFileExactBibtexProperty.getValue()) { + preferences.getAutoLinkPreferences().setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.EXACT); } else if (autolinkUseRegexProperty.getValue()) { - citationKeyDependency = AutoLinkPreferences.CitationKeyDependency.REGEX; + preferences.getAutoLinkPreferences().setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.REGEX); } - preferences.storeAutoLinkPreferences(new AutoLinkPreferences( - citationKeyDependency, - autolinkRegexKeyProperty.getValue(), - initialAutoLinkPreferences.shouldAskAutoNamingPdfs(), - preferences.getKeywordDelimiter())); + preferences.getAutoLinkPreferences().setRegularExpression(autolinkRegexKeyProperty.getValue()); } ValidationStatus mainFileDirValidationStatus() { diff --git a/src/main/java/org/jabref/logic/util/io/AutoLinkPreferences.java b/src/main/java/org/jabref/logic/util/io/AutoLinkPreferences.java index 58cb5d96972..09db96944c3 100644 --- a/src/main/java/org/jabref/logic/util/io/AutoLinkPreferences.java +++ b/src/main/java/org/jabref/logic/util/io/AutoLinkPreferences.java @@ -1,5 +1,12 @@ package org.jabref.logic.util.io; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + public class AutoLinkPreferences { public enum CitationKeyDependency { @@ -8,39 +15,66 @@ public enum CitationKeyDependency { REGEX // Filenames matching a regular expression pattern } - private final CitationKeyDependency citationKeyDependency; - private final String regularExpression; - private boolean askAutoNamingPdfs; - private final Character keywordDelimiter; + private final ObjectProperty citationKeyDependency; + private final StringProperty regularExpression; + private final BooleanProperty askAutoNamingPdfs; + private final SimpleObjectProperty keywordDelimiter; public AutoLinkPreferences(CitationKeyDependency citationKeyDependency, String regularExpression, boolean askAutoNamingPdfs, Character keywordDelimiter) { - this.citationKeyDependency = citationKeyDependency; - this.regularExpression = regularExpression; - this.askAutoNamingPdfs = askAutoNamingPdfs; - this.keywordDelimiter = keywordDelimiter; + this.citationKeyDependency = new SimpleObjectProperty<>(citationKeyDependency); + this.regularExpression = new SimpleStringProperty(regularExpression); + this.askAutoNamingPdfs = new SimpleBooleanProperty(askAutoNamingPdfs); + this.keywordDelimiter = new SimpleObjectProperty<>(keywordDelimiter); } public CitationKeyDependency getCitationKeyDependency() { + return citationKeyDependency.getValue(); + } + + public ObjectProperty citationKeyDependencyProperty() { return citationKeyDependency; } + public void setCitationKeyDependency(CitationKeyDependency citationKeyDependency) { + this.citationKeyDependency.set(citationKeyDependency); + } + public String getRegularExpression() { + return regularExpression.getValue(); + } + + public StringProperty regularExpressionProperty() { return regularExpression; } + public void setRegularExpression(String regularExpression) { + this.regularExpression.set(regularExpression); + } + public boolean shouldAskAutoNamingPdfs() { + return askAutoNamingPdfs.getValue(); + } + + public BooleanProperty askAutoNamingPdfsProperty() { return askAutoNamingPdfs; } - public AutoLinkPreferences withAskAutoNamingPdfs(boolean shouldAskAutoNamingPdfs) { - this.askAutoNamingPdfs = shouldAskAutoNamingPdfs; - return this; + public void setAskAutoNamingPdfs(boolean askAutoNamingPdfs) { + this.askAutoNamingPdfs.set(askAutoNamingPdfs); } public Character getKeywordDelimiter() { + return keywordDelimiter.getValue(); + } + + public SimpleObjectProperty keywordDelimiterProperty() { return keywordDelimiter; } + + public void setKeywordDelimiter(Character keywordDelimiter) { + this.keywordDelimiter.set(keywordDelimiter); + } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 381ca076613..9e224c08e8c 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -436,6 +436,7 @@ public class JabRefPreferences implements PreferencesService { private RemotePreferences remotePreferences; private ProxyPreferences proxyPreferences; private SearchPreferences searchPreferences; + private AutoLinkPreferences autoLinkPreferences; // The constructor is made private to enforce this as a singleton class: private JabRefPreferences() { @@ -2200,6 +2201,10 @@ public FilePreferences getFilePreferences() { @Override public AutoLinkPreferences getAutoLinkPreferences() { + if (Objects.nonNull(autoLinkPreferences)) { + return autoLinkPreferences; + } + AutoLinkPreferences.CitationKeyDependency citationKeyDependency = AutoLinkPreferences.CitationKeyDependency.START; // default if (getBoolean(AUTOLINK_EXACT_KEY_ONLY)) { @@ -2208,32 +2213,33 @@ public AutoLinkPreferences getAutoLinkPreferences() { citationKeyDependency = AutoLinkPreferences.CitationKeyDependency.REGEX; } - return new AutoLinkPreferences( + autoLinkPreferences = new AutoLinkPreferences( citationKeyDependency, get(AUTOLINK_REG_EXP_SEARCH_EXPRESSION_KEY), getBoolean(ASK_AUTO_NAMING_PDFS_AGAIN), getKeywordDelimiter()); - } - @Override - public void storeAutoLinkPreferences(AutoLinkPreferences preferences) { - // Starts bibtex only omitted, as it is not being saved - switch (preferences.getCitationKeyDependency()) { - case START -> { - putBoolean(AUTOLINK_EXACT_KEY_ONLY, false); - putBoolean(AUTOLINK_USE_REG_EXP_SEARCH_KEY, false); - } - case EXACT -> { - putBoolean(AUTOLINK_EXACT_KEY_ONLY, true); - putBoolean(AUTOLINK_USE_REG_EXP_SEARCH_KEY, false); - } - case REGEX -> { - putBoolean(AUTOLINK_EXACT_KEY_ONLY, false); - putBoolean(AUTOLINK_USE_REG_EXP_SEARCH_KEY, true); - } - } - putBoolean(ASK_AUTO_NAMING_PDFS_AGAIN, preferences.shouldAskAutoNamingPdfs()); - put(AUTOLINK_REG_EXP_SEARCH_EXPRESSION_KEY, preferences.getRegularExpression()); + EasyBind.listen(autoLinkPreferences.citationKeyDependencyProperty(), (obs, oldValue, newValue) -> { + // Starts bibtex only omitted, as it is not being saved + switch (newValue) { + case START -> { + putBoolean(AUTOLINK_EXACT_KEY_ONLY, false); + putBoolean(AUTOLINK_USE_REG_EXP_SEARCH_KEY, false); + } + case EXACT -> { + putBoolean(AUTOLINK_EXACT_KEY_ONLY, true); + putBoolean(AUTOLINK_USE_REG_EXP_SEARCH_KEY, false); + } + case REGEX -> { + putBoolean(AUTOLINK_EXACT_KEY_ONLY, false); + putBoolean(AUTOLINK_USE_REG_EXP_SEARCH_KEY, true); + } + } + }); + EasyBind.listen(autoLinkPreferences.askAutoNamingPdfsProperty(), (obs, oldValue, newValue) -> putBoolean(ASK_AUTO_NAMING_PDFS_AGAIN, newValue)); + EasyBind.listen(autoLinkPreferences.regularExpressionProperty(), (obs, oldValue, newValue) -> put(AUTOLINK_REG_EXP_SEARCH_EXPRESSION_KEY, newValue)); + + return autoLinkPreferences; } @Override diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 259d260ed43..43a8d6e6d9d 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -244,8 +244,6 @@ public interface PreferencesService { AutoLinkPreferences getAutoLinkPreferences(); - void storeAutoLinkPreferences(AutoLinkPreferences autoLinkPreferences); - boolean shouldAutosave(); void storeShouldAutosave(boolean shouldAutosave); From 404d633e6f2c5d7a205a1bb62934cc5cabba23a6 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage Date: Sat, 6 Nov 2021 15:02:43 +0100 Subject: [PATCH 3/4] Migrated ImportExportPreferences to new preferences model --- .../CreateModifyExporterDialogViewModel.java | 4 +- .../jabref/gui/exporter/ExportCommand.java | 5 +- .../gui/exporter/ExportToClipboardAction.java | 3 +- .../jabref/gui/importer/ImportCommand.java | 2 +- .../preferences/file/FileTabViewModel.java | 36 +++--- .../preferences/ImportExportPreferences.java | 118 ++++++++++++++---- .../jabref/preferences/JabRefPreferences.java | 42 +++---- .../preferences/PreferencesService.java | 4 - 8 files changed, 134 insertions(+), 80 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 7b51f7c425e..994602ddc92 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -56,9 +56,7 @@ public CreateModifyExporterDialogViewModel(ExporterViewModel exporter, DialogSer public ExporterViewModel saveExporter() { Path layoutFileDir = Path.of(layoutFile.get()).getParent(); if (layoutFileDir != null) { - String layoutFileDirString = layoutFileDir.toString(); - preferences.storeImportExportPreferences( - preferences.getImportExportPreferences().withExportWorkingDirectory(Path.of(layoutFileDirString))); + preferences.getImportExportPreferences().setExportWorkingDirectory(layoutFileDir); } // Check that there are no empty strings. diff --git a/src/main/java/org/jabref/gui/exporter/ExportCommand.java b/src/main/java/org/jabref/gui/exporter/ExportCommand.java index b5fad2c3885..005267ac841 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCommand.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCommand.java @@ -98,9 +98,8 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt // Make sure we remember which filter was used, to set // the default for next time: - preferences.storeImportExportPreferences(preferences.getImportExportPreferences() - .withLastExportExtension(format.getName()) - .withExportWorkingDirectory(file.getParent())); + preferences.getImportExportPreferences().setLastExportExtension(format.getName()); + preferences.getImportExportPreferences().setExportWorkingDirectory(file.getParent()); final List finEntries = entries; BackgroundTask diff --git a/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java b/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java index 81f8e58ad75..456c32fb8bb 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java +++ b/src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java @@ -110,8 +110,7 @@ private ExportResult exportToClipboard(Exporter exporter) throws Exception { .getFileDirectories(preferences.getFilePreferences())); // Add chosen export type to last used preference, to become default - preferences.storeImportExportPreferences( - preferences.getImportExportPreferences().withLastExportExtension(exporter.getName())); + preferences.getImportExportPreferences().setLastExportExtension(exporter.getName()); Path tmp = null; try { diff --git a/src/main/java/org/jabref/gui/importer/ImportCommand.java b/src/main/java/org/jabref/gui/importer/ImportCommand.java index ffb438b2db6..8e40e6c0c49 100644 --- a/src/main/java/org/jabref/gui/importer/ImportCommand.java +++ b/src/main/java/org/jabref/gui/importer/ImportCommand.java @@ -71,6 +71,6 @@ private void doImport(Path file, SortedSet importers, FileChooser.Exte ImportAction importMenu = new ImportAction(frame, openInNew, format.orElse(null), preferences); importMenu.automatedImport(Collections.singletonList(file.toString())); // Set last working dir for import - preferences.storeImportExportPreferences(preferences.getImportExportPreferences().withImportWorkingDirectory(file.getParent())); + preferences.getImportExportPreferences().setImportWorkingDirectory(file.getParent()); } } diff --git a/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java b/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java index 8d67378ab62..3f56e6b9c64 100644 --- a/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java @@ -28,25 +28,25 @@ public class FileTabViewModel implements PreferenceTabViewModel { private final BooleanProperty autosaveLocalLibraries = new SimpleBooleanProperty(); private final PreferencesService preferences; - private final ImportExportPreferences initialImportExportPreferences; + private final ImportExportPreferences importExportPreferences; FileTabViewModel(PreferencesService preferences) { this.preferences = preferences; - this.initialImportExportPreferences = preferences.getImportExportPreferences(); + this.importExportPreferences = preferences.getImportExportPreferences(); } @Override public void setValues() { openLastStartupProperty.setValue(preferences.shouldOpenLastFilesOnStartup()); - noWrapFilesProperty.setValue(initialImportExportPreferences.getNonWrappableFields()); - resolveStringsAllProperty.setValue(initialImportExportPreferences.shouldResolveStringsForAllStrings()); // Flipped around - resolveStringsBibTexProperty.setValue(initialImportExportPreferences.shouldResolveStringsForStandardBibtexFields()); - resolveStringsExceptProperty.setValue(initialImportExportPreferences.getNonResolvableFields()); + noWrapFilesProperty.setValue(importExportPreferences.getNonWrappableFields()); + resolveStringsAllProperty.setValue(importExportPreferences.shouldResolveStringsForAllStrings()); // Flipped around + resolveStringsBibTexProperty.setValue(importExportPreferences.shouldResolveStringsForStandardBibtexFields()); + resolveStringsExceptProperty.setValue(importExportPreferences.getNonResolvableFields()); newLineSeparatorListProperty.setValue(FXCollections.observableArrayList(NewLineSeparator.values())); - selectedNewLineSeparatorProperty.setValue(initialImportExportPreferences.getNewLineSeparator()); + selectedNewLineSeparatorProperty.setValue(importExportPreferences.getNewLineSeparator()); - alwaysReformatBibProperty.setValue(initialImportExportPreferences.shouldAlwaysReformatOnSave()); + alwaysReformatBibProperty.setValue(importExportPreferences.shouldAlwaysReformatOnSave()); autosaveLocalLibraries.setValue(preferences.shouldAutosave()); } @@ -55,17 +55,15 @@ public void setValues() { public void storeSettings() { preferences.storeOpenLastFilesOnStartup(openLastStartupProperty.getValue()); - ImportExportPreferences newImportExportPreferences = new ImportExportPreferences( - noWrapFilesProperty.getValue().trim(), - resolveStringsBibTexProperty.getValue(), - resolveStringsAllProperty.getValue(), - resolveStringsExceptProperty.getValue().trim(), - selectedNewLineSeparatorProperty.getValue(), - alwaysReformatBibProperty.getValue(), - initialImportExportPreferences.getImportWorkingDirectory(), - initialImportExportPreferences.getLastExportExtension(), - initialImportExportPreferences.getExportWorkingDirectory()); - preferences.storeImportExportPreferences(newImportExportPreferences); + preferences.getImportExportPreferences().setNonWrappableFields(noWrapFilesProperty.getValue().trim()); + preferences.getImportExportPreferences().setResolveStringsForStandardBibtexFields(resolveStringsBibTexProperty.getValue()); + preferences.getImportExportPreferences().setResolveStringsForAllStrings(resolveStringsAllProperty.getValue()); + preferences.getImportExportPreferences().setNonResolvableFields(resolveStringsExceptProperty.getValue().trim()); + preferences.getImportExportPreferences().setNewLineSeparator(selectedNewLineSeparatorProperty.getValue()); + preferences.getImportExportPreferences().setAlwaysReformatOnSave(alwaysReformatBibProperty.getValue()); + // preferences.getImportExportPreferences().setImportWorkingDirectory(initialImportExportPreferences.getImportWorkingDirectory()); + // preferences.getImportExportPreferences().setLastExportExtension(initialImportExportPreferences.getLastExportExtension()); + // preferences.getImportExportPreferences().setExportWorkingDirectory(initialImportExportPreferences.getExportWorkingDirectory()); preferences.storeShouldAutosave(autosaveLocalLibraries.getValue()); } diff --git a/src/main/java/org/jabref/preferences/ImportExportPreferences.java b/src/main/java/org/jabref/preferences/ImportExportPreferences.java index cbc808fd3cd..51a465ecf0a 100644 --- a/src/main/java/org/jabref/preferences/ImportExportPreferences.java +++ b/src/main/java/org/jabref/preferences/ImportExportPreferences.java @@ -2,16 +2,23 @@ import java.nio.file.Path; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + public class ImportExportPreferences { - private final String nonWrappableFields; - private final boolean resolveStringsForStandardBibtexFields; - private final boolean resolveStringsForAllStrings; - private final String nonResolvableFields; - private final NewLineSeparator newLineSeparator; - private final boolean alwaysReformatOnSave; - private Path importWorkingDirectory; - private String lastExportExtension; - private Path exportWorkingDirectory; + private final StringProperty nonWrappableFields; + private final BooleanProperty resolveStringsForStandardBibtexFields; + private final BooleanProperty resolveStringsForAllStrings; + private final StringProperty nonResolvableFields; + private final ObjectProperty newLineSeparator; + private final BooleanProperty alwaysReformatOnSave; + private final ObjectProperty importWorkingDirectory; + private final StringProperty lastExportExtension; + private final ObjectProperty exportWorkingDirectory; public ImportExportPreferences(String nonWrappableFields, boolean resolveStringsForStandardBibtexFields, @@ -22,65 +29,122 @@ public ImportExportPreferences(String nonWrappableFields, Path importWorkingDirectory, String lastExportExtension, Path exportWorkingDirectory) { - this.nonWrappableFields = nonWrappableFields; - this.resolveStringsForStandardBibtexFields = resolveStringsForStandardBibtexFields; - this.resolveStringsForAllStrings = resolveStringsForAllStrings; - this.nonResolvableFields = nonResolvableFields; - this.newLineSeparator = newLineSeparator; - this.alwaysReformatOnSave = alwaysReformatOnSave; - this.importWorkingDirectory = importWorkingDirectory; - this.lastExportExtension = lastExportExtension; - this.exportWorkingDirectory = exportWorkingDirectory; + this.nonWrappableFields = new SimpleStringProperty(nonWrappableFields); + this.resolveStringsForStandardBibtexFields = new SimpleBooleanProperty(resolveStringsForStandardBibtexFields); + this.resolveStringsForAllStrings = new SimpleBooleanProperty(resolveStringsForAllStrings); + this.nonResolvableFields = new SimpleStringProperty(nonResolvableFields); + this.newLineSeparator = new SimpleObjectProperty<>(newLineSeparator); + this.alwaysReformatOnSave = new SimpleBooleanProperty(alwaysReformatOnSave); + this.importWorkingDirectory = new SimpleObjectProperty<>(importWorkingDirectory); + this.lastExportExtension = new SimpleStringProperty(lastExportExtension); + this.exportWorkingDirectory = new SimpleObjectProperty<>(exportWorkingDirectory); } public String getNonWrappableFields() { + return nonWrappableFields.get(); + } + + public StringProperty nonWrappableFieldsProperty() { return nonWrappableFields; } + public void setNonWrappableFields(String nonWrappableFields) { + this.nonWrappableFields.set(nonWrappableFields); + } + public boolean shouldResolveStringsForStandardBibtexFields() { + return resolveStringsForStandardBibtexFields.get(); + } + + public BooleanProperty resolveStringsForStandardBibtexFieldsProperty() { return resolveStringsForStandardBibtexFields; } + public void setResolveStringsForStandardBibtexFields(boolean resolveStringsForStandardBibtexFields) { + this.resolveStringsForStandardBibtexFields.set(resolveStringsForStandardBibtexFields); + } + public boolean shouldResolveStringsForAllStrings() { + return resolveStringsForAllStrings.get(); + } + + public BooleanProperty resolveStringsForAllStringsProperty() { return resolveStringsForAllStrings; } + public void setResolveStringsForAllStrings(boolean resolveStringsForAllStrings) { + this.resolveStringsForAllStrings.set(resolveStringsForAllStrings); + } + public String getNonResolvableFields() { + return nonResolvableFields.get(); + } + + public StringProperty nonResolvableFieldsProperty() { return nonResolvableFields; } + public void setNonResolvableFields(String nonResolvableFields) { + this.nonResolvableFields.set(nonResolvableFields); + } + public NewLineSeparator getNewLineSeparator() { + return newLineSeparator.get(); + } + + public ObjectProperty newLineSeparatorProperty() { return newLineSeparator; } + public void setNewLineSeparator(NewLineSeparator newLineSeparator) { + this.newLineSeparator.set(newLineSeparator); + } + public boolean shouldAlwaysReformatOnSave() { + return alwaysReformatOnSave.get(); + } + + public BooleanProperty alwaysReformatOnSaveProperty() { return alwaysReformatOnSave; } + public void setAlwaysReformatOnSave(boolean alwaysReformatOnSave) { + this.alwaysReformatOnSave.set(alwaysReformatOnSave); + } + public Path getImportWorkingDirectory() { + return importWorkingDirectory.get(); + } + + public ObjectProperty importWorkingDirectoryProperty() { return importWorkingDirectory; } - public ImportExportPreferences withImportWorkingDirectory(Path importWorkingDirectory) { - this.importWorkingDirectory = importWorkingDirectory; - return this; + public void setImportWorkingDirectory(Path importWorkingDirectory) { + this.importWorkingDirectory.set(importWorkingDirectory); } public String getLastExportExtension() { + return lastExportExtension.get(); + } + + public StringProperty lastExportExtensionProperty() { return lastExportExtension; } - public ImportExportPreferences withLastExportExtension(String lastExportExtension) { - this.lastExportExtension = lastExportExtension; - return this; + public void setLastExportExtension(String lastExportExtension) { + this.lastExportExtension.set(lastExportExtension); } public Path getExportWorkingDirectory() { + return exportWorkingDirectory.get(); + } + + public ObjectProperty exportWorkingDirectoryProperty() { return exportWorkingDirectory; } - public ImportExportPreferences withExportWorkingDirectory(Path exportWorkingDirectory) { - this.exportWorkingDirectory = exportWorkingDirectory; - return this; + public void setExportWorkingDirectory(Path exportWorkingDirectory) { + this.exportWorkingDirectory.set(exportWorkingDirectory); } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 9e224c08e8c..53a7f113b25 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -437,6 +437,7 @@ public class JabRefPreferences implements PreferencesService { private ProxyPreferences proxyPreferences; private SearchPreferences searchPreferences; private AutoLinkPreferences autoLinkPreferences; + private ImportExportPreferences importExportPreferences; // The constructor is made private to enforce this as a singleton class: private JabRefPreferences() { @@ -2126,15 +2127,6 @@ public NewLineSeparator getNewLineSeparator() { return NewLineSeparator.parse(get(NEWLINE)); } - @Override - public void storeNewLineSeparator(NewLineSeparator newLineSeparator) { - String escapeChars = newLineSeparator.toString(); - put(NEWLINE, escapeChars); - - // We also have to change Globals variable as globals is not a getter, but a constant - OS.NEWLINE = escapeChars; - } - @Override public FieldContentFormatterPreferences getFieldContentParserPreferences() { return new FieldContentFormatterPreferences( @@ -2258,7 +2250,11 @@ public void storeShouldAutosave(boolean shouldAutosave) { @Override public ImportExportPreferences getImportExportPreferences() { - return new ImportExportPreferences( + if (Objects.nonNull(importExportPreferences)) { + return importExportPreferences; + } + + importExportPreferences = new ImportExportPreferences( get(NON_WRAPPABLE_FIELDS), !getBoolean(RESOLVE_STRINGS_ALL_FIELDS), getBoolean(RESOLVE_STRINGS_ALL_FIELDS), @@ -2268,18 +2264,22 @@ public ImportExportPreferences getImportExportPreferences() { Path.of(get(IMPORT_WORKING_DIRECTORY)), get(LAST_USED_EXPORT), Path.of(get(EXPORT_WORKING_DIRECTORY))); - } - @Override - public void storeImportExportPreferences(ImportExportPreferences preferences) { - put(NON_WRAPPABLE_FIELDS, preferences.getNonWrappableFields()); - putBoolean(RESOLVE_STRINGS_ALL_FIELDS, preferences.shouldResolveStringsForAllStrings()); - put(DO_NOT_RESOLVE_STRINGS_FOR, preferences.getNonResolvableFields()); - storeNewLineSeparator(preferences.getNewLineSeparator()); - putBoolean(REFORMAT_FILE_ON_SAVE_AND_EXPORT, preferences.shouldAlwaysReformatOnSave()); - put(IMPORT_WORKING_DIRECTORY, preferences.getImportWorkingDirectory().toString()); - put(LAST_USED_EXPORT, preferences.getLastExportExtension()); - put(EXPORT_WORKING_DIRECTORY, preferences.getExportWorkingDirectory().toString()); + EasyBind.listen(importExportPreferences.nonWrappableFieldsProperty(), (obs, oldValue, newValue) -> put(NON_WRAPPABLE_FIELDS, newValue)); + EasyBind.listen(importExportPreferences.resolveStringsForStandardBibtexFieldsProperty(), (obs, oldValue, newValue) -> putBoolean(RESOLVE_STRINGS_ALL_FIELDS, newValue)); + EasyBind.listen(importExportPreferences.resolveStringsForAllStringsProperty(), (obs, oldValue, newValue) -> putBoolean(RESOLVE_STRINGS_ALL_FIELDS, newValue)); + EasyBind.listen(importExportPreferences.nonResolvableFieldsProperty(), (obs, oldValue, newValue) -> put(DO_NOT_RESOLVE_STRINGS_FOR, newValue)); + EasyBind.listen(importExportPreferences.newLineSeparatorProperty(), (obs, oldValue, newValue) -> { + String escapeChars = newValue.toString(); + put(NEWLINE, escapeChars); + OS.NEWLINE = escapeChars; + }); + EasyBind.listen(importExportPreferences.alwaysReformatOnSaveProperty(), (obs, oldValue, newValue) -> putBoolean(REFORMAT_FILE_ON_SAVE_AND_EXPORT, newValue)); + EasyBind.listen(importExportPreferences.importWorkingDirectoryProperty(), (obs, oldValue, newValue) -> put(IMPORT_WORKING_DIRECTORY, newValue.toString())); + EasyBind.listen(importExportPreferences.lastExportExtensionProperty(), (obs, oldValue, newValue) -> put(LAST_USED_EXPORT, newValue)); + EasyBind.listen(importExportPreferences.exportWorkingDirectoryProperty(), (obs, oldValue, newValue) -> put(EXPORT_WORKING_DIRECTORY, newValue.toString())); + + return importExportPreferences; } @Override diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 43a8d6e6d9d..fe7d74c0b5b 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -240,8 +240,6 @@ public interface PreferencesService { NewLineSeparator getNewLineSeparator(); - void storeNewLineSeparator(NewLineSeparator newLineSeparator); - AutoLinkPreferences getAutoLinkPreferences(); boolean shouldAutosave(); @@ -258,8 +256,6 @@ public interface PreferencesService { ImportExportPreferences getImportExportPreferences(); - void storeImportExportPreferences(ImportExportPreferences preferences); - List getCustomExportFormats(JournalAbbreviationRepository repository); void storeCustomExportFormats(List exporters); From 38c9f48c635edfc638f893fde758ec945389a60e Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage Date: Sat, 6 Nov 2021 15:06:49 +0100 Subject: [PATCH 4/4] Migrated ImportExportPreferences to new preferences model --- .../gui/preferences/file/FileTabViewModel.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java b/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java index 3f56e6b9c64..09f7a10bc82 100644 --- a/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java @@ -55,15 +55,12 @@ public void setValues() { public void storeSettings() { preferences.storeOpenLastFilesOnStartup(openLastStartupProperty.getValue()); - preferences.getImportExportPreferences().setNonWrappableFields(noWrapFilesProperty.getValue().trim()); - preferences.getImportExportPreferences().setResolveStringsForStandardBibtexFields(resolveStringsBibTexProperty.getValue()); - preferences.getImportExportPreferences().setResolveStringsForAllStrings(resolveStringsAllProperty.getValue()); - preferences.getImportExportPreferences().setNonResolvableFields(resolveStringsExceptProperty.getValue().trim()); - preferences.getImportExportPreferences().setNewLineSeparator(selectedNewLineSeparatorProperty.getValue()); - preferences.getImportExportPreferences().setAlwaysReformatOnSave(alwaysReformatBibProperty.getValue()); - // preferences.getImportExportPreferences().setImportWorkingDirectory(initialImportExportPreferences.getImportWorkingDirectory()); - // preferences.getImportExportPreferences().setLastExportExtension(initialImportExportPreferences.getLastExportExtension()); - // preferences.getImportExportPreferences().setExportWorkingDirectory(initialImportExportPreferences.getExportWorkingDirectory()); + importExportPreferences.setNonWrappableFields(noWrapFilesProperty.getValue().trim()); + importExportPreferences.setResolveStringsForStandardBibtexFields(resolveStringsBibTexProperty.getValue()); + importExportPreferences.setResolveStringsForAllStrings(resolveStringsAllProperty.getValue()); + importExportPreferences.setNonResolvableFields(resolveStringsExceptProperty.getValue().trim()); + importExportPreferences.setNewLineSeparator(selectedNewLineSeparatorProperty.getValue()); + importExportPreferences.setAlwaysReformatOnSave(alwaysReformatBibProperty.getValue()); preferences.storeShouldAutosave(autosaveLocalLibraries.getValue()); } @@ -74,6 +71,8 @@ public BooleanProperty openLastStartupProperty() { return openLastStartupProperty; } + // ImportExport + public StringProperty noWrapFilesProperty() { return noWrapFilesProperty; }