diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a4c83d649a..7fd4a23590a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We restructured the 'File' tab and extracted some parts into the 'Linked files' tab [#6779](https://github.com/JabRef/jabref/pull/6779) - JabRef now offers journal lists from . JabRef the lists which use a dot inside the abbreviations. [#5749](https://github.com/JabRef/jabref/pull/5749) +- We removed two useless preferences in the groups preferences dialog. [#6836](https://github.com/JabRef/jabref/pull/6836) ### Fixed diff --git a/src/main/java/org/jabref/JabRefMain.java b/src/main/java/org/jabref/JabRefMain.java index 369190d5cb5..8873da6cc5d 100644 --- a/src/main/java/org/jabref/JabRefMain.java +++ b/src/main/java/org/jabref/JabRefMain.java @@ -166,14 +166,14 @@ private static void applyPreferences(JabRefPreferences preferences) { // Build list of Import and Export formats Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(), - Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor()); + Globals.prefs.getXmpPreferences(), Globals.getFileUpdateMonitor()); Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.loadBibEntryTypes(BibDatabaseMode.BIBTEX), preferences.loadBibEntryTypes(BibDatabaseMode.BIBLATEX)); Globals.exportFactory = ExporterFactory.create( Globals.prefs.getCustomExportFormats(Globals.journalAbbreviationRepository), Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository), Globals.prefs.getSavePreferencesForExport(), - Globals.prefs.getXMPPreferences()); + Globals.prefs.getXmpPreferences()); // Initialize protected terms loader Globals.protectedTermsLoader = new ProtectedTermsLoader(Globals.prefs.getProtectedTermsPreferences()); diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index 9aaecfc92de..70edaba1b44 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -461,7 +461,7 @@ private void importPreferences() { LayoutFormatterPreferences layoutPreferences = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository); SavePreferences savePreferences = Globals.prefs.getSavePreferencesForExport(); - XmpPreferences xmpPreferences = Globals.prefs.getXMPPreferences(); + XmpPreferences xmpPreferences = Globals.prefs.getXmpPreferences(); Globals.exportFactory = ExporterFactory.create(customExporters, layoutPreferences, savePreferences, xmpPreferences); } catch (JabRefException ex) { LOGGER.error("Cannot import preferences", ex); diff --git a/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternPanel.java b/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternPanel.java index 42b28084211..b3ede249f9b 100644 --- a/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternPanel.java +++ b/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternPanel.java @@ -17,7 +17,7 @@ import org.jabref.model.bibtexkeypattern.AbstractCitationKeyPattern; import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.types.EntryType; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; @@ -32,7 +32,7 @@ public class CitationKeyPatternPanel extends TableView entryTypeList, AbstractCitationKeyPattern keyPattern) { + public CitationKeyPatternPanel(PreferencesService preferences, Collection entryTypeList, AbstractCitationKeyPattern keyPattern) { super(); viewModel = new CitationKeyPatternPanelViewModel(preferences, entryTypeList, keyPattern); diff --git a/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternPanelViewModel.java b/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternPanelViewModel.java index 6f906b98c38..dbfad157b9f 100644 --- a/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternPanelViewModel.java +++ b/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternPanelViewModel.java @@ -13,7 +13,7 @@ import org.jabref.model.bibtexkeypattern.AbstractCitationKeyPattern; import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.types.EntryType; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; public class CitationKeyPatternPanelViewModel { @@ -38,9 +38,9 @@ public class CitationKeyPatternPanelViewModel { private final ObjectProperty defaultItemProperty = new SimpleObjectProperty<>(); private final AbstractCitationKeyPattern initialKeyPattern; private final Collection bibEntryTypeList; - private final JabRefPreferences preferences; + private final PreferencesService preferences; - public CitationKeyPatternPanelViewModel(JabRefPreferences preferences, Collection entryTypeList, AbstractCitationKeyPattern initialKeyPattern) { + public CitationKeyPatternPanelViewModel(PreferencesService preferences, Collection entryTypeList, AbstractCitationKeyPattern initialKeyPattern) { this.preferences = preferences; this.bibEntryTypeList = entryTypeList; this.initialKeyPattern = initialKeyPattern; @@ -72,12 +72,12 @@ public void setValues() { } public void setItemToDefaultPattern(CitationKeyPatternPanelItemModel item) { - item.setPattern((String) preferences.defaults.get(JabRefPreferences.DEFAULT_CITATION_KEY_PATTERN)); + item.setPattern(preferences.getDefaultsDefaultCitationKeyPattern()); } public void resetAll() { patternListProperty.forEach(item -> item.setPattern("")); - defaultItemProperty.getValue().setPattern((String) preferences.defaults.get(JabRefPreferences.DEFAULT_CITATION_KEY_PATTERN)); + defaultItemProperty.getValue().setPattern(preferences.getDefaultsDefaultCitationKeyPattern()); } public ListProperty patternListProperty() { diff --git a/src/main/java/org/jabref/gui/exporter/ExportCommand.java b/src/main/java/org/jabref/gui/exporter/ExportCommand.java index 010708dc30d..d55a1a97ea5 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCommand.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCommand.java @@ -54,7 +54,7 @@ public void execute() { List customExporters = preferences.getCustomExportFormats(Globals.journalAbbreviationRepository); LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository); SavePreferences savePreferences = preferences.getSavePreferencesForExport(); - XmpPreferences xmpPreferences = preferences.getXMPPreferences(); + XmpPreferences xmpPreferences = preferences.getXmpPreferences(); // Get list of exporters and sort before adding to file dialog List exporters = Globals.exportFactory.getExporters().stream() diff --git a/src/main/java/org/jabref/gui/exporter/WriteXMPAction.java b/src/main/java/org/jabref/gui/exporter/WriteXMPAction.java index 90ed161d558..368e4970e46 100644 --- a/src/main/java/org/jabref/gui/exporter/WriteXMPAction.java +++ b/src/main/java/org/jabref/gui/exporter/WriteXMPAction.java @@ -127,7 +127,7 @@ private void writeXMP() { for (Path file : files) { if (Files.exists(file)) { try { - XmpUtilWriter.writeXmp(file, entry, database, Globals.prefs.getXMPPreferences()); + XmpUtilWriter.writeXmp(file, entry, database, Globals.prefs.getXmpPreferences()); Platform.runLater( () -> optionsDialog.getProgressArea().appendText(" " + Localization.lang("OK") + ".\n")); entriesChanged++; diff --git a/src/main/java/org/jabref/gui/externalfiles/DownloadFullTextAction.java b/src/main/java/org/jabref/gui/externalfiles/DownloadFullTextAction.java index 73bf06cce21..a1eadf4a04e 100644 --- a/src/main/java/org/jabref/gui/externalfiles/DownloadFullTextAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/DownloadFullTextAction.java @@ -150,7 +150,7 @@ private void addLinkedFileFromURL(BibDatabaseContext databaseContext, URL url, B databaseContext, Globals.TASK_EXECUTOR, dialogService, - preferences.getXMPPreferences(), + preferences.getXmpPreferences(), preferences.getFilePreferences(), ExternalFileTypes.getInstance()); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java index 50f69c0c0d5..c230aa9010d 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java @@ -107,7 +107,7 @@ public LinkedFileViewModel fromFile(Path file) { databaseContext, taskExecutor, dialogService, - preferences.getXMPPreferences(), + preferences.getXmpPreferences(), preferences.getFilePreferences(), externalFileTypes); } @@ -128,7 +128,7 @@ private List parseToFileViewModel(String stringValue) { databaseContext, taskExecutor, dialogService, - preferences.getXMPPreferences(), + preferences.getXmpPreferences(), preferences.getFilePreferences(), externalFileTypes)) .collect(Collectors.toList()); @@ -159,7 +159,7 @@ public void addNewFile() { databaseContext, taskExecutor, dialogService, - preferences.getXMPPreferences(), + preferences.getXmpPreferences(), preferences.getFilePreferences(), externalFileTypes)); }); @@ -197,7 +197,7 @@ private List findAssociatedNotLinkedFiles(BibEntry entry) { databaseContext, taskExecutor, dialogService, - preferences.getXMPPreferences(), + preferences.getXmpPreferences(), preferences.getFilePreferences(), externalFileTypes); newLinkedFile.markAsAutomaticallyFound(); @@ -248,7 +248,7 @@ private void addFromURL(URL url) { databaseContext, taskExecutor, dialogService, - preferences.getXMPPreferences(), + preferences.getXmpPreferences(), preferences.getFilePreferences(), externalFileTypes); files.add(onlineFile); diff --git a/src/main/java/org/jabref/gui/groups/GroupsPreferences.java b/src/main/java/org/jabref/gui/groups/GroupsPreferences.java new file mode 100644 index 00000000000..6006e8ea2b7 --- /dev/null +++ b/src/main/java/org/jabref/gui/groups/GroupsPreferences.java @@ -0,0 +1,36 @@ +package org.jabref.gui.groups; + +public class GroupsPreferences { + + private final GroupViewMode groupViewMode; + private final boolean shouldAutoAssignGroup; + private final boolean shouldDisplayGroupCount; + private final Character keywordSeparator; + + public GroupsPreferences(GroupViewMode groupViewMode, + boolean shouldAutoAssignGroup, + boolean shouldDisplayGroupCount, + Character keywordSeparator) { + + this.groupViewMode = groupViewMode; + this.shouldAutoAssignGroup = shouldAutoAssignGroup; + this.shouldDisplayGroupCount = shouldDisplayGroupCount; + this.keywordSeparator = keywordSeparator; + } + + public GroupViewMode getGroupViewMode() { + return groupViewMode; + } + + public boolean shouldAutoAssignGroup() { + return shouldAutoAssignGroup; + } + + public boolean shouldDisplayGroupCount() { + return shouldDisplayGroupCount; + } + + public Character getKeywordDelimiter() { + return keywordSeparator; + } +} diff --git a/src/main/java/org/jabref/gui/importer/ImportCustomizationDialogViewModel.java b/src/main/java/org/jabref/gui/importer/ImportCustomizationDialogViewModel.java index 90ac43ee424..e0a023b6f72 100644 --- a/src/main/java/org/jabref/gui/importer/ImportCustomizationDialogViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportCustomizationDialogViewModel.java @@ -120,7 +120,10 @@ public void removeSelectedImporter() { public void saveToPrefs() { Globals.prefs.customImports.clear(); Globals.prefs.customImports.addAll(importers); - Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(), Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor()); + Globals.IMPORT_FORMAT_READER.resetImportFormats( + Globals.prefs.getImportFormatPreferences(), + Globals.prefs.getXmpPreferences(), + Globals.getFileUpdateMonitor()); } public ListProperty selectedImportersProperty() { diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index 68721e59343..0097cb03440 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -140,7 +140,15 @@ public void importEntries(List entriesToImport, boolean shouldDownload if (shouldDownloadFiles) { for (BibEntry bibEntry : entriesToImport) { for (LinkedFile linkedFile : bibEntry.getFiles()) { - LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFile, bibEntry, databaseContext, taskExecutor, dialogService, preferences.getXMPPreferences(), filePreferences, ExternalFileTypes.getInstance()); + LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel( + linkedFile, + bibEntry, + databaseContext, + taskExecutor, + dialogService, + preferences.getXmpPreferences(), + filePreferences, + ExternalFileTypes.getInstance()); linkedFileViewModel.download(); } } diff --git a/src/main/java/org/jabref/gui/maintable/OpenExternalFileAction.java b/src/main/java/org/jabref/gui/maintable/OpenExternalFileAction.java index 84201650ce4..6e7024eefc6 100644 --- a/src/main/java/org/jabref/gui/maintable/OpenExternalFileAction.java +++ b/src/main/java/org/jabref/gui/maintable/OpenExternalFileAction.java @@ -46,7 +46,7 @@ public void execute() { databaseContext, Globals.TASK_EXECUTOR, dialogService, - preferencesService.getXMPPreferences(), + preferencesService.getXmpPreferences(), preferencesService.getFilePreferences(), ExternalFileTypes.getInstance()); linkedFileViewModel.open(); diff --git a/src/main/java/org/jabref/gui/maintable/OpenFolderAction.java b/src/main/java/org/jabref/gui/maintable/OpenFolderAction.java index d1fd013f79e..008dfb839da 100644 --- a/src/main/java/org/jabref/gui/maintable/OpenFolderAction.java +++ b/src/main/java/org/jabref/gui/maintable/OpenFolderAction.java @@ -37,7 +37,7 @@ public void execute() { databaseContext, Globals.TASK_EXECUTOR, dialogService, - preferencesService.getXMPPreferences(), + preferencesService.getXmpPreferences(), preferencesService.getFilePreferences(), ExternalFileTypes.getInstance() ); diff --git a/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java b/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java index 2c46132a52c..f95351d1ee2 100644 --- a/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java +++ b/src/main/java/org/jabref/gui/maintable/columns/FileColumn.java @@ -68,7 +68,7 @@ public FileColumn(MainTableColumnModel model, entry.getEntry(), database, Globals.TASK_EXECUTOR, dialogService, - preferencesService.getXMPPreferences(), + preferencesService.getXmpPreferences(), preferencesService.getFilePreferences(), externalFileTypes); linkedFileViewModel.open(); @@ -132,7 +132,7 @@ private ContextMenu createFileMenu(BibEntryTableViewModel entry, List extends VBox implements PreferencesTab { @@ -18,7 +18,7 @@ public abstract class AbstractPreferenceTabView imp @FXML private CheckBox autosaveLocalLibraries; @FXML private Button autosaveLocalLibrariesHelp; - public FileTabView(JabRefPreferences preferences) { + public FileTabView(PreferencesService preferences) { this.preferences = preferences; ViewLoader.view(this) diff --git a/src/main/java/org/jabref/gui/preferences/GeneralTabView.java b/src/main/java/org/jabref/gui/preferences/GeneralTabView.java index 3d0fdf2cffa..52d7b6273dd 100644 --- a/src/main/java/org/jabref/gui/preferences/GeneralTabView.java +++ b/src/main/java/org/jabref/gui/preferences/GeneralTabView.java @@ -20,7 +20,7 @@ import org.jabref.logic.l10n.Language; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; @@ -51,7 +51,7 @@ public class GeneralTabView extends AbstractPreferenceTabView - - - + diff --git a/src/main/java/org/jabref/gui/preferences/GroupsTabView.java b/src/main/java/org/jabref/gui/preferences/GroupsTabView.java index e25ccd47438..023e0de06d2 100644 --- a/src/main/java/org/jabref/gui/preferences/GroupsTabView.java +++ b/src/main/java/org/jabref/gui/preferences/GroupsTabView.java @@ -6,21 +6,19 @@ import javafx.scene.control.TextField; import org.jabref.logic.l10n.Localization; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; public class GroupsTabView extends AbstractPreferenceTabView implements PreferencesTab { - @FXML private CheckBox grayNonHits; @FXML private RadioButton groupViewModeIntersection; @FXML private RadioButton groupViewModeUnion; @FXML private CheckBox autoAssignGroup; @FXML private CheckBox displayGroupCount; - @FXML private TextField defaultGroupingField; @FXML private TextField keywordSeparator; - public GroupsTabView(JabRefPreferences preferences) { + public GroupsTabView(PreferencesService preferences) { this.preferences = preferences; ViewLoader.view(this) @@ -36,12 +34,10 @@ public String getTabName() { public void initialize() { this.viewModel = new GroupsTabViewModel(dialogService, preferences); - grayNonHits.selectedProperty().bindBidirectional(viewModel.grayNonHitsProperty()); groupViewModeIntersection.selectedProperty().bindBidirectional(viewModel.groupViewModeIntersectionProperty()); groupViewModeUnion.selectedProperty().bindBidirectional(viewModel.groupViewModeUnionProperty()); autoAssignGroup.selectedProperty().bindBidirectional(viewModel.autoAssignGroupProperty()); displayGroupCount.selectedProperty().bindBidirectional(viewModel.displayGroupCount()); - defaultGroupingField.textProperty().bindBidirectional(viewModel.defaultGroupingFieldProperty()); keywordSeparator.textProperty().bindBidirectional(viewModel.keywordSeparatorProperty()); } } diff --git a/src/main/java/org/jabref/gui/preferences/GroupsTabViewModel.java b/src/main/java/org/jabref/gui/preferences/GroupsTabViewModel.java index 67abce42a7b..c2cc3fcfd02 100644 --- a/src/main/java/org/jabref/gui/preferences/GroupsTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/GroupsTabViewModel.java @@ -10,59 +10,57 @@ import org.jabref.gui.DialogService; import org.jabref.gui.groups.GroupViewMode; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.gui.groups.GroupsPreferences; +import org.jabref.preferences.PreferencesService; public class GroupsTabViewModel implements PreferenceTabViewModel { - private final BooleanProperty grayNonHitsProperty = new SimpleBooleanProperty(); private final BooleanProperty groupViewModeIntersectionProperty = new SimpleBooleanProperty(); private final BooleanProperty groupViewModeUnionProperty = new SimpleBooleanProperty(); private final BooleanProperty autoAssignGroupProperty = new SimpleBooleanProperty(); private final BooleanProperty displayGroupCountProperty = new SimpleBooleanProperty(); - private final StringProperty defaultGroupingFieldProperty = new SimpleStringProperty(""); private final StringProperty keywordSeparatorProperty = new SimpleStringProperty(""); private final DialogService dialogService; - private final JabRefPreferences preferences; + private final PreferencesService preferences; + private final GroupsPreferences initialGroupsPreferences; - public GroupsTabViewModel(DialogService dialogService, JabRefPreferences preferences) { + public GroupsTabViewModel(DialogService dialogService, PreferencesService preferences) { this.dialogService = dialogService; this.preferences = preferences; + this.initialGroupsPreferences = preferences.getGroupsPreferences(); } @Override public void setValues() { - grayNonHitsProperty.setValue(preferences.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)); - switch (preferences.getGroupViewMode()) { - case INTERSECTION: + switch (initialGroupsPreferences.getGroupViewMode()) { + case INTERSECTION -> { groupViewModeIntersectionProperty.setValue(true); groupViewModeUnionProperty.setValue(false); - break; - case UNION: + } + case UNION -> { groupViewModeIntersectionProperty.setValue(false); groupViewModeUnionProperty.setValue(true); - break; + } } - autoAssignGroupProperty.setValue(preferences.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)); - displayGroupCountProperty.setValue(preferences.getBoolean(JabRefPreferences.DISPLAY_GROUP_COUNT)); - - defaultGroupingFieldProperty.setValue(preferences.get(JabRefPreferences.GROUPS_DEFAULT_FIELD)); - keywordSeparatorProperty.setValue(preferences.get(JabRefPreferences.KEYWORD_SEPARATOR)); + autoAssignGroupProperty.setValue(initialGroupsPreferences.shouldAutoAssignGroup()); + displayGroupCountProperty.setValue(initialGroupsPreferences.shouldDisplayGroupCount()); + keywordSeparatorProperty.setValue(initialGroupsPreferences.getKeywordDelimiter().toString()); } @Override public void storeSettings() { - preferences.putBoolean(JabRefPreferences.GRAY_OUT_NON_HITS, grayNonHitsProperty.getValue()); + GroupViewMode groupViewMode = GroupViewMode.UNION; if (groupViewModeIntersectionProperty.getValue()) { - preferences.setGroupViewMode(GroupViewMode.INTERSECTION); - } else if (groupViewModeUnionProperty.getValue()) { - preferences.setGroupViewMode(GroupViewMode.UNION); + groupViewMode = GroupViewMode.INTERSECTION; } - preferences.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP, autoAssignGroupProperty.getValue()); - preferences.putBoolean(JabRefPreferences.DISPLAY_GROUP_COUNT, displayGroupCountProperty.getValue()); - preferences.put(JabRefPreferences.GROUPS_DEFAULT_FIELD, defaultGroupingFieldProperty.getValue().trim()); - preferences.put(JabRefPreferences.KEYWORD_SEPARATOR, keywordSeparatorProperty.getValue()); + GroupsPreferences newGroupsPreferences = new GroupsPreferences( + groupViewMode, + autoAssignGroupProperty.getValue(), + displayGroupCountProperty.getValue(), + keywordSeparatorProperty.getValue().charAt(0)); + preferences.storeGroupsPreferences(newGroupsPreferences); } @Override @@ -75,10 +73,6 @@ public List getRestartWarnings() { return new ArrayList<>(); } - public BooleanProperty grayNonHitsProperty() { - return grayNonHitsProperty; - } - public BooleanProperty groupViewModeIntersectionProperty() { return groupViewModeIntersectionProperty; } @@ -95,10 +89,6 @@ public BooleanProperty displayGroupCount() { return displayGroupCountProperty; } - public StringProperty defaultGroupingFieldProperty() { - return defaultGroupingFieldProperty; - } - public StringProperty keywordSeparatorProperty() { return keywordSeparatorProperty; } diff --git a/src/main/java/org/jabref/gui/preferences/LinkedFilesTabView.java b/src/main/java/org/jabref/gui/preferences/LinkedFilesTabView.java index 6418ab96c74..65ca048f9cf 100644 --- a/src/main/java/org/jabref/gui/preferences/LinkedFilesTabView.java +++ b/src/main/java/org/jabref/gui/preferences/LinkedFilesTabView.java @@ -15,7 +15,7 @@ import org.jabref.gui.util.IconValidationDecorator; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; @@ -37,7 +37,7 @@ public class LinkedFilesTabView extends AbstractPreferenceTabView names = preferences.getStringList(JabRefPreferences.NAME_FORMATER_KEY); - List formats = preferences.getStringList(JabRefPreferences.NAME_FORMATTER_VALUE); + List names = initialNameFormatterPreferences.getNameFormatterKey(); + List formats = initialNameFormatterPreferences.getNameFormatterValue(); for (int i = 0; i < names.size(); i++) { if (i < formats.size()) { @@ -53,8 +56,10 @@ public void storeSettings() { formats.add(formatterListItem.getFormat()); } - preferences.putStringList(JabRefPreferences.NAME_FORMATER_KEY, names); - preferences.putStringList(JabRefPreferences.NAME_FORMATTER_VALUE, formats); + NameFormatterPreferences newNameFormatterPreferences = new NameFormatterPreferences( + names, + formats); + preferences.storeNameFormatterPreferences(newNameFormatterPreferences); } public void addFormatter() { diff --git a/src/main/java/org/jabref/gui/preferences/NetworkTabView.java b/src/main/java/org/jabref/gui/preferences/NetworkTabView.java index 245d5f3ed5b..c998c397508 100644 --- a/src/main/java/org/jabref/gui/preferences/NetworkTabView.java +++ b/src/main/java/org/jabref/gui/preferences/NetworkTabView.java @@ -17,7 +17,7 @@ import org.jabref.gui.util.IconValidationDecorator; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; @@ -46,7 +46,7 @@ public class NetworkTabView extends AbstractPreferenceTabView customExporters = preferences.getCustomExportFormats(Globals.journalAbbreviationRepository); LayoutFormatterPreferences layoutPreferences = preferences.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository); SavePreferences savePreferences = preferences.getSavePreferencesForExport(); - XmpPreferences xmpPreferences = preferences.getXMPPreferences(); + XmpPreferences xmpPreferences = preferences.getXmpPreferences(); Globals.exportFactory = ExporterFactory.create(customExporters, layoutPreferences, savePreferences, xmpPreferences); ExternalApplicationsPreferences externalApplicationsPreferences = preferences.getExternalApplicationsPreferences(); @@ -155,10 +155,7 @@ private void updateAfterPreferenceChanges() { /** * Checks if all tabs are valid - * ToDo: After conversion of all tabs use mvvmfx-validator - * ToDo: should be observable for binding of OK-button in View */ - public boolean validSettings() { for (PreferencesTab tab : preferenceTabs) { if (!tab.validateSettings()) { diff --git a/src/main/java/org/jabref/gui/preferences/PreviewTabView.java b/src/main/java/org/jabref/gui/preferences/PreviewTabView.java index a1bc618b641..cc0e2a52717 100644 --- a/src/main/java/org/jabref/gui/preferences/PreviewTabView.java +++ b/src/main/java/org/jabref/gui/preferences/PreviewTabView.java @@ -33,7 +33,7 @@ import org.jabref.logic.preview.PreviewLayout; import org.jabref.logic.util.TestEntry; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; import com.tobiasdiez.easybind.EasyBind; @@ -63,6 +63,14 @@ public class PreviewTabView extends AbstractPreferenceTabView editArea.copy(); + case CUT -> editArea.cut(); + case PASTE -> editArea.paste(); + case SELECT_ALL -> editArea.selectAll(); } editArea.requestFocus(); } } } - public PreviewTabView(JabRefPreferences preferences) { - this.preferences = preferences; - - ViewLoader.view(this) - .root(this) - .load(); - } - @Override public String getTabName() { return Localization.lang("Entry preview"); diff --git a/src/main/java/org/jabref/gui/preferences/PreviewTabViewModel.java b/src/main/java/org/jabref/gui/preferences/PreviewTabViewModel.java index e478914451e..bd088a1a731 100644 --- a/src/main/java/org/jabref/gui/preferences/PreviewTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/PreviewTabViewModel.java @@ -37,7 +37,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.TextBasedPreviewLayout; import org.jabref.logic.preview.PreviewLayout; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import org.jabref.preferences.PreviewPreferences; import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; @@ -73,8 +73,8 @@ public class PreviewTabViewModel implements PreferenceTabViewModel { private final StringProperty sourceTextProperty = new SimpleStringProperty(""); private final DialogService dialogService; - private final JabRefPreferences preferences; - private final PreviewPreferences previewPreferences; + private final PreferencesService preferences; + private final PreviewPreferences initialPreviewPreferences; private final TaskExecutor taskExecutor; private final Validator chosenListValidator; @@ -83,12 +83,12 @@ public class PreviewTabViewModel implements PreferenceTabViewModel { private ListProperty dragSourceList = null; private ObjectProperty> dragSourceSelectionModel = null; - public PreviewTabViewModel(DialogService dialogService, JabRefPreferences preferences, TaskExecutor taskExecutor, StateManager stateManager) { + public PreviewTabViewModel(DialogService dialogService, PreferencesService preferences, TaskExecutor taskExecutor, StateManager stateManager) { this.dialogService = dialogService; this.preferences = preferences; this.taskExecutor = taskExecutor; this.localDragboard = stateManager.getLocalDragboard(); - previewPreferences = preferences.getPreviewPreferences(); + initialPreviewPreferences = preferences.getPreviewPreferences(); sourceTextProperty.addListener((observable, oldValue, newValue) -> { if (getCurrentLayout() instanceof TextBasedPreviewLayout) { @@ -113,13 +113,13 @@ public BooleanProperty showAsExtraTabProperty() { } public void setValues() { - showAsExtraTab.set(previewPreferences.showPreviewAsExtraTab()); + showAsExtraTab.set(initialPreviewPreferences.showPreviewAsExtraTab()); chosenListProperty().getValue().clear(); - chosenListProperty.getValue().addAll(previewPreferences.getPreviewCycle()); + chosenListProperty.getValue().addAll(initialPreviewPreferences.getPreviewCycle()); availableListProperty.clear(); if (chosenListProperty.stream().noneMatch(layout -> layout instanceof TextBasedPreviewLayout)) { - availableListProperty.getValue().add(previewPreferences.getTextBasedPreviewLayout()); + availableListProperty.getValue().add(initialPreviewPreferences.getTextBasedPreviewLayout()); } BackgroundTask.wrap(CitationStyle::discoverCitationStyles) @@ -182,7 +182,7 @@ private PreviewLayout getCurrentLayout() { PreviewLayout layout = findLayoutByName("Preview"); if (layout == null) { - layout = previewPreferences.getTextBasedPreviewLayout(); + layout = initialPreviewPreferences.getTextBasedPreviewLayout(); } return layout; diff --git a/src/main/java/org/jabref/gui/preferences/TableTabView.java b/src/main/java/org/jabref/gui/preferences/TableTabView.java index cb92b5311f5..309ae7da5dd 100644 --- a/src/main/java/org/jabref/gui/preferences/TableTabView.java +++ b/src/main/java/org/jabref/gui/preferences/TableTabView.java @@ -21,7 +21,7 @@ import org.jabref.gui.util.ViewModelListCellFactory; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; @@ -49,9 +49,7 @@ public class TableTabView extends AbstractPreferenceTabView i private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer(); - private final JabRefPreferences preferences; - - public TableTabView(JabRefPreferences preferences) { + public TableTabView(PreferencesService preferences) { this.preferences = preferences; ViewLoader.view(this) diff --git a/src/main/java/org/jabref/gui/preferences/XmpPrivacyTabView.java b/src/main/java/org/jabref/gui/preferences/XmpPrivacyTabView.java index 77baff41b69..07b0ee2474a 100644 --- a/src/main/java/org/jabref/gui/preferences/XmpPrivacyTabView.java +++ b/src/main/java/org/jabref/gui/preferences/XmpPrivacyTabView.java @@ -18,7 +18,7 @@ import org.jabref.gui.util.ViewModelListCellFactory; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.field.Field; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer; @@ -32,9 +32,9 @@ public class XmpPrivacyTabView extends AbstractPreferenceTabView addFieldName; @FXML private Button addField; - private ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer(); + private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer(); - public XmpPrivacyTabView(JabRefPreferences preferences) { + public XmpPrivacyTabView(PreferencesService preferences) { this.preferences = preferences; ViewLoader.view(this) diff --git a/src/main/java/org/jabref/gui/preferences/XmpPrivacyTabViewModel.java b/src/main/java/org/jabref/gui/preferences/XmpPrivacyTabViewModel.java index fc9bdd24f66..a54f8aa8053 100644 --- a/src/main/java/org/jabref/gui/preferences/XmpPrivacyTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/XmpPrivacyTabViewModel.java @@ -1,8 +1,8 @@ package org.jabref.gui.preferences; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; -import java.util.stream.Collectors; import javafx.beans.property.BooleanProperty; import javafx.beans.property.ListProperty; @@ -14,9 +14,10 @@ import org.jabref.gui.DialogService; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; import de.saxsys.mvvmfx.utils.validation.ValidationMessage; @@ -31,13 +32,15 @@ public class XmpPrivacyTabViewModel implements PreferenceTabViewModel { private final ObjectProperty addFieldProperty = new SimpleObjectProperty<>(); private final DialogService dialogService; - private final JabRefPreferences preferences; + private final PreferencesService preferences; + private final XmpPreferences initialXmpPreferences; - private Validator xmpFilterListValidator; + private final Validator xmpFilterListValidator; - XmpPrivacyTabViewModel(DialogService dialogService, JabRefPreferences preferences) { + XmpPrivacyTabViewModel(DialogService dialogService, PreferencesService preferences) { this.dialogService = dialogService; this.preferences = preferences; + this.initialXmpPreferences = preferences.getXmpPreferences(); xmpFilterListValidator = new FunctionBasedValidator<>( xmpFilterListProperty, @@ -50,12 +53,10 @@ public class XmpPrivacyTabViewModel implements PreferenceTabViewModel { @Override public void setValues() { - xmpFilterEnabledProperty.setValue(preferences.getBoolean(JabRefPreferences.USE_XMP_PRIVACY_FILTER)); + xmpFilterEnabledProperty.setValue(initialXmpPreferences.shouldUseXmpPrivacyFilter()); xmpFilterListProperty.clear(); - List xmpFilters = preferences.getStringList(JabRefPreferences.XMP_PRIVACY_FILTERS) - .stream().map(FieldFactory::parseField).collect(Collectors.toList()); - xmpFilterListProperty.addAll(xmpFilters); + xmpFilterListProperty.addAll(initialXmpPreferences.getXmpPrivacyFilter()); availableFieldsProperty.clear(); availableFieldsProperty.addAll(FieldFactory.getCommonFields()); @@ -63,10 +64,11 @@ public void setValues() { @Override public void storeSettings() { - preferences.putBoolean(JabRefPreferences.USE_XMP_PRIVACY_FILTER, xmpFilterEnabledProperty.getValue()); - preferences.putStringList(JabRefPreferences.XMP_PRIVACY_FILTERS, xmpFilterListProperty.getValue().stream() - .map(Field::getName) - .collect(Collectors.toList())); + XmpPreferences newXmpPreferences = new XmpPreferences( + xmpFilterEnabledProperty.getValue(), + new HashSet<>(xmpFilterListProperty.getValue()), + preferences.getKeywordDelimiter()); + preferences.storeXmpPreferences(newXmpPreferences); } public void addField() { diff --git a/src/main/java/org/jabref/logic/xmp/DublinCoreExtractor.java b/src/main/java/org/jabref/logic/xmp/DublinCoreExtractor.java index fdf91c478e6..77a3fa5f7b5 100644 --- a/src/main/java/org/jabref/logic/xmp/DublinCoreExtractor.java +++ b/src/main/java/org/jabref/logic/xmp/DublinCoreExtractor.java @@ -342,7 +342,7 @@ private void fillCustomField(Field field, String value) { public void fillDublinCoreSchema() { // Query privacy filter settings - boolean useXmpPrivacyFilter = xmpPreferences.isUseXMPPrivacyFilter(); + boolean useXmpPrivacyFilter = xmpPreferences.shouldUseXmpPrivacyFilter(); Set> fieldValues = new TreeSet<>(Comparator.comparing(fieldStringEntry -> fieldStringEntry.getKey().getName())); fieldValues.addAll(bibEntry.getFieldMap().entrySet()); diff --git a/src/main/java/org/jabref/logic/xmp/XmpPreferences.java b/src/main/java/org/jabref/logic/xmp/XmpPreferences.java index 221fa496e31..d04ab3ca91b 100644 --- a/src/main/java/org/jabref/logic/xmp/XmpPreferences.java +++ b/src/main/java/org/jabref/logic/xmp/XmpPreferences.java @@ -6,18 +6,18 @@ public class XmpPreferences { - private final boolean useXMPPrivacyFilter; + private final boolean useXmpPrivacyFilter; private final Set xmpPrivacyFilter; private final Character keywordSeparator; - public XmpPreferences(boolean useXMPPrivacyFilter, Set xmpPrivacyFilter, Character keywordSeparator) { - this.useXMPPrivacyFilter = useXMPPrivacyFilter; + public XmpPreferences(boolean useXmpPrivacyFilter, Set xmpPrivacyFilter, Character keywordSeparator) { + this.useXmpPrivacyFilter = useXmpPrivacyFilter; this.xmpPrivacyFilter = xmpPrivacyFilter; this.keywordSeparator = keywordSeparator; } - public boolean isUseXMPPrivacyFilter() { - return useXMPPrivacyFilter; + public boolean shouldUseXmpPrivacyFilter() { + return useXmpPrivacyFilter; } public Set getXmpPrivacyFilter() { diff --git a/src/main/java/org/jabref/logic/xmp/XmpUtilWriter.java b/src/main/java/org/jabref/logic/xmp/XmpUtilWriter.java index 8abac0c35ae..0ea00dba569 100644 --- a/src/main/java/org/jabref/logic/xmp/XmpUtilWriter.java +++ b/src/main/java/org/jabref/logic/xmp/XmpUtilWriter.java @@ -245,7 +245,7 @@ private static void writeDocumentInformation(PDDocument document, BibEntry resolvedEntry = XmpUtilWriter.getDefaultOrDatabaseEntry(entry, database); // Query privacy filter settings - boolean useXmpPrivacyFilter = xmpPreferences.isUseXMPPrivacyFilter(); + boolean useXmpPrivacyFilter = xmpPreferences.shouldUseXmpPrivacyFilter(); // Set all the values including key and entryType for (Entry fieldValuePair : resolvedEntry.getFieldMap().entrySet()) { diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 16405f7a2a4..064683a3651 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -44,6 +44,7 @@ import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.entryeditor.EntryEditorPreferences; import org.jabref.gui.groups.GroupViewMode; +import org.jabref.gui.groups.GroupsPreferences; import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.maintable.ColumnPreferences; import org.jabref.gui.maintable.MainTableColumnModel; @@ -176,7 +177,6 @@ public class JabRefPreferences implements PreferencesService { public static final String EDITOR_EMACS_KEYBINDINGS = "editorEMACSkeyBindings"; public static final String EDITOR_EMACS_KEYBINDINGS_REBIND_CA = "editorEMACSkeyBindingsRebindCA"; public static final String EDITOR_EMACS_KEYBINDINGS_REBIND_CF = "editorEMACSkeyBindingsRebindCF"; - public static final String GROUPS_DEFAULT_FIELD = "groupsDefaultField"; public static final String KEYWORD_SEPARATOR = "groupKeywordSeparator"; public static final String AUTO_ASSIGN_GROUP = "autoAssignGroup"; @@ -224,7 +224,6 @@ public class JabRefPreferences implements PreferencesService { // When this should be made possible, the code to inspect is org.jabref.gui.preferences.CitationKeyPatternPrefTab.storeSettings() -> LabelPattern keypatterns = getCiteKeyPattern(); etc public static final String DEFAULT_CITATION_KEY_PATTERN = "defaultBibtexKeyPattern"; public static final String UNWANTED_CITATION_KEY_CHARACTERS = "defaultUnwantedBibtexKeyCharacters"; - public static final String GRAY_OUT_NON_HITS = "grayOutNonHits"; public static final String CONFIRM_DELETE = "confirmDelete"; public static final String WARN_BEFORE_OVERWRITING_KEY = "warnBeforeOverwritingKey"; public static final String AVOID_OVERWRITING_KEY = "avoidOverwritingKey"; @@ -393,28 +392,13 @@ public class JabRefPreferences implements PreferencesService { private final Preferences prefs; /** - * Cache variable for getGlobalCitationKeyPattern + * Cache variables */ private GlobalCitationKeyPattern globalCitationKeyPattern; - - /** - * Cache variable for getEntryEditorTabList - */ private Map> entryEditorTabList; - - /** - * Cache variable for getMainTableColumns - */ private List mainTableColumns; - - /** - * Cache variable for getColumnSortOrder - */ private List mainTableColumnSortOrder; - - /** - * Cache variable for getTheme - */ + private PreviewPreferences previewPreferences; private Theme globalTheme; // The constructor is made private to enforce this as a singleton class: @@ -549,7 +533,6 @@ private JabRefPreferences() { defaults.put(AUTOCOMPLETER_FIRST_LAST, Boolean.FALSE); // "Autocomplete names in 'Firstname Lastname' format only" defaults.put(AUTOCOMPLETER_LAST_FIRST, Boolean.FALSE); // "Autocomplete names in 'Lastname, Firstname' format only" defaults.put(AUTOCOMPLETER_COMPLETE_FIELDS, "author;editor;title;journal;publisher;keywords;crossref;related;entryset"); - defaults.put(GROUPS_DEFAULT_FIELD, StandardField.KEYWORDS.getName()); defaults.put(AUTO_ASSIGN_GROUP, Boolean.TRUE); defaults.put(DISPLAY_GROUP_COUNT, Boolean.TRUE); defaults.put(GROUP_INTERSECT_UNION_VIEW_MODE, GroupViewMode.INTERSECTION.name()); @@ -597,7 +580,6 @@ private JabRefPreferences() { defaults.put(AVOID_OVERWRITING_KEY, Boolean.FALSE); defaults.put(WARN_BEFORE_OVERWRITING_KEY, Boolean.TRUE); defaults.put(CONFIRM_DELETE, Boolean.TRUE); - defaults.put(GRAY_OUT_NON_HITS, Boolean.TRUE); defaults.put(DEFAULT_CITATION_KEY_PATTERN, "[auth][year]"); defaults.put(UNWANTED_CITATION_KEY_CHARACTERS, "-`สน:!;?^+"); defaults.put(DO_NOT_RESOLVE_STRINGS_FOR, StandardField.URL.getName()); @@ -1186,14 +1168,6 @@ public LayoutFormatterPreferences getLayoutFormatterPreferences(JournalAbbreviat repository); } - @Override - public XmpPreferences getXMPPreferences() { - return new XmpPreferences( - getBoolean(USE_XMP_PRIVACY_FILTER), - getStringList(XMP_PRIVACY_FILTERS).stream().map(FieldFactory::parseField).collect(Collectors.toSet()), - getKeywordDelimiter()); - } - @Override public OpenOfficePreferences getOpenOfficePreferences() { return new OpenOfficePreferences( @@ -1219,10 +1193,6 @@ public void setOpenOfficePreferences(OpenOfficePreferences openOfficePreferences put(JabRefPreferences.OO_BIBLIOGRAPHY_STYLE_FILE, openOfficePreferences.getCurrentStyle()); } - private NameFormatterPreferences getNameFormatterPreferences() { - return new NameFormatterPreferences(getStringList(NAME_FORMATER_KEY), getStringList(NAME_FORMATTER_VALUE)); - } - public JabRefPreferences storeVersionPreferences(VersionPreferences versionPreferences) { put(VERSION_IGNORED_UPDATE, versionPreferences.getIgnoredVersion().toString()); return this; @@ -1233,58 +1203,6 @@ public VersionPreferences getVersionPreferences() { return new VersionPreferences(ignoredVersion); } - public JabRefPreferences storePreviewPreferences(PreviewPreferences previewPreferences) { - putInt(CYCLE_PREVIEW_POS, previewPreferences.getPreviewCyclePosition()); - putStringList(CYCLE_PREVIEW, previewPreferences.getPreviewCycle().stream().map(layout -> { - if (layout instanceof CitationStylePreviewLayout) { - return ((CitationStylePreviewLayout) layout).getFilePath(); - } else { - return layout.getName(); - } - }).collect(Collectors.toList())); - putDouble(PREVIEW_PANEL_HEIGHT, previewPreferences.getPreviewPanelDividerPosition().doubleValue()); - put(PREVIEW_STYLE, previewPreferences.getPreviewStyle()); - putBoolean(PREVIEW_AS_TAB, previewPreferences.showPreviewAsExtraTab()); - return this; - } - - @Override - public PreviewPreferences getPreviewPreferences() { - List cycle = getStringList(CYCLE_PREVIEW); - double panelHeight = getDouble(PREVIEW_PANEL_HEIGHT); - String style = get(PREVIEW_STYLE); - String styleDefault = (String) defaults.get(PREVIEW_STYLE); - boolean showAsTab = getBoolean(PREVIEW_AS_TAB); - - // For backwards compatibility always add at least the default preview to the cycle - if (cycle.isEmpty()) { - cycle.add("Preview"); - } - - List layouts = cycle.stream() - .map(layout -> { - if (CitationStyle.isCitationStyleFile(layout)) { - return CitationStyle.createCitationStyleFromFile(layout) - .map(file -> (PreviewLayout) new CitationStylePreviewLayout(file)) - .orElse(null); - } else { - return new TextBasedPreviewLayout(style, getLayoutFormatterPreferences(Globals.journalAbbreviationRepository)); - } - }) - .filter(Objects::nonNull) - .collect(Collectors.toList()); - - int cyclePos; - int storedCyclePos = getInt(CYCLE_PREVIEW_POS); - if (storedCyclePos < layouts.size()) { - cyclePos = storedCyclePos; - } else { - cyclePos = 0; // fallback if stored position is no longer valid - } - - return new PreviewPreferences(layouts, cyclePos, panelHeight, style, styleDefault, showAsTab); - } - public ProtectedTermsPreferences getProtectedTermsPreferences() { return new ProtectedTermsPreferences( getStringList(PROTECTED_TERMS_ENABLED_INTERNAL), @@ -1392,11 +1310,6 @@ public SaveOrderConfig loadExportSaveOrder() { new SaveOrderConfig.SortCriterion(FieldFactory.parseField(get(EXPORT_TERTIARY_SORT_FIELD)), getBoolean(EXPORT_TERTIARY_SORT_DESCENDING))); } - @Override - public Character getKeywordDelimiter() { - return get(KEYWORD_SEPARATOR).charAt(0); - } - public String getOrCreateUserId() { Optional userId = getAsOptional(USER_ID); if (userId.isPresent()) { @@ -1542,6 +1455,12 @@ private void saveCustomEntryTypes(BibDatabaseMode bibDatabaseMode, BibEntryTypes storeBibEntryTypes(customBiblatexBibTexTypes, bibDatabaseMode); } + @Override + @Deprecated + public String getDefaultsDefaultCitationKeyPattern() { + return (String) defaults.get(DEFAULT_CITATION_KEY_PATTERN); + } + //************************************************************************************************************* // GeneralPreferences //************************************************************************************************************* @@ -1660,9 +1579,31 @@ public void storeTimestampPreferences(TimestampPreferences preferences) { } //************************************************************************************************************* - // ToDo: GroupPreferences + // GroupsPreferences //************************************************************************************************************* + @Override + public Character getKeywordDelimiter() { + return get(KEYWORD_SEPARATOR).charAt(0); + } + + @Override + public GroupsPreferences getGroupsPreferences() { + return new GroupsPreferences( + GroupViewMode.valueOf(get(GROUP_INTERSECT_UNION_VIEW_MODE)), + getBoolean(AUTO_ASSIGN_GROUP), + getBoolean(JabRefPreferences.DISPLAY_GROUP_COUNT), + get(JabRefPreferences.KEYWORD_SEPARATOR).charAt(0)); + } + + @Override + public void storeGroupsPreferences(GroupsPreferences preferences) { + put(GROUP_INTERSECT_UNION_VIEW_MODE, preferences.getGroupViewMode().name()); + putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP, preferences.shouldAutoAssignGroup()); + putBoolean(JabRefPreferences.DISPLAY_GROUP_COUNT, preferences.shouldDisplayGroupCount()); + put(KEYWORD_SEPARATOR, String.valueOf(preferences.getKeywordDelimiter())); + } + @Override public GroupViewMode getGroupViewMode() { return GroupViewMode.valueOf(get(GROUP_INTERSECT_UNION_VIEW_MODE)); @@ -2235,7 +2176,7 @@ public ImportFormatPreferences getImportFormatPreferences() { getKeywordDelimiter(), getCitationKeyPatternPreferences(), getFieldContentParserPreferences(), - getXMPPreferences(), + getXmpPreferences(), isKeywordSyncEnabled()); } @@ -2422,9 +2363,102 @@ public void storeShouldAutosave(boolean shouldAutosave) { } //************************************************************************************************************* - // ToDo: Misc preferences + // Preview preferences + //************************************************************************************************************* + + @Override + public PreviewPreferences getPreviewPreferences() { + if (this.previewPreferences == null) { + updatePreviewPreferences(); + } + return this.previewPreferences; + } + + @Override + public void updatePreviewPreferences() { + List cycle = getStringList(CYCLE_PREVIEW); + double panelHeight = getDouble(PREVIEW_PANEL_HEIGHT); + String style = get(PREVIEW_STYLE); + String styleDefault = (String) defaults.get(PREVIEW_STYLE); + boolean showAsTab = getBoolean(PREVIEW_AS_TAB); + + // For backwards compatibility always add at least the default preview to the cycle + if (cycle.isEmpty()) { + cycle.add("Preview"); + } + + List layouts = cycle.stream() + .map(layout -> { + if (CitationStyle.isCitationStyleFile(layout)) { + return CitationStyle.createCitationStyleFromFile(layout) + .map(file -> (PreviewLayout) new CitationStylePreviewLayout(file)) + .orElse(null); + } else { + return new TextBasedPreviewLayout(style, getLayoutFormatterPreferences(Globals.journalAbbreviationRepository)); + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + + int cyclePos; + int storedCyclePos = getInt(CYCLE_PREVIEW_POS); + if (storedCyclePos < layouts.size()) { + cyclePos = storedCyclePos; + } else { + cyclePos = 0; // fallback if stored position is no longer valid + } + + this.previewPreferences = new PreviewPreferences(layouts, cyclePos, panelHeight, style, styleDefault, showAsTab); + } + + @Override + public void storePreviewPreferences(PreviewPreferences previewPreferences) { + putInt(CYCLE_PREVIEW_POS, previewPreferences.getPreviewCyclePosition()); + putStringList(CYCLE_PREVIEW, previewPreferences.getPreviewCycle().stream().map(layout -> { + if (layout instanceof CitationStylePreviewLayout) { + return ((CitationStylePreviewLayout) layout).getFilePath(); + } else { + return layout.getName(); + } + }).collect(Collectors.toList())); + putDouble(PREVIEW_PANEL_HEIGHT, previewPreferences.getPreviewPanelDividerPosition().doubleValue()); + put(PREVIEW_STYLE, previewPreferences.getPreviewStyle()); + putBoolean(PREVIEW_AS_TAB, previewPreferences.showPreviewAsExtraTab()); + + updatePreviewPreferences(); + } + + //************************************************************************************************************* + // Misc preferences //************************************************************************************************************* + @Override + public XmpPreferences getXmpPreferences() { + return new XmpPreferences( + getBoolean(USE_XMP_PRIVACY_FILTER), + getStringList(XMP_PRIVACY_FILTERS).stream().map(FieldFactory::parseField).collect(Collectors.toSet()), + getKeywordDelimiter()); + } + + @Override + public void storeXmpPreferences(XmpPreferences preferences) { + putBoolean(USE_XMP_PRIVACY_FILTER, preferences.shouldUseXmpPrivacyFilter()); + putStringList(XMP_PRIVACY_FILTERS, preferences.getXmpPrivacyFilter().stream().map(Field::getName).collect(Collectors.toList())); + } + + @Override + public NameFormatterPreferences getNameFormatterPreferences() { + return new NameFormatterPreferences( + getStringList(NAME_FORMATER_KEY), + getStringList(NAME_FORMATTER_VALUE)); + } + + @Override + public void storeNameFormatterPreferences(NameFormatterPreferences preferences) { + putStringList(NAME_FORMATER_KEY, preferences.getNameFormatterKey()); + putStringList(NAME_FORMATTER_VALUE, preferences.getNameFormatterValue()); + } + @Override public AutoCompletePreferences getAutoCompletePreferences() { AutoCompletePreferences.NameFormat nameFormat = AutoCompletePreferences.NameFormat.BOTH; diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 8ddd5da2eec..cc565990896 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -9,6 +9,7 @@ import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.entryeditor.EntryEditorPreferences; import org.jabref.gui.groups.GroupViewMode; +import org.jabref.gui.groups.GroupsPreferences; import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.maintable.ColumnPreferences; import org.jabref.gui.maintable.MainTableNameFormatPreferences; @@ -27,6 +28,7 @@ import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Language; import org.jabref.logic.layout.LayoutFormatterPreferences; +import org.jabref.logic.layout.format.NameFormatterPreferences; import org.jabref.logic.net.ProxyPreferences; import org.jabref.logic.openoffice.OpenOfficePreferences; import org.jabref.logic.preferences.OwnerPreferences; @@ -50,8 +52,6 @@ public interface PreferencesService { JournalAbbreviationPreferences getJournalAbbreviationPreferences(); - Character getKeywordDelimiter(); - void storeKeyBindingRepository(KeyBindingRepository keyBindingRepository); KeyBindingRepository getKeyBindingRepository(); @@ -70,8 +70,6 @@ public interface PreferencesService { FieldContentFormatterPreferences getFieldContentParserPreferences(); - XmpPreferences getXMPPreferences(); - Path getWorkingDir(); void setWorkingDir(Path dir); @@ -80,8 +78,6 @@ public interface PreferencesService { void setOpenOfficePreferences(OpenOfficePreferences openOfficePreferences); - PreviewPreferences getPreviewPreferences(); - List getCustomExportFormats(JournalAbbreviationRepository repository); void storeCustomExportFormats(List exporters); @@ -124,6 +120,9 @@ public interface PreferencesService { void setCleanupPreset(CleanupPreset cleanupPreset); + @Deprecated + String getDefaultsDefaultCitationKeyPattern(); + //************************************************************************************************************* // GeneralPreferences //************************************************************************************************************* @@ -157,9 +156,15 @@ public interface PreferencesService { void storeTimestampPreferences(TimestampPreferences preferences); //************************************************************************************************************* - // ToDo: GroupPreferences + // GroupsPreferences //************************************************************************************************************* + Character getKeywordDelimiter(); + + GroupsPreferences getGroupsPreferences(); + + void storeGroupsPreferences(GroupsPreferences preferences); + GroupViewMode getGroupViewMode(); void setGroupViewMode(GroupViewMode mode); @@ -275,9 +280,27 @@ public interface PreferencesService { void storeShouldAutosave(boolean shouldAutosave); //************************************************************************************************************* - // ToDo: Misc preferences + // Preview preferences //************************************************************************************************************* + PreviewPreferences getPreviewPreferences(); + + void updatePreviewPreferences(); + + void storePreviewPreferences(PreviewPreferences previewPreferences); + + //************************************************************************************************************* + // Misc preferences + //************************************************************************************************************* + + XmpPreferences getXmpPreferences(); + + void storeXmpPreferences(XmpPreferences preferences); + + NameFormatterPreferences getNameFormatterPreferences(); + + void storeNameFormatterPreferences(NameFormatterPreferences preferences); + AutoCompletePreferences getAutoCompletePreferences(); void storeAutoCompletePreferences(AutoCompletePreferences autoCompletePreferences); diff --git a/src/test/java/org/jabref/logic/exporter/XmpExporterTest.java b/src/test/java/org/jabref/logic/exporter/XmpExporterTest.java index e636e1135cd..762f14de866 100644 --- a/src/test/java/org/jabref/logic/exporter/XmpExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/XmpExporterTest.java @@ -185,7 +185,7 @@ public void writeMultipleEntriesInDifferentFiles(@TempDir Path testFolder) throw @Test public void exportSingleEntryWithPrivacyFilter(@TempDir Path testFolder) throws Exception { when(xmpPreferences.getXmpPrivacyFilter()).thenReturn(Collections.singleton(StandardField.AUTHOR)); - when(xmpPreferences.isUseXMPPrivacyFilter()).thenReturn(true); + when(xmpPreferences.shouldUseXmpPrivacyFilter()).thenReturn(true); Path file = testFolder.resolve("ThisIsARandomlyNamedFile"); Files.createFile(file); diff --git a/src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java b/src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java index c30f8702d2c..6158930f2da 100644 --- a/src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java +++ b/src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java @@ -41,7 +41,7 @@ void setUp() { when(importFormatPreferences.getEncoding()).thenReturn(StandardCharsets.UTF_8); xmpPreferences = mock(XmpPreferences.class); // The code assumes privacy filters to be off - when(xmpPreferences.isUseXMPPrivacyFilter()).thenReturn(false); + when(xmpPreferences.shouldUseXmpPrivacyFilter()).thenReturn(false); when(xmpPreferences.getKeywordSeparator()).thenReturn(','); diff --git a/src/test/java/org/jabref/logic/xmp/XmpUtilWriterTest.java b/src/test/java/org/jabref/logic/xmp/XmpUtilWriterTest.java index 5b1da8d5f67..e8afd51e3f7 100644 --- a/src/test/java/org/jabref/logic/xmp/XmpUtilWriterTest.java +++ b/src/test/java/org/jabref/logic/xmp/XmpUtilWriterTest.java @@ -77,7 +77,7 @@ private void initBibEntries() { void setUp() { xmpPreferences = mock(XmpPreferences.class); // The code assumes privacy filters to be off - when(xmpPreferences.isUseXMPPrivacyFilter()).thenReturn(false); + when(xmpPreferences.shouldUseXmpPrivacyFilter()).thenReturn(false); when(xmpPreferences.getKeywordSeparator()).thenReturn(',');