From c1ab2bffad0acb8073a95bce987b25c8abf52453 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 9 Sep 2024 17:57:41 +0200 Subject: [PATCH] Pull down CoreGuiPreferences and Workspace preferences --- .../jabref/gui/dialogs/AutosaveUiManager.java | 4 +- .../org/jabref/gui/exporter/SaveAction.java | 6 +- .../jabref/gui/exporter/SaveAllAction.java | 6 +- .../gui/exporter/SaveDatabaseAction.java | 6 +- .../org/jabref/gui/groups/GroupTreeView.java | 6 +- .../gui/preferences/GuiPreferences.java | 6 + .../gui/preferences/JabRefGuiPreferences.java | 155 ++++++++++++++++- .../general/GeneralTabViewModel.java | 5 +- .../gui/slr/ManageStudyDefinitionView.java | 16 +- .../jabref/http/server/LibrariesResource.java | 9 +- .../jabref/http/server/LibraryResource.java | 11 +- .../java/org/jabref/http/server/Server.java | 5 +- .../logic/preferences/CliPreferences.java | 6 - .../preferences/JabRefCliPreferences.java | 159 +----------------- .../migrations/PreferencesMigrations.java | 4 +- .../gui/exporter/SaveDatabaseActionTest.java | 14 +- .../org/jabref/http/server/ServerTest.java | 2 + .../GuiPreferencesMigrationsTest.java | 5 +- .../styletester/StyleTesterMain.java | 4 +- 19 files changed, 220 insertions(+), 209 deletions(-) diff --git a/src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java b/src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java index 8fd8f7fcf55..ed57563c30c 100644 --- a/src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java +++ b/src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java @@ -3,9 +3,9 @@ import org.jabref.gui.DialogService; import org.jabref.gui.LibraryTab; import org.jabref.gui.exporter.SaveDatabaseAction; +import org.jabref.gui.preferences.GuiPreferences; import org.jabref.model.database.event.AutosaveEvent; import org.jabref.model.entry.BibEntryTypesManager; -import org.jabref.logic.preferences.CliPreferences; import com.google.common.eventbus.Subscribe; import org.slf4j.Logger; @@ -20,7 +20,7 @@ public class AutosaveUiManager { private final SaveDatabaseAction saveDatabaseAction; - public AutosaveUiManager(LibraryTab libraryTab, DialogService dialogService, CliPreferences preferences, BibEntryTypesManager entryTypesManager) { + public AutosaveUiManager(LibraryTab libraryTab, DialogService dialogService, GuiPreferences preferences, BibEntryTypesManager entryTypesManager) { this.saveDatabaseAction = new SaveDatabaseAction(libraryTab, dialogService, preferences, entryTypesManager); } diff --git a/src/main/java/org/jabref/gui/exporter/SaveAction.java b/src/main/java/org/jabref/gui/exporter/SaveAction.java index 1f76ee09642..04b12fd8892 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveAction.java @@ -7,8 +7,8 @@ import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; +import org.jabref.gui.preferences.GuiPreferences; import org.jabref.model.entry.BibEntryTypesManager; -import org.jabref.logic.preferences.CliPreferences; import com.airhacks.afterburner.injection.Injector; @@ -23,12 +23,12 @@ public enum SaveMethod { SAVE, SAVE_AS, SAVE_SELECTED } private final Supplier tabSupplier; private final DialogService dialogService; - private final CliPreferences preferences; + private final GuiPreferences preferences; public SaveAction(SaveMethod saveMethod, Supplier tabSupplier, DialogService dialogService, - CliPreferences preferences, + GuiPreferences preferences, StateManager stateManager) { this.saveMethod = saveMethod; this.tabSupplier = tabSupplier; diff --git a/src/main/java/org/jabref/gui/exporter/SaveAllAction.java b/src/main/java/org/jabref/gui/exporter/SaveAllAction.java index d66ef93fe69..a31329039be 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveAllAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveAllAction.java @@ -6,9 +6,9 @@ import org.jabref.gui.DialogService; import org.jabref.gui.LibraryTab; import org.jabref.gui.actions.SimpleCommand; +import org.jabref.gui.preferences.GuiPreferences; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntryTypesManager; -import org.jabref.logic.preferences.CliPreferences; import com.airhacks.afterburner.injection.Injector; @@ -16,9 +16,9 @@ public class SaveAllAction extends SimpleCommand { private final Supplier> tabsSupplier; private final DialogService dialogService; - private final CliPreferences preferences; + private final GuiPreferences preferences; - public SaveAllAction(Supplier> tabsSupplier, CliPreferences preferences, DialogService dialogService) { + public SaveAllAction(Supplier> tabsSupplier, GuiPreferences preferences, DialogService dialogService) { this.tabsSupplier = tabsSupplier; this.dialogService = dialogService; this.preferences = preferences; diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index 2ba60621655..3e1449ba123 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -24,6 +24,7 @@ import org.jabref.gui.autosaveandbackup.BackupManager; import org.jabref.gui.maintable.BibEntryTableViewModel; import org.jabref.gui.maintable.columns.MainTableColumn; +import org.jabref.gui.preferences.GuiPreferences; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.logic.exporter.AtomicFileWriter; import org.jabref.logic.exporter.BibDatabaseWriter; @@ -42,7 +43,6 @@ import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.metadata.SaveOrder; import org.jabref.model.metadata.SelfContainedSaveOrder; -import org.jabref.logic.preferences.CliPreferences; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,7 +59,7 @@ public class SaveDatabaseAction { private final LibraryTab libraryTab; private final DialogService dialogService; - private final CliPreferences preferences; + private final GuiPreferences preferences; private final BibEntryTypesManager entryTypesManager; public enum SaveDatabaseMode { @@ -68,7 +68,7 @@ public enum SaveDatabaseMode { public SaveDatabaseAction(LibraryTab libraryTab, DialogService dialogService, - CliPreferences preferences, + GuiPreferences preferences, BibEntryTypesManager entryTypesManager) { this.libraryTab = libraryTab; this.dialogService = dialogService; diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeView.java b/src/main/java/org/jabref/gui/groups/GroupTreeView.java index 921f7fc9a98..a28919ef26e 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeView.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeView.java @@ -51,6 +51,7 @@ import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.actions.StandardActions; import org.jabref.gui.ai.chatting.chathistory.ChatHistoryService; +import org.jabref.gui.preferences.GuiPreferences; import org.jabref.gui.search.SearchTextField; import org.jabref.gui.util.BindingsHelper; import org.jabref.gui.util.ControlHelper; @@ -61,7 +62,6 @@ import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.TaskExecutor; import org.jabref.model.entry.BibEntry; -import org.jabref.logic.preferences.CliPreferences; import com.tobiasdiez.easybind.EasyBind; import org.controlsfx.control.textfield.CustomTextField; @@ -84,7 +84,7 @@ public class GroupTreeView extends BorderPane { private final DialogService dialogService; private final ChatHistoryService chatHistoryService; private final TaskExecutor taskExecutor; - private final CliPreferences preferences; + private final GuiPreferences preferences; private TreeTableView groupTree; private TreeTableColumn mainColumn; @@ -106,7 +106,7 @@ public class GroupTreeView extends BorderPane { */ public GroupTreeView(TaskExecutor taskExecutor, StateManager stateManager, - CliPreferences preferences, + GuiPreferences preferences, DialogService dialogService, ChatHistoryService chatHistoryService ) { diff --git a/src/main/java/org/jabref/gui/preferences/GuiPreferences.java b/src/main/java/org/jabref/gui/preferences/GuiPreferences.java index 4e497d44c82..056e3e76d11 100644 --- a/src/main/java/org/jabref/gui/preferences/GuiPreferences.java +++ b/src/main/java/org/jabref/gui/preferences/GuiPreferences.java @@ -1,5 +1,7 @@ package org.jabref.gui.preferences; +import org.jabref.gui.CoreGuiPreferences; +import org.jabref.gui.WorkspacePreferences; import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.entryeditor.EntryEditorPreferences; import org.jabref.gui.mergeentries.MergeDialogPreferences; @@ -10,4 +12,8 @@ public interface GuiPreferences extends org.jabref.logic.preferences.CliPreferen MergeDialogPreferences getMergeDialogPreferences(); AutoCompletePreferences getAutoCompletePreferences(); + + CoreGuiPreferences getGuiPreferences(); + + WorkspacePreferences getWorkspacePreferences(); } diff --git a/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java b/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java index 2a7f2c9227b..f018e137f15 100644 --- a/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java +++ b/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java @@ -1,5 +1,6 @@ package org.jabref.gui.preferences; +import java.nio.file.Path; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -7,15 +8,23 @@ import java.util.Set; import java.util.stream.Collectors; +import javafx.beans.InvalidationListener; +import javafx.collections.ListChangeListener; import javafx.collections.SetChangeListener; +import org.jabref.gui.CoreGuiPreferences; +import org.jabref.gui.WorkspacePreferences; import org.jabref.gui.autocompleter.AutoCompletePreferences; import org.jabref.gui.duplicationFinder.DuplicateResolverDialog; import org.jabref.gui.entryeditor.EntryEditorPreferences; import org.jabref.gui.mergeentries.DiffMode; import org.jabref.gui.mergeentries.MergeDialogPreferences; +import org.jabref.gui.theme.Theme; +import org.jabref.logic.importer.fetcher.DoiFetcher; +import org.jabref.logic.l10n.Localization; import org.jabref.logic.preferences.AutoCompleteFirstNameMode; import org.jabref.logic.preferences.JabRefCliPreferences; +import org.jabref.logic.util.io.FileHistory; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; import org.jabref.model.strings.StringUtil; @@ -24,8 +33,20 @@ public class JabRefGuiPreferences extends JabRefCliPreferences implements GuiPreferences { - // AutcompleteFields - public because needed for pref migration + // Public because needed for pref migration public static final String AUTOCOMPLETER_COMPLETE_FIELDS = "autoCompleteFields"; + public static final String MAIN_FONT_SIZE = "mainFontSize"; + + // region workspace + private static final String THEME = "fxTheme"; + private static final String THEME_SYNC_OS = "themeSyncOs"; + private static final String OPEN_LAST_EDITED = "openLastEdited"; + private static final String OVERRIDE_DEFAULT_FONT_SIZE = "overrideDefaultFontSize"; + private static final String SHOW_ADVANCED_HINTS = "showAdvancedHints"; + private static final String CONFIRM_DELETE = "confirmDelete"; + // endregion + + private static final String RECENT_DATABASES = "recentDatabases"; private static final String ENTRY_EDITOR_HEIGHT = "entryEditorHeightFX"; @@ -41,13 +62,20 @@ public class JabRefGuiPreferences extends JabRefCliPreferences implements GuiPre private static final String AUTOCOMPLETER_FIRSTNAME_MODE = "autoCompFirstNameMode"; private static final String AUTOCOMPLETER_LAST_FIRST = "autoCompLF"; private static final String AUTOCOMPLETER_FIRST_LAST = "autoCompFF"; - // endregion + // endregion + + private static final String LAST_FOCUSED = "lastFocused"; + private static final String ID_ENTRY_GENERATOR = "idEntryGenerator"; + // SLR + private static final String SELECTED_SLR_CATALOGS = "selectedSlrCatalogs"; private static JabRefGuiPreferences singleton; private EntryEditorPreferences entryEditorPreferences; private MergeDialogPreferences mergeDialogPreferences; private AutoCompletePreferences autoCompletePreferences; + private CoreGuiPreferences coreGuiPreferences; + private WorkspacePreferences workspacePreferences; private JabRefGuiPreferences() { super(); @@ -74,6 +102,23 @@ private JabRefGuiPreferences() { 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"); // endregion + + // region coreGuiPreferences + // Set DOI to be the default ID entry generator + defaults.put(ID_ENTRY_GENERATOR, DoiFetcher.NAME); + defaults.put(RECENT_DATABASES, ""); + defaults.put(LAST_FOCUSED, ""); + // endregion + + // region workspace + defaults.put(MAIN_FONT_SIZE, 9); + defaults.put(OVERRIDE_DEFAULT_FONT_SIZE, false); + defaults.put(OPEN_LAST_EDITED, Boolean.TRUE); + defaults.put(THEME, Theme.BASE_CSS); + defaults.put(THEME_SYNC_OS, Boolean.FALSE); + defaults.put(CONFIRM_DELETE, Boolean.TRUE); + defaults.put(SHOW_ADVANCED_HINTS, Boolean.TRUE); + // endregion } @Deprecated @@ -261,4 +306,110 @@ public AutoCompletePreferences getAutoCompletePreferences() { return autoCompletePreferences; } + + // region (core) GUI preferences + public CoreGuiPreferences getGuiPreferences() { + if (coreGuiPreferences != null) { + return coreGuiPreferences; + } + + coreGuiPreferences = new CoreGuiPreferences( + getDouble(MAIN_WINDOW_POS_X), + getDouble(MAIN_WINDOW_POS_Y), + getDouble(MAIN_WINDOW_WIDTH), + getDouble(MAIN_WINDOW_HEIGHT), + getBoolean(WINDOW_MAXIMISED), + getStringList(LAST_EDITED).stream() + .map(Path::of) + .collect(Collectors.toList()), + Path.of(get(LAST_FOCUSED)), + getFileHistory(), + get(ID_ENTRY_GENERATOR), + getDouble(SIDE_PANE_WIDTH)); + + EasyBind.listen(coreGuiPreferences.positionXProperty(), (obs, oldValue, newValue) -> putDouble(MAIN_WINDOW_POS_X, newValue.doubleValue())); + EasyBind.listen(coreGuiPreferences.positionYProperty(), (obs, oldValue, newValue) -> putDouble(MAIN_WINDOW_POS_Y, newValue.doubleValue())); + EasyBind.listen(coreGuiPreferences.sizeXProperty(), (obs, oldValue, newValue) -> putDouble(MAIN_WINDOW_WIDTH, newValue.doubleValue())); + EasyBind.listen(coreGuiPreferences.sizeYProperty(), (obs, oldValue, newValue) -> putDouble(MAIN_WINDOW_HEIGHT, newValue.doubleValue())); + EasyBind.listen(coreGuiPreferences.windowMaximisedProperty(), (obs, oldValue, newValue) -> putBoolean(WINDOW_MAXIMISED, newValue)); + EasyBind.listen(coreGuiPreferences.sidePaneWidthProperty(), (obs, oldValue, newValue) -> putDouble(SIDE_PANE_WIDTH, newValue.doubleValue())); + + coreGuiPreferences.getLastFilesOpened().addListener((ListChangeListener) change -> { + if (change.getList().isEmpty()) { + remove(LAST_EDITED); + } else { + putStringList(LAST_EDITED, coreGuiPreferences.getLastFilesOpened().stream() + .map(Path::toAbsolutePath) + .map(Path::toString) + .collect(Collectors.toList())); + } + }); + EasyBind.listen(coreGuiPreferences.lastFocusedFileProperty(), (obs, oldValue, newValue) -> { + if (newValue != null) { + put(LAST_FOCUSED, newValue.toAbsolutePath().toString()); + } else { + remove(LAST_FOCUSED); + } + }); + coreGuiPreferences.getFileHistory().addListener((InvalidationListener) change -> storeFileHistory(coreGuiPreferences.getFileHistory())); + EasyBind.listen(coreGuiPreferences.lastSelectedIdBasedFetcherProperty(), (obs, oldValue, newValue) -> put(ID_ENTRY_GENERATOR, newValue)); + + return coreGuiPreferences; + } + + private FileHistory getFileHistory() { + return FileHistory.of(getStringList(RECENT_DATABASES).stream() + .map(Path::of) + .toList()); + } + + private void storeFileHistory(FileHistory history) { + putStringList(RECENT_DATABASES, history.stream() + .map(Path::toAbsolutePath) + .map(Path::toString) + .toList()); + } + // endregion + + + @Override + public WorkspacePreferences getWorkspacePreferences() { + if (workspacePreferences != null) { + return workspacePreferences; + } + + workspacePreferences = new WorkspacePreferences( + getLanguage(), + getBoolean(OVERRIDE_DEFAULT_FONT_SIZE), + getInt(MAIN_FONT_SIZE), + (Integer) defaults.get(MAIN_FONT_SIZE), + new Theme(get(THEME)), + getBoolean(THEME_SYNC_OS), + getBoolean(OPEN_LAST_EDITED), + getBoolean(SHOW_ADVANCED_HINTS), + getBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION), + getBoolean(CONFIRM_DELETE), + getStringList(SELECTED_SLR_CATALOGS)); + + EasyBind.listen(workspacePreferences.languageProperty(), (obs, oldValue, newValue) -> { + put(LANGUAGE, newValue.getId()); + if (oldValue != newValue) { + setLanguageDependentDefaultValues(); + Localization.setLanguage(newValue); + } + }); + + EasyBind.listen(workspacePreferences.shouldOverrideDefaultFontSizeProperty(), (obs, oldValue, newValue) -> putBoolean(OVERRIDE_DEFAULT_FONT_SIZE, newValue)); + EasyBind.listen(workspacePreferences.mainFontSizeProperty(), (obs, oldValue, newValue) -> putInt(MAIN_FONT_SIZE, newValue)); + EasyBind.listen(workspacePreferences.themeProperty(), (obs, oldValue, newValue) -> put(THEME, newValue.getName())); + EasyBind.listen(workspacePreferences.themeSyncOsProperty(), (obs, oldValue, newValue) -> putBoolean(THEME_SYNC_OS, newValue)); + EasyBind.listen(workspacePreferences.openLastEditedProperty(), (obs, oldValue, newValue) -> putBoolean(OPEN_LAST_EDITED, newValue)); + EasyBind.listen(workspacePreferences.showAdvancedHintsProperty(), (obs, oldValue, newValue) -> putBoolean(SHOW_ADVANCED_HINTS, newValue)); + EasyBind.listen(workspacePreferences.warnAboutDuplicatesInInspectionProperty(), (obs, oldValue, newValue) -> putBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION, newValue)); + EasyBind.listen(workspacePreferences.confirmDeleteProperty(), (obs, oldValue, newValue) -> putBoolean(CONFIRM_DELETE, newValue)); + workspacePreferences.getSelectedSlrCatalogs().addListener((ListChangeListener) change -> + putStringList(SELECTED_SLR_CATALOGS, workspacePreferences.getSelectedSlrCatalogs())); + return workspacePreferences; + } + } diff --git a/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java b/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java index 7d1327b5e41..64c80e8b410 100644 --- a/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java @@ -23,6 +23,7 @@ import org.jabref.gui.WorkspacePreferences; import org.jabref.gui.desktop.os.NativeDesktop; import org.jabref.gui.frame.UiMessageHandler; +import org.jabref.gui.preferences.GuiPreferences; import org.jabref.gui.preferences.PreferenceTabViewModel; import org.jabref.gui.remote.CLIMessageHandler; import org.jabref.gui.theme.Theme; @@ -34,6 +35,7 @@ import org.jabref.logic.l10n.Language; import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.ssl.TrustStoreManager; +import org.jabref.logic.preferences.CliPreferences; import org.jabref.logic.remote.RemotePreferences; import org.jabref.logic.remote.RemoteUtil; import org.jabref.logic.remote.server.RemoteListenerServerManager; @@ -42,7 +44,6 @@ import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.strings.StringUtil; import org.jabref.model.util.FileUpdateMonitor; -import org.jabref.logic.preferences.CliPreferences; import com.airhacks.afterburner.injection.Injector; import de.saxsys.mvvmfx.utils.validation.CompositeValidator; @@ -104,7 +105,7 @@ public class GeneralTabViewModel implements PreferenceTabViewModel { private final BibEntryTypesManager entryTypesManager; private final TrustStoreManager trustStoreManager; - public GeneralTabViewModel(DialogService dialogService, CliPreferences preferences, FileUpdateMonitor fileUpdateMonitor, BibEntryTypesManager entryTypesManager) { + public GeneralTabViewModel(DialogService dialogService, GuiPreferences preferences, FileUpdateMonitor fileUpdateMonitor, BibEntryTypesManager entryTypesManager) { this.dialogService = dialogService; this.preferences = preferences; this.workspacePreferences = preferences.getWorkspacePreferences(); diff --git a/src/main/java/org/jabref/gui/slr/ManageStudyDefinitionView.java b/src/main/java/org/jabref/gui/slr/ManageStudyDefinitionView.java index db88455cf10..519b9899ed2 100644 --- a/src/main/java/org/jabref/gui/slr/ManageStudyDefinitionView.java +++ b/src/main/java/org/jabref/gui/slr/ManageStudyDefinitionView.java @@ -26,6 +26,7 @@ import org.jabref.gui.DialogService; import org.jabref.gui.icon.IconTheme; +import org.jabref.gui.preferences.GuiPreferences; import org.jabref.gui.theme.ThemeManager; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.DirectoryDialogConfiguration; @@ -33,7 +34,6 @@ import org.jabref.gui.util.ViewModelTableRowFactory; import org.jabref.logic.l10n.Localization; import org.jabref.model.study.Study; -import org.jabref.logic.preferences.CliPreferences; import com.airhacks.afterburner.views.ViewLoader; import jakarta.inject.Inject; @@ -76,7 +76,7 @@ public class ManageStudyDefinitionView extends BaseDialog @FXML private Label directoryWarning; @Inject private DialogService dialogService; - @Inject private CliPreferences prefs; + @Inject private GuiPreferences preferences; @Inject private ThemeManager themeManager; private ManageStudyDefinitionViewModel viewModel; @@ -157,17 +157,17 @@ private void setupSaveSurveyButton(boolean isEdit) { private void initialize() { if (study.isEmpty()) { viewModel = new ManageStudyDefinitionViewModel( - prefs.getImportFormatPreferences(), - prefs.getImporterPreferences(), - prefs.getWorkspacePreferences(), + preferences.getImportFormatPreferences(), + preferences.getImporterPreferences(), + preferences.getWorkspacePreferences(), dialogService); } else { viewModel = new ManageStudyDefinitionViewModel( study.get(), pathToStudyDataDirectory, - prefs.getImportFormatPreferences(), - prefs.getImporterPreferences(), - prefs.getWorkspacePreferences(), + preferences.getImportFormatPreferences(), + preferences.getImporterPreferences(), + preferences.getWorkspacePreferences(), dialogService); // The directory of the study cannot be changed diff --git a/src/main/java/org/jabref/http/server/LibrariesResource.java b/src/main/java/org/jabref/http/server/LibrariesResource.java index a19c84f3015..7292786d41f 100644 --- a/src/main/java/org/jabref/http/server/LibrariesResource.java +++ b/src/main/java/org/jabref/http/server/LibrariesResource.java @@ -2,7 +2,6 @@ import java.util.List; -import org.jabref.logic.util.io.BackupFileUtil; import org.jabref.logic.preferences.CliPreferences; import com.google.gson.Gson; @@ -20,9 +19,9 @@ public class LibrariesResource { @GET @Produces(MediaType.APPLICATION_JSON) public String get() { - List fileNamesWithUniqueSuffix = preferences.getGuiPreferences().getLastFilesOpened().stream() - .map(p -> p.getFileName() + "-" + BackupFileUtil.getUniqueFilePrefix(p)) - .toList(); - return new Gson().toJson(fileNamesWithUniqueSuffix); +// List fileNamesWithUniqueSuffix = preferences.getGuiPreferences().getLastFilesOpened().stream() +// .map(p -> p.getFileName() + "-" + BackupFileUtil.getUniqueFilePrefix(p)) +// .toList(); + return new Gson().toJson(List.of()); } } diff --git a/src/main/java/org/jabref/http/server/LibraryResource.java b/src/main/java/org/jabref/http/server/LibraryResource.java index 885e4424110..4b51dd28d70 100644 --- a/src/main/java/org/jabref/http/server/LibraryResource.java +++ b/src/main/java/org/jabref/http/server/LibraryResource.java @@ -89,10 +89,11 @@ public Response getBibtex(@PathParam("id") String id) { } private java.nio.file.Path getLibraryPath(String id) { - return preferences.getGuiPreferences().getLastFilesOpened() - .stream() - .filter(p -> (p.getFileName() + "-" + BackupFileUtil.getUniqueFilePrefix(p)).equals(id)) - .findAny() - .orElseThrow(NotFoundException::new); +// return preferences.getGuiPreferences().getLastFilesOpened() +// .stream() +// .filter(p -> (p.getFileName() + "-" + BackupFileUtil.getUniqueFilePrefix(p)).equals(id)) +// .findAny() +// .orElseThrow(NotFoundException::new); + throw new NotFoundException(); } } diff --git a/src/main/java/org/jabref/http/server/Server.java b/src/main/java/org/jabref/http/server/Server.java index 47c0663fa2d..6f83c9271f8 100644 --- a/src/main/java/org/jabref/http/server/Server.java +++ b/src/main/java/org/jabref/http/server/Server.java @@ -9,11 +9,8 @@ import javax.net.ssl.SSLContext; -import javafx.collections.ObservableList; - import org.jabref.architecture.AllowedToUseStandardStreams; import org.jabref.logic.os.OS; -import org.jabref.logic.preferences.JabRefCliPreferences; import jakarta.ws.rs.SeBootstrap; import net.harawata.appdirs.AppDirsFactory; @@ -36,7 +33,7 @@ public static void main(final String[] args) throws InterruptedException, URISyn SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); - final ObservableList lastFilesOpened = JabRefCliPreferences.getInstance().getGuiPreferences().getLastFilesOpened(); + final List lastFilesOpened = List.of(); // JabRefCliPreferences.getInstance().getGuiPreferences().getLastFilesOpened(); // The server serves the last opened files (see org.jabref.http.server.LibraryResource.getLibraryPath) // In a testing environment, this might be difficult to handle diff --git a/src/main/java/org/jabref/logic/preferences/CliPreferences.java b/src/main/java/org/jabref/logic/preferences/CliPreferences.java index 9ff826a904d..792f66bdc55 100644 --- a/src/main/java/org/jabref/logic/preferences/CliPreferences.java +++ b/src/main/java/org/jabref/logic/preferences/CliPreferences.java @@ -4,8 +4,6 @@ import java.util.Map; import java.util.prefs.BackingStoreException; -import org.jabref.gui.CoreGuiPreferences; -import org.jabref.gui.WorkspacePreferences; import org.jabref.gui.externalfiles.UnlinkedFilesDialogPreferences; import org.jabref.gui.frame.ExternalApplicationsPreferences; import org.jabref.gui.frame.SidePanePreferences; @@ -124,8 +122,6 @@ public interface CliPreferences { ColumnPreferences getSearchDialogColumnPreferences(); - WorkspacePreferences getWorkspacePreferences(); - AutoLinkPreferences getAutoLinkPreferences(); ExportPreferences getExportPreferences(); @@ -138,8 +134,6 @@ public interface CliPreferences { SidePanePreferences getSidePanePreferences(); - CoreGuiPreferences getGuiPreferences(); - XmpPreferences getXmpPreferences(); NameFormatterPreferences getNameFormatterPreferences(); diff --git a/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java b/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java index 5a372cc69e1..719cf04c327 100644 --- a/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java +++ b/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java @@ -27,13 +27,10 @@ import java.util.stream.Stream; import javafx.beans.InvalidationListener; -import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import javafx.collections.SetChangeListener; import javafx.scene.control.TableColumn.SortType; -import org.jabref.gui.CoreGuiPreferences; -import org.jabref.gui.WorkspacePreferences; import org.jabref.gui.desktop.os.NativeDesktop; import org.jabref.gui.externalfiles.UnlinkedFilesDialogPreferences; import org.jabref.gui.externalfiletype.ExternalFileType; @@ -54,7 +51,6 @@ import org.jabref.gui.push.PushToApplications; import org.jabref.gui.sidepane.SidePaneType; import org.jabref.gui.specialfields.SpecialFieldsPreferences; -import org.jabref.gui.theme.Theme; import org.jabref.logic.FilePreferences; import org.jabref.logic.InternalPreferences; import org.jabref.logic.JabRefException; @@ -81,7 +77,6 @@ import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.fetcher.ACMPortalFetcher; import org.jabref.logic.importer.fetcher.DBLPFetcher; -import org.jabref.logic.importer.fetcher.DoiFetcher; import org.jabref.logic.importer.fetcher.GrobidPreferences; import org.jabref.logic.importer.fetcher.IEEE; import org.jabref.logic.importer.fetcher.MrDlibPreferences; @@ -116,7 +111,6 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.logic.util.Version; import org.jabref.logic.util.io.AutoLinkPreferences; -import org.jabref.logic.util.io.FileHistory; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.ai.AiProvider; import org.jabref.model.ai.EmbeddingModel; @@ -177,8 +171,6 @@ public class JabRefCliPreferences implements CliPreferences { * There are more default parameters in this map which belong to separate preference classes. */ public static final String EXTERNAL_FILE_TYPES = "externalFileTypes"; - public static final String THEME = "fxTheme"; - public static final String THEME_SYNC_OS = "themeSyncOs"; public static final String LANGUAGE = "language"; public static final String NAMES_LAST_ONLY = "namesLastOnly"; public static final String ABBR_AUTHOR_NAMES = "abbrAuthorNames"; @@ -224,8 +216,6 @@ public class JabRefCliPreferences implements CliPreferences { public static final String MAIN_WINDOW_HEIGHT = "mainWindowSizeY"; public static final String LAST_EDITED = "lastEdited"; - public static final String OPEN_LAST_EDITED = "openLastEdited"; - public static final String LAST_FOCUSED = "lastFocused"; public static final String AUTO_OPEN_FORM = "autoOpenForm"; public static final String IMPORT_WORKING_DIRECTORY = "importWorkingDirectory"; public static final String LAST_USED_EXPORT = "lastUsedExport"; @@ -238,12 +228,8 @@ public class JabRefCliPreferences implements CliPreferences { public static final String AUTO_ASSIGN_GROUP = "autoAssignGroup"; public static final String DISPLAY_GROUP_COUNT = "displayGroupCount"; public static final String EXTRA_FILE_COLUMNS = "extraFileColumns"; - public static final String OVERRIDE_DEFAULT_FONT_SIZE = "overrideDefaultFontSize"; - public static final String MAIN_FONT_SIZE = "mainFontSize"; - public static final String RECENT_DATABASES = "recentDatabases"; public static final String MEMORY_STICK_MODE = "memoryStickMode"; - public static final String SHOW_ADVANCED_HINTS = "showAdvancedHints"; public static final String DEFAULT_ENCODING = "defaultEncoding"; public static final String BASE_DOI_URI = "baseDOIURI"; @@ -261,7 +247,6 @@ public class JabRefCliPreferences implements CliPreferences { public static final String ADD_CREATION_DATE = "addCreationDate"; public static final String ADD_MODIFICATION_DATE = "addModificationDate"; - public static final String WARN_ABOUT_DUPLICATES_IN_INSPECTION = "warnAboutDuplicatesInInspection"; public static final String NON_WRAPPABLE_FIELDS = "nonWrappableFields"; public static final String RESOLVE_STRINGS_FOR_FIELDS = "resolveStringsForFields"; public static final String DO_NOT_RESOLVE_STRINGS = "doNotResolveStrings"; @@ -306,7 +291,6 @@ public class JabRefCliPreferences implements CliPreferences { public static final String DEFAULT_CITATION_KEY_PATTERN = "defaultBibtexKeyPattern"; public static final String UNWANTED_CITATION_KEY_CHARACTERS = "defaultUnwantedBibtexKeyCharacters"; - public static final String CONFIRM_DELETE = "confirmDelete"; public static final String CONFIRM_LINKED_FILE_DELETE = "confirmLinkedFileDelete"; public static final String TRASH_INSTEAD_OF_DELETE = "trashInsteadOfDelete"; public static final String WARN_BEFORE_OVERWRITING_KEY = "warnBeforeOverwritingKey"; @@ -384,9 +368,6 @@ public class JabRefCliPreferences implements CliPreferences { // KeyBindings - keys - public because needed for pref migration public static final String BINDINGS = "bindings"; - // Id Entry Generator Preferences - public static final String ID_ENTRY_GENERATOR = "idEntryGenerator"; - // String delimiter public static final Character STRINGLIST_DELIMITER = ';'; @@ -398,6 +379,9 @@ public class JabRefCliPreferences implements CliPreferences { public static final String PREVIEW_IN_ENTRY_TABLE_TOOLTIP = "previewInEntryTableTooltip"; public static final String PREVIEW_BST_LAYOUT_PATHS = "previewBstLayoutPaths"; + // TODO: USed by both importer preferences and workspace preferences + protected static final String WARN_ABOUT_DUPLICATES_IN_INSPECTION = "warnAboutDuplicatesInInspection"; + // UI private static final String FONT_FAMILY = "fontFamily"; @@ -476,9 +460,6 @@ public class JabRefCliPreferences implements CliPreferences { private static final Logger LOGGER = LoggerFactory.getLogger(JabRefCliPreferences.class); private static final java.util.prefs.Preferences PREFS_NODE = java.util.prefs.Preferences.userRoot().node("/org/jabref"); - // SLR - private static final String SELECTED_SLR_CATALOGS = "selectedSlrCatalogs"; - // The only instance of this class: private static JabRefCliPreferences singleton; /** @@ -500,13 +481,11 @@ public class JabRefCliPreferences implements CliPreferences { private PreviewPreferences previewPreferences; private OpenOfficePreferences openOfficePreferences; private SidePanePreferences sidePanePreferences; - private WorkspacePreferences workspacePreferences; private ImporterPreferences importerPreferences; private GrobidPreferences grobidPreferences; private ProtectedTermsPreferences protectedTermsPreferences; private MrDlibPreferences mrDlibPreferences; private FilePreferences filePreferences; - private CoreGuiPreferences coreGuiPreferences; private RemotePreferences remotePreferences; private ProxyPreferences proxyPreferences; private SSLPreferences sslPreferences; @@ -543,7 +522,7 @@ protected JabRefCliPreferences() { importPreferences(Path.of("jabref.xml")); } } catch (JabRefException e) { - LOGGER.warn("Could not import preferences from jabref.xml: {}", e.getMessage(), e); + LOGGER.warn("Could not import preferences from jabref.xml", e); } // load user preferences @@ -588,9 +567,6 @@ protected JabRefCliPreferences() { defaults.put(BIBLATEX_DEFAULT_MODE, Boolean.FALSE); - // Set DOI to be the default ID entry generator - defaults.put(ID_ENTRY_GENERATOR, DoiFetcher.NAME); - defaults.put(USE_CUSTOM_DOI_URI, Boolean.FALSE); defaults.put(BASE_DOI_URI, "https://doi.org"); @@ -607,7 +583,6 @@ protected JabRefCliPreferences() { defaults.put(PUSH_TO_APPLICATION, "TeXstudio"); - defaults.put(RECENT_DATABASES, ""); defaults.put(EXTERNAL_FILE_TYPES, ""); defaults.put(KEY_PATTERN_REGEX, ""); defaults.put(KEY_PATTERN_REPLACEMENT, ""); @@ -677,9 +652,7 @@ protected JabRefCliPreferences() { defaults.put(IMPORT_WORKING_DIRECTORY, USER_HOME); defaults.put(PREFS_EXPORT_PATH, USER_HOME); defaults.put(AUTO_OPEN_FORM, Boolean.TRUE); - defaults.put(OPEN_LAST_EDITED, Boolean.TRUE); defaults.put(LAST_EDITED, ""); - defaults.put(LAST_FOCUSED, ""); defaults.put(DEFAULT_SHOW_SOURCE, Boolean.FALSE); defaults.put(SHOW_USER_COMMENTS_FIELDS, Boolean.TRUE); @@ -704,7 +677,6 @@ protected JabRefCliPreferences() { defaults.put(DEFAULT_ENCODING, StandardCharsets.UTF_8.name()); defaults.put(DEFAULT_OWNER, System.getProperty("user.name")); defaults.put(MEMORY_STICK_MODE, Boolean.FALSE); - defaults.put(SHOW_ADVANCED_HINTS, Boolean.TRUE); defaults.put(EXTRA_FILE_COLUMNS, Boolean.FALSE); @@ -743,7 +715,6 @@ protected JabRefCliPreferences() { defaults.put(OVERWRITE_OWNER, Boolean.FALSE); defaults.put(AVOID_OVERWRITING_KEY, Boolean.FALSE); defaults.put(WARN_BEFORE_OVERWRITING_KEY, Boolean.TRUE); - defaults.put(CONFIRM_DELETE, Boolean.TRUE); defaults.put(CONFIRM_LINKED_FILE_DELETE, Boolean.TRUE); defaults.put(DEFAULT_CITATION_KEY_PATTERN, "[auth][year]"); defaults.put(UNWANTED_CITATION_KEY_CHARACTERS, "-`สน:!;?^"); @@ -770,9 +741,6 @@ protected JabRefCliPreferences() { defaults.put(LAST_USED_EXPORT, ""); defaults.put(SIDE_PANE_WIDTH, 0.15); - defaults.put(MAIN_FONT_SIZE, 9); - defaults.put(OVERRIDE_DEFAULT_FONT_SIZE, false); - defaults.put(AUTOLINK_EXACT_KEY_ONLY, Boolean.FALSE); defaults.put(AUTOLINK_FILES_ENABLED, Boolean.TRUE); defaults.put(LOCAL_AUTO_SAVE, Boolean.FALSE); @@ -852,10 +820,6 @@ protected JabRefCliPreferences() { "\\begin{comment}

Comment: \\format[Markdown,HTMLChars(keepCurlyBraces)]{\\comment}\\end{comment}__NEWLINE__" + "__NEWLINE__"); - // set default theme - defaults.put(THEME, Theme.BASE_CSS); - defaults.put(THEME_SYNC_OS, Boolean.FALSE); - setLanguageDependentDefaultValues(); // region:AI @@ -1005,7 +969,7 @@ public void putDouble(String key, double value) { prefs.putDouble(key, value); } - private void remove(String key) { + protected void remove(String key) { prefs.remove(key); } @@ -2019,51 +1983,7 @@ private String getUserAndHost() { return userAndHost; } - //************************************************************************************************************* - // WorkspacePreferences - //************************************************************************************************************* - - @Override - public WorkspacePreferences getWorkspacePreferences() { - if (workspacePreferences != null) { - return workspacePreferences; - } - - workspacePreferences = new WorkspacePreferences( - getLanguage(), - getBoolean(OVERRIDE_DEFAULT_FONT_SIZE), - getInt(MAIN_FONT_SIZE), - (Integer) defaults.get(MAIN_FONT_SIZE), - new Theme(get(THEME)), - getBoolean(THEME_SYNC_OS), - getBoolean(OPEN_LAST_EDITED), - getBoolean(SHOW_ADVANCED_HINTS), - getBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION), - getBoolean(CONFIRM_DELETE), - getStringList(SELECTED_SLR_CATALOGS)); - - EasyBind.listen(workspacePreferences.languageProperty(), (obs, oldValue, newValue) -> { - put(LANGUAGE, newValue.getId()); - if (oldValue != newValue) { - setLanguageDependentDefaultValues(); - Localization.setLanguage(newValue); - } - }); - - EasyBind.listen(workspacePreferences.shouldOverrideDefaultFontSizeProperty(), (obs, oldValue, newValue) -> putBoolean(OVERRIDE_DEFAULT_FONT_SIZE, newValue)); - EasyBind.listen(workspacePreferences.mainFontSizeProperty(), (obs, oldValue, newValue) -> putInt(MAIN_FONT_SIZE, newValue)); - EasyBind.listen(workspacePreferences.themeProperty(), (obs, oldValue, newValue) -> put(THEME, newValue.getName())); - EasyBind.listen(workspacePreferences.themeSyncOsProperty(), (obs, oldValue, newValue) -> putBoolean(THEME_SYNC_OS, newValue)); - EasyBind.listen(workspacePreferences.openLastEditedProperty(), (obs, oldValue, newValue) -> putBoolean(OPEN_LAST_EDITED, newValue)); - EasyBind.listen(workspacePreferences.showAdvancedHintsProperty(), (obs, oldValue, newValue) -> putBoolean(SHOW_ADVANCED_HINTS, newValue)); - EasyBind.listen(workspacePreferences.warnAboutDuplicatesInInspectionProperty(), (obs, oldValue, newValue) -> putBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION, newValue)); - EasyBind.listen(workspacePreferences.confirmDeleteProperty(), (obs, oldValue, newValue) -> putBoolean(CONFIRM_DELETE, newValue)); - workspacePreferences.getSelectedSlrCatalogs().addListener((ListChangeListener) change -> - putStringList(SELECTED_SLR_CATALOGS, workspacePreferences.getSelectedSlrCatalogs())); - return workspacePreferences; - } - - private Language getLanguage() { + protected Language getLanguage() { return Stream.of(Language.values()) .filter(language -> language.getId().equalsIgnoreCase(get(LANGUAGE))) .findFirst() @@ -2526,73 +2446,6 @@ private static EnumSet getDefaultCleanupJobs() { return activeJobs; } - //************************************************************************************************************* - // GUI preferences - //************************************************************************************************************* - - @Override - public CoreGuiPreferences getGuiPreferences() { - if (coreGuiPreferences != null) { - return coreGuiPreferences; - } - - coreGuiPreferences = new CoreGuiPreferences( - getDouble(MAIN_WINDOW_POS_X), - getDouble(MAIN_WINDOW_POS_Y), - getDouble(MAIN_WINDOW_WIDTH), - getDouble(MAIN_WINDOW_HEIGHT), - getBoolean(WINDOW_MAXIMISED), - getStringList(LAST_EDITED).stream() - .map(Path::of) - .collect(Collectors.toList()), - Path.of(get(LAST_FOCUSED)), - getFileHistory(), - get(ID_ENTRY_GENERATOR), - getDouble(SIDE_PANE_WIDTH)); - - EasyBind.listen(coreGuiPreferences.positionXProperty(), (obs, oldValue, newValue) -> putDouble(MAIN_WINDOW_POS_X, newValue.doubleValue())); - EasyBind.listen(coreGuiPreferences.positionYProperty(), (obs, oldValue, newValue) -> putDouble(MAIN_WINDOW_POS_Y, newValue.doubleValue())); - EasyBind.listen(coreGuiPreferences.sizeXProperty(), (obs, oldValue, newValue) -> putDouble(MAIN_WINDOW_WIDTH, newValue.doubleValue())); - EasyBind.listen(coreGuiPreferences.sizeYProperty(), (obs, oldValue, newValue) -> putDouble(MAIN_WINDOW_HEIGHT, newValue.doubleValue())); - EasyBind.listen(coreGuiPreferences.windowMaximisedProperty(), (obs, oldValue, newValue) -> putBoolean(WINDOW_MAXIMISED, newValue)); - EasyBind.listen(coreGuiPreferences.sidePaneWidthProperty(), (obs, oldValue, newValue) -> putDouble(SIDE_PANE_WIDTH, newValue.doubleValue())); - - coreGuiPreferences.getLastFilesOpened().addListener((ListChangeListener) change -> { - if (change.getList().isEmpty()) { - prefs.remove(LAST_EDITED); - } else { - putStringList(LAST_EDITED, coreGuiPreferences.getLastFilesOpened().stream() - .map(Path::toAbsolutePath) - .map(Path::toString) - .collect(Collectors.toList())); - } - }); - EasyBind.listen(coreGuiPreferences.lastFocusedFileProperty(), (obs, oldValue, newValue) -> { - if (newValue != null) { - put(LAST_FOCUSED, newValue.toAbsolutePath().toString()); - } else { - remove(LAST_FOCUSED); - } - }); - coreGuiPreferences.getFileHistory().addListener((InvalidationListener) change -> storeFileHistory(coreGuiPreferences.getFileHistory())); - EasyBind.listen(coreGuiPreferences.lastSelectedIdBasedFetcherProperty(), (obs, oldValue, newValue) -> put(ID_ENTRY_GENERATOR, newValue)); - - return coreGuiPreferences; - } - - private FileHistory getFileHistory() { - return FileHistory.of(getStringList(RECENT_DATABASES).stream() - .map(Path::of) - .toList()); - } - - private void storeFileHistory(FileHistory history) { - putStringList(RECENT_DATABASES, history.stream() - .map(Path::toAbsolutePath) - .map(Path::toString) - .toList()); - } - @Override public UnlinkedFilesDialogPreferences getUnlinkedFilesDialogPreferences() { if (unlinkedFilesDialogPreferences != null) { diff --git a/src/main/java/org/jabref/migrations/PreferencesMigrations.java b/src/main/java/org/jabref/migrations/PreferencesMigrations.java index a9423c543c5..ffd62da8aa6 100644 --- a/src/main/java/org/jabref/migrations/PreferencesMigrations.java +++ b/src/main/java/org/jabref/migrations/PreferencesMigrations.java @@ -463,9 +463,9 @@ static void restoreVariablesForBackwardCompatibility(JabRefCliPreferences prefer try { // some versions stored the font size as double to the **same** key // since the preference store is type-safe, we need to add this workaround - String fontSizeAsString = preferences.get(JabRefCliPreferences.MAIN_FONT_SIZE); + String fontSizeAsString = preferences.get(JabRefGuiPreferences.MAIN_FONT_SIZE); int fontSizeAsInt = (int) Math.round(Double.parseDouble(fontSizeAsString)); - preferences.putInt(JabRefCliPreferences.MAIN_FONT_SIZE, fontSizeAsInt); + preferences.putInt(JabRefGuiPreferences.MAIN_FONT_SIZE, fontSizeAsInt); } catch (ClassCastException e) { // already an integer } diff --git a/src/test/java/org/jabref/gui/exporter/SaveDatabaseActionTest.java b/src/test/java/org/jabref/gui/exporter/SaveDatabaseActionTest.java index bd2b5c370dc..bbc91aa2501 100644 --- a/src/test/java/org/jabref/gui/exporter/SaveDatabaseActionTest.java +++ b/src/test/java/org/jabref/gui/exporter/SaveDatabaseActionTest.java @@ -8,10 +8,12 @@ import java.util.Optional; import java.util.stream.Collectors; +import javafx.beans.property.SimpleBooleanProperty; import javafx.collections.FXCollections; import org.jabref.gui.DialogService; import org.jabref.gui.LibraryTab; +import org.jabref.gui.preferences.GuiPreferences; import org.jabref.gui.undo.CountingUndoManager; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.logic.FilePreferences; @@ -22,7 +24,6 @@ import org.jabref.logic.exporter.BibDatabaseWriter; import org.jabref.logic.exporter.ExportPreferences; import org.jabref.logic.exporter.SaveConfiguration; -import org.jabref.logic.preferences.JabRefCliPreferences; import org.jabref.logic.shared.DatabaseLocation; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; @@ -51,7 +52,7 @@ class SaveDatabaseActionTest { private Path file = Path.of(TEST_BIBTEX_LIBRARY_LOCATION); private final DialogService dialogService = mock(DialogService.class); private final FilePreferences filePreferences = mock(FilePreferences.class); - private final JabRefCliPreferences preferences = mock(JabRefCliPreferences.class); + private final GuiPreferences preferences = mock(GuiPreferences.class); private LibraryTab libraryTab = mock(LibraryTab.class); private BibDatabaseContext dbContext = spy(BibDatabaseContext.class); private SaveDatabaseAction saveDatabaseAction; @@ -89,7 +90,10 @@ void saveAsShouldNotSetWorkingDirectoryIfNotSelected() { void saveShouldShowSaveAsIfDatabaseNotSelected() { when(dbContext.getDatabasePath()).thenReturn(Optional.empty()); when(dbContext.getLocation()).thenReturn(DatabaseLocation.LOCAL); - when(preferences.getBoolean(JabRefCliPreferences.LOCAL_AUTO_SAVE)).thenReturn(false); + when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(file)); + LibraryPreferences libraryPreferences = mock(LibraryPreferences.class); + when(preferences.getLibraryPreferences()).thenReturn(libraryPreferences); + when(libraryPreferences.autoSaveProperty()).thenReturn(new SimpleBooleanProperty(false)); when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(file)); doReturn(true).when(saveDatabaseAction).saveAs(any(), any()); @@ -117,7 +121,9 @@ private SaveDatabaseAction createSaveDatabaseActionForBibDatabase(BibDatabase da when(dbContext.getDatabase()).thenReturn(database); when(dbContext.getMetaData()).thenReturn(metaData); when(dbContext.getEntries()).thenReturn(database.getEntries()); - when(preferences.getBoolean(JabRefCliPreferences.LOCAL_AUTO_SAVE)).thenReturn(false); + LibraryPreferences libraryPreferences = mock(LibraryPreferences.class); + when(preferences.getLibraryPreferences()).thenReturn(libraryPreferences); + when(libraryPreferences.autoSaveProperty()).thenReturn(new SimpleBooleanProperty(false)); when(preferences.getFieldPreferences()).thenReturn(fieldPreferences); when(preferences.getCitationKeyPatternPreferences()).thenReturn(mock(CitationKeyPatternPreferences.class)); when(preferences.getCitationKeyPatternPreferences().getKeyPatterns()).thenReturn(emptyGlobalCitationKeyPatterns); diff --git a/src/test/java/org/jabref/http/server/ServerTest.java b/src/test/java/org/jabref/http/server/ServerTest.java index 1589bc70988..c8d91b3e39e 100644 --- a/src/test/java/org/jabref/http/server/ServerTest.java +++ b/src/test/java/org/jabref/http/server/ServerTest.java @@ -90,9 +90,11 @@ private static void initializePreferencesService() { // used twice, once for reading and once for writing when(importFormatPreferences.fieldPreferences()).thenReturn(fieldContentFormatterPreferences); +/* coreGuiPreferences = mock(CoreGuiPreferences.class); when(preferences.getGuiPreferences()).thenReturn(coreGuiPreferences); when(coreGuiPreferences.getLastFilesOpened()).thenReturn(FXCollections.observableArrayList(TestBibFile.GENERAL_SERVER_TEST.path)); +*/ } } diff --git a/src/test/java/org/jabref/migrations/GuiPreferencesMigrationsTest.java b/src/test/java/org/jabref/migrations/GuiPreferencesMigrationsTest.java index b423201ad36..762c8ad799e 100644 --- a/src/test/java/org/jabref/migrations/GuiPreferencesMigrationsTest.java +++ b/src/test/java/org/jabref/migrations/GuiPreferencesMigrationsTest.java @@ -4,6 +4,7 @@ import java.util.Collections; import java.util.List; +import org.jabref.gui.preferences.JabRefGuiPreferences; import org.jabref.logic.preferences.CliPreferences; import org.jabref.logic.preferences.JabRefCliPreferences; @@ -185,7 +186,7 @@ void restoreColumnVariablesForBackwardCompatibility() { when(prefs.getStringList("columnNames")).thenReturn(updatedNames); - when(prefs.get(JabRefCliPreferences.MAIN_FONT_SIZE)).thenReturn("11.2"); + when(prefs.get(JabRefGuiPreferences.MAIN_FONT_SIZE)).thenReturn("11.2"); PreferencesMigrations.restoreVariablesForBackwardCompatibility(prefs); @@ -194,7 +195,7 @@ void restoreColumnVariablesForBackwardCompatibility() { verify(prefs).put("columnSortTypes", ""); verify(prefs).put("columnSortOrder", ""); - verify(prefs).putInt(JabRefCliPreferences.MAIN_FONT_SIZE, 11); + verify(prefs).putInt(JabRefGuiPreferences.MAIN_FONT_SIZE, 11); } @Test diff --git a/src/test/java/org/jabref/testutils/interactive/styletester/StyleTesterMain.java b/src/test/java/org/jabref/testutils/interactive/styletester/StyleTesterMain.java index 2f5c341af8e..c026d68fe99 100644 --- a/src/test/java/org/jabref/testutils/interactive/styletester/StyleTesterMain.java +++ b/src/test/java/org/jabref/testutils/interactive/styletester/StyleTesterMain.java @@ -4,10 +4,10 @@ import javafx.scene.Scene; import javafx.stage.Stage; +import org.jabref.gui.preferences.JabRefGuiPreferences; import org.jabref.gui.theme.ThemeManager; import org.jabref.gui.util.DefaultFileUpdateMonitor; import org.jabref.logic.JabRefException; -import org.jabref.logic.preferences.JabRefCliPreferences; import org.jabref.logic.util.HeadlessExecutorService; /** @@ -25,7 +25,7 @@ public void start(Stage stage) throws JabRefException { DefaultFileUpdateMonitor fileUpdateMonitor = new DefaultFileUpdateMonitor(); HeadlessExecutorService.INSTANCE.executeInterruptableTask(fileUpdateMonitor, "FileUpdateMonitor"); ThemeManager themeManager = new ThemeManager( - JabRefCliPreferences.getInstance().getWorkspacePreferences(), + JabRefGuiPreferences.getInstance().getWorkspacePreferences(), fileUpdateMonitor, Runnable::run);