diff --git a/jabgui/src/main/java/org/jabref/gui/WorkspacePreferences.java b/jabgui/src/main/java/org/jabref/gui/WorkspacePreferences.java index 60af19990b0..cf313a6b668 100644 --- a/jabgui/src/main/java/org/jabref/gui/WorkspacePreferences.java +++ b/jabgui/src/main/java/org/jabref/gui/WorkspacePreferences.java @@ -1,6 +1,7 @@ package org.jabref.gui; import java.util.List; +import java.util.Locale; import javafx.beans.property.BooleanProperty; import javafx.beans.property.IntegerProperty; @@ -23,7 +24,6 @@ public class WorkspacePreferences { private final BooleanProperty themeSyncOs; private final BooleanProperty shouldOpenLastEdited; private final BooleanProperty showAdvancedHints; - private final BooleanProperty warnAboutDuplicatesInInspection; private final BooleanProperty confirmDelete; private final BooleanProperty confirmHideTabBar; private final ObservableList selectedSlrCatalogs; @@ -36,7 +36,6 @@ public WorkspacePreferences(Language language, boolean themeSyncOs, boolean shouldOpenLastEdited, boolean showAdvancedHints, - boolean warnAboutDuplicatesInInspection, boolean confirmDelete, boolean confirmHideTabBar, List selectedSlrCatalogs) { @@ -48,12 +47,46 @@ public WorkspacePreferences(Language language, this.themeSyncOs = new SimpleBooleanProperty(themeSyncOs); this.shouldOpenLastEdited = new SimpleBooleanProperty(shouldOpenLastEdited); this.showAdvancedHints = new SimpleBooleanProperty(showAdvancedHints); - this.warnAboutDuplicatesInInspection = new SimpleBooleanProperty(warnAboutDuplicatesInInspection); this.confirmDelete = new SimpleBooleanProperty(confirmDelete); this.confirmHideTabBar = new SimpleBooleanProperty(confirmHideTabBar); this.selectedSlrCatalogs = FXCollections.observableArrayList(selectedSlrCatalogs); } + /// Creates Object with default values + private WorkspacePreferences() { + this( + Language.getLanguageFor(Locale.getDefault().getLanguage()), // Default language + false, // Default font size override + 9, // Default font size + 9, // FixMe: main default and default default is weird + new Theme(Theme.BASE_CSS), // Default theme + false, // Default theme sync with OS + true, // Default open last edited + true, // Default show advanced hints + true, // Default confirm delete + true, // Default confirm hide tab bar + List.of() // Default selected SLR catalogs + ); + } + + public static WorkspacePreferences getDefault() { + return new WorkspacePreferences(); + } + + public void setAll(WorkspacePreferences preferences) { + this.language.set(preferences.getLanguage()); + this.shouldOverrideDefaultFontSize.set(preferences.shouldOverrideDefaultFontSize()); + this.mainFontSize.set(preferences.getMainFontSize()); + this.defaultFontSize.set(preferences.getDefaultFontSize()); + this.theme.set(preferences.getTheme()); + this.themeSyncOs.set(preferences.shouldThemeSyncOs()); + this.shouldOpenLastEdited.set(preferences.shouldOpenLastEdited()); + this.showAdvancedHints.set(preferences.shouldShowAdvancedHints()); + this.confirmDelete.set(preferences.shouldConfirmDelete()); + this.confirmHideTabBar.set(preferences.shouldHideTabBar()); + this.selectedSlrCatalogs.setAll(preferences.getSelectedSlrCatalogs()); + } + public Language getLanguage() { return language.get(); } @@ -142,18 +175,6 @@ public void setShowAdvancedHints(boolean showAdvancedHints) { this.showAdvancedHints.set(showAdvancedHints); } - public boolean shouldWarnAboutDuplicatesInInspection() { - return warnAboutDuplicatesInInspection.get(); - } - - public BooleanProperty warnAboutDuplicatesInInspectionProperty() { - return warnAboutDuplicatesInInspection; - } - - public void setWarnAboutDuplicatesInInspection(boolean warnAboutDuplicatesInInspection) { - this.warnAboutDuplicatesInInspection.set(warnAboutDuplicatesInInspection); - } - public boolean shouldConfirmDelete() { return confirmDelete.get(); } diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java b/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java index f4db8364a69..6a130d488f2 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java @@ -10,6 +10,7 @@ import java.util.Objects; import java.util.SequencedMap; import java.util.Set; +import java.util.prefs.BackingStoreException; import java.util.stream.Collectors; import javafx.beans.InvalidationListener; @@ -45,6 +46,7 @@ import org.jabref.gui.sidepane.SidePaneType; import org.jabref.gui.specialfields.SpecialFieldsPreferences; import org.jabref.gui.theme.Theme; +import org.jabref.logic.JabRefException; import org.jabref.logic.bst.BstPreviewLayout; import org.jabref.logic.citationstyle.CSLStyleLoader; import org.jabref.logic.citationstyle.CSLStyleUtils; @@ -83,7 +85,6 @@ public class JabRefGuiPreferences extends JabRefCliPreferences implements GuiPre // Public because needed for pref migration public static final String AUTOCOMPLETER_COMPLETE_FIELDS = "autoCompleteFields"; - public static final String MAIN_FONT_SIZE = "mainFontSize"; // region Preview - public for pref migrations public static final String PREVIEW_STYLE = "previewStyle"; @@ -111,6 +112,18 @@ public class JabRefGuiPreferences extends JabRefCliPreferences implements GuiPre private static final Logger LOGGER = LoggerFactory.getLogger(JabRefGuiPreferences.class); + // region WorkspacePreferences + private static final String OVERRIDE_DEFAULT_FONT_SIZE = "overrideDefaultFontSize"; + private static final String MAIN_FONT_SIZE = "mainFontSize"; + 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 SHOW_ADVANCED_HINTS = "showAdvancedHints"; + private static final String CONFIRM_DELETE = "confirmDelete"; + private static final String CONFIRM_HIDE_TAB_BAR = "confirmHideTabBar"; + private static final String SELECTED_SLR_CATALOGS = "selectedSlrCatalogs"; + // endregion + // region core GUI preferences private static final String MAIN_WINDOW_POS_X = "mainWindowPosX"; private static final String MAIN_WINDOW_POS_Y = "mainWindowPosY"; @@ -150,16 +163,6 @@ public class JabRefGuiPreferences extends JabRefCliPreferences implements GuiPre private static final String FILE_BROWSER_COMMAND = "fileBrowserCommand"; // endregion - // 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"; - private static final String CONFIRM_HIDE_TAB_BAR = "confirmHideTabBar"; - // endregion - private static final String ENTRY_EDITOR_HEIGHT = "entryEditorHeightFX"; /** @@ -196,7 +199,6 @@ public class JabRefGuiPreferences extends JabRefCliPreferences implements GuiPre private static final String SPECIALFIELDSENABLED = "specialFieldsEnabled"; // endregion - private static final String SELECTED_SLR_CATALOGS = "selectedSlrCatalogs"; private static final String UNLINKED_FILES_SELECTED_EXTENSION = "unlinkedFilesSelectedExtension"; private static final String UNLINKED_FILES_SELECTED_DATE_RANGE = "unlinkedFilesSelectedDateRange"; private static final String UNLINKED_FILES_SELECTED_SORT = "unlinkedFilesSelectedSort"; @@ -269,17 +271,6 @@ private JabRefGuiPreferences() { defaults.put(AUTOCOMPLETER_COMPLETE_FIELDS, "author;editor;title;journal;publisher;keywords;crossref;related;entryset"); // 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(CONFIRM_HIDE_TAB_BAR, Boolean.TRUE); - defaults.put(SHOW_ADVANCED_HINTS, Boolean.TRUE); - // endregion - // region unlinkedFilesDialogPreferences defaults.put(UNLINKED_FILES_SELECTED_EXTENSION, StandardFileType.ANY_FILE.getName()); defaults.put(UNLINKED_FILES_SELECTED_DATE_RANGE, DateRange.ALL_TIME.name()); @@ -429,6 +420,21 @@ public CopyToPreferences getCopyToPreferences() { return copyToPreferences; } + @Override + public void clear() throws BackingStoreException { + super.clear(); + + getWorkspacePreferences().setAll(WorkspacePreferences.getDefault()); + } + + @Override + public void importPreferences(Path file) throws JabRefException { + super.importPreferences(file); + + // in case of incomplete or corrupt xml fall back to current preferences + getWorkspacePreferences().setAll(getWorkspacePreferencesFromLowLevelApi(getWorkspacePreferences())); + } + // region EntryEditorPreferences public EntryEditorPreferences getEntryEditorPreferences() { if (entryEditorPreferences != null) { @@ -641,21 +647,9 @@ public WorkspacePreferences getWorkspacePreferences() { 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), - getBoolean(CONFIRM_HIDE_TAB_BAR), - getStringList(SELECTED_SLR_CATALOGS)); + workspacePreferences = getWorkspacePreferencesFromLowLevelApi(WorkspacePreferences.getDefault()); - EasyBind.listen(workspacePreferences.languageProperty(), (obs, oldValue, newValue) -> { + EasyBind.listen(workspacePreferences.languageProperty(), (_, oldValue, newValue) -> { put(LANGUAGE, newValue.getId()); if (oldValue != newValue) { setLanguageDependentDefaultValues(); @@ -663,20 +657,42 @@ public WorkspacePreferences getWorkspacePreferences() { } }); - 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)); - EasyBind.listen(workspacePreferences.hideTabBarProperty(), (obs, oldValue, newValue) -> putBoolean(CONFIRM_HIDE_TAB_BAR, newValue)); - workspacePreferences.getSelectedSlrCatalogs().addListener((ListChangeListener) change -> + EasyBind.listen(workspacePreferences.shouldOverrideDefaultFontSizeProperty(), (_, _, newValue) -> + putBoolean(OVERRIDE_DEFAULT_FONT_SIZE, newValue)); + EasyBind.listen(workspacePreferences.mainFontSizeProperty(), (_, _, newValue) -> + putInt(MAIN_FONT_SIZE, newValue)); + EasyBind.listen(workspacePreferences.themeProperty(), (_, _, newValue) -> + put(THEME, newValue.getName())); + EasyBind.listen(workspacePreferences.themeSyncOsProperty(), (_, _, newValue) -> + putBoolean(THEME_SYNC_OS, newValue)); + EasyBind.listen(workspacePreferences.openLastEditedProperty(), (_, _, newValue) -> + putBoolean(OPEN_LAST_EDITED, newValue)); + EasyBind.listen(workspacePreferences.showAdvancedHintsProperty(), (_, _, newValue) -> + putBoolean(SHOW_ADVANCED_HINTS, newValue)); + EasyBind.listen(workspacePreferences.confirmDeleteProperty(), (_, _, newValue) -> + putBoolean(CONFIRM_DELETE, newValue)); + EasyBind.listen(workspacePreferences.hideTabBarProperty(), (_, _, newValue) -> + putBoolean(CONFIRM_HIDE_TAB_BAR, newValue)); + workspacePreferences.getSelectedSlrCatalogs().addListener((ListChangeListener) _ -> putStringList(SELECTED_SLR_CATALOGS, workspacePreferences.getSelectedSlrCatalogs())); return workspacePreferences; } + private WorkspacePreferences getWorkspacePreferencesFromLowLevelApi(WorkspacePreferences defaults) { + return new WorkspacePreferences( + getLanguage(), + getBoolean(OVERRIDE_DEFAULT_FONT_SIZE, defaults.shouldOverrideDefaultFontSize()), + getInt(MAIN_FONT_SIZE, defaults.getMainFontSize()), + defaults.getDefaultFontSize(), // FixMe + new Theme(get(THEME, Theme.BASE_CSS)), + getBoolean(THEME_SYNC_OS, defaults.shouldThemeSyncOs()), + getBoolean(OPEN_LAST_EDITED, defaults.shouldOpenLastEdited()), + getBoolean(SHOW_ADVANCED_HINTS, defaults.shouldShowAdvancedHints()), + getBoolean(CONFIRM_DELETE, defaults.shouldConfirmDelete()), + getBoolean(CONFIRM_HIDE_TAB_BAR, defaults.shouldHideTabBar()), + getStringList(SELECTED_SLR_CATALOGS)); + } + @Override public UnlinkedFilesDialogPreferences getUnlinkedFilesDialogPreferences() { if (unlinkedFilesDialogPreferences != null) { diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java b/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java index f7a6950218c..220378e8979 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java @@ -39,6 +39,7 @@ public class PreferencesDialogView extends BaseDialog preferenceTabList; @FXML private ScrollPane preferencesContainer; @FXML private ButtonType saveButton; + @FXML private ButtonType cancelButton; @FXML private ToggleButton memoryStickMode; @Inject private DialogService dialogService; @@ -55,7 +56,7 @@ public PreferencesDialogView(Class preferencesTabToSel .load() .setAsDialogPane(this); - ControlHelper.setAction(saveButton, getDialogPane(), event -> savePreferencesAndCloseDialog()); + ControlHelper.setAction(saveButton, getDialogPane(), _ -> savePreferencesAndCloseDialog()); // Stop the default button from firing when the user hits enter within the search box searchBox.setOnKeyPressed(event -> { @@ -149,7 +150,11 @@ void exportPreferences() { @FXML void importPreferences() { - viewModel.importPreferences(); + if (viewModel.importPreferences()) { + // Hint the user that preferences are already loaded into the UI + // ToDo: Import into the ui directly and save changes on click on Save button + this.getDialogPane().lookupButton(cancelButton).setDisable(true); + } } @FXML @@ -159,6 +164,10 @@ void showAllPreferences() { @FXML void resetPreferences() { - viewModel.resetPreferences(); + if (viewModel.resetPreferences()) { + // Hint the user that preferences are already loaded into the UI + // ToDo: Reset the ui and save changes on click on Save button + this.getDialogPane().lookupButton(cancelButton).setDisable(true); + } } } diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java b/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java index 5836422f225..87d344f8571 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java @@ -1,7 +1,9 @@ package org.jabref.gui.preferences; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.prefs.BackingStoreException; import javafx.beans.property.BooleanProperty; @@ -93,25 +95,26 @@ public ObservableList getPreferenceTabs() { return new ReadOnlyListWrapper<>(preferenceTabs); } - public void importPreferences() { + public boolean importPreferences() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(StandardFileType.XML) .withDefaultExtension(StandardFileType.XML) .withInitialDirectory(preferences.getInternalPreferences().getLastPreferencesExportPath()).build(); - dialogService.showFileOpenDialog(fileDialogConfiguration) - .ifPresent(file -> { - try { - preferences.importPreferences(file); - setValues(); + Optional importFileOpt = dialogService.showFileOpenDialog(fileDialogConfiguration); + if (importFileOpt.isPresent()) { + try { + preferences.importPreferences(importFileOpt.get()); + setValues(); - dialogService.showWarningDialogAndWait(Localization.lang("Import preferences"), - Localization.lang("You must restart JabRef for this to come into effect.")); - } catch (JabRefException ex) { - LOGGER.error("Error while importing preferences", ex); - dialogService.showErrorDialogAndWait(Localization.lang("Import preferences"), ex); - } - }); + return true; + } catch (JabRefException ex) { + LOGGER.error("Error while importing preferences", ex); + dialogService.showErrorDialogAndWait(Localization.lang("Import preferences"), ex); + } + } + + return false; } public void exportPreferences() { @@ -138,7 +141,8 @@ public void showPreferences() { dialogService.showCustomDialogAndWait(new PreferencesFilterDialog(new PreferencesFilter(preferences))); } - public void resetPreferences() { + /// returns true if the preferences have been reset + public boolean resetPreferences() { boolean resetPreferencesConfirmed = dialogService.showConfirmationDialogAndWait( Localization.lang("Reset preferences"), Localization.lang("Are you sure you want to reset all settings to default values?"), @@ -147,14 +151,16 @@ public void resetPreferences() { if (resetPreferencesConfirmed) { try { preferences.clear(); - dialogService.showWarningDialogAndWait(Localization.lang("Reset preferences"), - Localization.lang("You must restart JabRef for this to come into effect.")); + setValues(); + + return true; } catch (BackingStoreException ex) { LOGGER.error("Error while resetting preferences", ex); dialogService.showErrorDialogAndWait(Localization.lang("Reset preferences"), ex); } - setValues(); } + + return false; } /** diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java b/jabgui/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java index 2ec82e3c46d..bb820980b8e 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java @@ -13,20 +13,23 @@ import javafx.scene.control.TextFormatter; import javafx.util.converter.IntegerStringConverter; +import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.StandardActions; +import org.jabref.gui.frame.UiMessageHandler; import org.jabref.gui.help.HelpAction; import org.jabref.gui.preferences.AbstractPreferenceTabView; import org.jabref.gui.preferences.PreferencesTab; import org.jabref.gui.theme.ThemeTypes; import org.jabref.gui.util.IconValidationDecorator; import org.jabref.gui.util.ViewModelListCellFactory; +import org.jabref.http.manager.HttpServerManager; +import org.jabref.languageserver.controller.LanguageServerController; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Language; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.remote.server.RemoteListenerServerManager; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.entry.BibEntryTypesManager; -import org.jabref.model.util.FileUpdateMonitor; import com.airhacks.afterburner.views.ViewLoader; import com.tobiasdiez.easybind.EasyBind; @@ -36,6 +39,12 @@ public class GeneralTab extends AbstractPreferenceTabView implements PreferencesTab { + @Inject private HttpServerManager httpServerManager; + @Inject private LanguageServerController languageServerController; + @Inject private UiMessageHandler uiMessageHandler; + @Inject private RemoteListenerServerManager remoteListenerServerManager; + @Inject private StateManager stateManager; + @FXML private SearchableComboBox language; @FXML private ComboBox theme; @FXML private CheckBox themeSyncOs; @@ -45,7 +54,6 @@ public class GeneralTab extends AbstractPreferenceTabView i @FXML private Spinner fontSize; @FXML private CheckBox openLastStartup; @FXML private CheckBox showAdvancedHints; - @FXML private CheckBox inspectionWarningDuplicate; @FXML private CheckBox confirmDelete; @FXML private CheckBox shouldAskForIncludingCrossReferences; @@ -64,8 +72,6 @@ public class GeneralTab extends AbstractPreferenceTabView i @FXML private CheckBox enableLanguageServer; @FXML private TextField languageServerPort; @FXML private Button remoteHelp; - @Inject private FileUpdateMonitor fileUpdateMonitor; - @Inject private BibEntryTypesManager entryTypesManager; private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer(); @@ -91,7 +97,14 @@ public String getTabName() { } public void initialize() { - this.viewModel = new GeneralTabViewModel(dialogService, preferences, fileUpdateMonitor); + this.viewModel = new GeneralTabViewModel( + dialogService, + preferences, + httpServerManager, + languageServerController, + uiMessageHandler, + remoteListenerServerManager, + stateManager); new ViewModelListCellFactory() .withText(Language::getDisplayName) @@ -125,7 +138,6 @@ public void initialize() { openLastStartup.selectedProperty().bindBidirectional(viewModel.openLastStartupProperty()); showAdvancedHints.selectedProperty().bindBidirectional(viewModel.showAdvancedHintsProperty()); - inspectionWarningDuplicate.selectedProperty().bindBidirectional(viewModel.inspectionWarningDuplicateProperty()); confirmDelete.selectedProperty().bindBidirectional(viewModel.confirmDeleteProperty()); shouldAskForIncludingCrossReferences.selectedProperty().bindBidirectional(viewModel.shouldAskForIncludingCrossReferences()); confirmHideTabBar.selectedProperty().bindBidirectional(viewModel.confirmHideTabBarProperty()); diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java b/jabgui/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java index a4d1c1bfd8a..967e54aa9e7 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java @@ -45,24 +45,18 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.logic.util.strings.StringUtil; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.util.FileUpdateMonitor; -import com.airhacks.afterburner.injection.Injector; import de.saxsys.mvvmfx.utils.validation.CompositeValidator; import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; import de.saxsys.mvvmfx.utils.validation.ValidationMessage; import de.saxsys.mvvmfx.utils.validation.ValidationStatus; import de.saxsys.mvvmfx.utils.validation.Validator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class GeneralTabViewModel implements PreferenceTabViewModel { protected static SpinnerValueFactory fontSizeValueFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(9, Integer.MAX_VALUE); - private static final Logger LOGGER = LoggerFactory.getLogger(GeneralTabViewModel.class); - private final ReadOnlyListProperty languagesListProperty = new ReadOnlyListWrapper<>(FXCollections.observableArrayList(Language.getSorted())); private final ObjectProperty selectedLanguageProperty = new SimpleObjectProperty<>(); @@ -81,7 +75,6 @@ public class GeneralTabViewModel implements PreferenceTabViewModel { private final BooleanProperty openLastStartupProperty = new SimpleBooleanProperty(); private final BooleanProperty showAdvancedHintsProperty = new SimpleBooleanProperty(); - private final BooleanProperty inspectionWarningDuplicateProperty = new SimpleBooleanProperty(); private final BooleanProperty confirmDeleteProperty = new SimpleBooleanProperty(); private final BooleanProperty shouldAskForIncludingCrossReferencesProperty = new SimpleBooleanProperty(); private final BooleanProperty hideTabBarProperty = new SimpleBooleanProperty(); @@ -102,6 +95,11 @@ public class GeneralTabViewModel implements PreferenceTabViewModel { private final LibraryPreferences libraryPreferences; private final FilePreferences filePreferences; private final RemotePreferences remotePreferences; + private final HttpServerManager httpServerManager; + private final LanguageServerController languageServerController; + private final UiMessageHandler uiMessageHandler; + private final RemoteListenerServerManager remoteListenerServerManager; + private final StateManager stateManager; private final Validator fontSizeValidator; private final Validator customPathToThemeValidator; @@ -118,20 +116,28 @@ public class GeneralTabViewModel implements PreferenceTabViewModel { private final StringProperty languageServerPortProperty = new SimpleStringProperty(""); private final TrustStoreManager trustStoreManager; - private final FileUpdateMonitor fileUpdateMonitor; - - public GeneralTabViewModel(DialogService dialogService, GuiPreferences preferences, FileUpdateMonitor fileUpdateMonitor) { + public GeneralTabViewModel(DialogService dialogService, + GuiPreferences preferences, + HttpServerManager httpServerManager, + LanguageServerController languageServerController, + UiMessageHandler uiMessageHandler, + RemoteListenerServerManager remoteListenerServerManager, + StateManager stateManager) { this.dialogService = dialogService; this.preferences = preferences; this.workspacePreferences = preferences.getWorkspacePreferences(); this.libraryPreferences = preferences.getLibraryPreferences(); this.filePreferences = preferences.getFilePreferences(); this.remotePreferences = preferences.getRemotePreferences(); - this.fileUpdateMonitor = fileUpdateMonitor; + this.httpServerManager = httpServerManager; + this.languageServerController = languageServerController; + this.uiMessageHandler = uiMessageHandler; + this.remoteListenerServerManager = remoteListenerServerManager; + this.stateManager = stateManager; fontSizeValidator = new FunctionBasedValidator<>( fontSizeProperty, - input -> { + _ -> { try { return Integer.parseInt(fontSizeProperty().getValue()) > 8; } catch (NumberFormatException ex) { @@ -207,7 +213,6 @@ public void setValues() { openLastStartupProperty.setValue(workspacePreferences.shouldOpenLastEdited()); showAdvancedHintsProperty.setValue(workspacePreferences.shouldShowAdvancedHints()); - inspectionWarningDuplicateProperty.setValue(workspacePreferences.shouldWarnAboutDuplicatesInInspection()); confirmDeleteProperty.setValue(workspacePreferences.shouldConfirmDelete()); shouldAskForIncludingCrossReferencesProperty.setValue(preferences.getCopyToPreferences().getShouldAskForIncludingCrossReferences()); @@ -257,7 +262,6 @@ public void storeSettings() { workspacePreferences.setOpenLastEdited(openLastStartupProperty.getValue()); workspacePreferences.setShowAdvancedHints(showAdvancedHintsProperty.getValue()); - workspacePreferences.setWarnAboutDuplicatesInInspection(inspectionWarningDuplicateProperty.getValue()); workspacePreferences.setConfirmDelete(confirmDeleteProperty.getValue()); preferences.getCopyToPreferences().setShouldAskForIncludingCrossReferences(shouldAskForIncludingCrossReferencesProperty.getValue()); @@ -284,15 +288,12 @@ public void storeSettings() { } }); - UiMessageHandler uiMessageHandler = Injector.instantiateModelOrService(UiMessageHandler.class); CLIMessageHandler messageHandler = new CLIMessageHandler(uiMessageHandler, preferences); - RemoteListenerServerManager remoteListenerServerManager = Injector.instantiateModelOrService(RemoteListenerServerManager.class); // stop in all cases, because the port might have changed remoteListenerServerManager.stop(); if (remoteServerProperty.getValue()) { remotePreferences.setUseRemoteServer(true); - remoteListenerServerManager.openAndStart(messageHandler, - remotePreferences.getPort()); + remoteListenerServerManager.openAndStart(messageHandler, remotePreferences.getPort()); } else { remotePreferences.setUseRemoteServer(false); remoteListenerServerManager.stop(); @@ -310,19 +311,17 @@ public void storeSettings() { } }); - HttpServerManager httpServerManager = Injector.instantiateModelOrService(HttpServerManager.class); // stop in all cases, because the port might have changed httpServerManager.stop(); if (enableHttpServerProperty.getValue()) { remotePreferences.setEnableHttpServer(true); URI uri = remotePreferences.getHttpServerUri(); - httpServerManager.start(Injector.instantiateModelOrService(StateManager.class), uri); + httpServerManager.start(stateManager, uri); } else { remotePreferences.setEnableHttpServer(false); httpServerManager.stop(); } - LanguageServerController languageServerController = Injector.instantiateModelOrService(LanguageServerController.class); // stop in all cases, because the port might have changed (or other settings that can't be easily tracked https://github.com/JabRef/jabref/pull/13697#discussion_r2285997003) languageServerController.stop(); if (enableLanguageServerProperty.getValue()) { @@ -435,10 +434,6 @@ public BooleanProperty showAdvancedHintsProperty() { return this.showAdvancedHintsProperty; } - public BooleanProperty inspectionWarningDuplicateProperty() { - return this.inspectionWarningDuplicateProperty; - } - public BooleanProperty confirmDeleteProperty() { return this.confirmDeleteProperty; } diff --git a/jabgui/src/main/java/org/jabref/gui/theme/ThemeManager.java b/jabgui/src/main/java/org/jabref/gui/theme/ThemeManager.java index cd8cde0aefb..fe39a3d6d6b 100644 --- a/jabgui/src/main/java/org/jabref/gui/theme/ThemeManager.java +++ b/jabgui/src/main/java/org/jabref/gui/theme/ThemeManager.java @@ -3,13 +3,13 @@ import java.io.IOException; import java.net.URL; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.WeakHashMap; -import java.util.stream.Stream; import javafx.application.ColorScheme; import javafx.application.Platform; @@ -111,16 +111,15 @@ public ThemeManager(@NonNull WorkspacePreferences workspacePreferences, /// Using `installCss` directly would cause a delay in theme application, resulting /// in a brief flash of the default JavaFX theme (Modena CSS) before the intended theme appears. public void installCssImmediately(Scene scene) { - List stylesheets = scene.getStylesheets(); + List toAdd = new ArrayList<>(2); + toAdd.add(baseStyleSheet.getSceneStylesheet().toExternalForm()); + theme.getAdditionalStylesheet() + .map(StyleSheet::getSceneStylesheet) + .map(URL::toExternalForm) + .ifPresent(toAdd::add); + scene.getStylesheets().clear(); - List baseOrThemeStylesheet = Stream - .of(baseStyleSheet.getSceneStylesheet(), - theme.getAdditionalStylesheet().map(StyleSheet::getSceneStylesheet).orElse(null) - ).filter(Objects::nonNull) - .map(URL::toExternalForm) - .toList(); - - stylesheets.addAll(baseOrThemeStylesheet); + scene.getStylesheets().addAll(toAdd); } /// Registers a runnable on JavaFX thread to install the base and additional css files as stylesheets in the given scene. diff --git a/jabgui/src/main/java/org/jabref/migrations/PreferencesMigrations.java b/jabgui/src/main/java/org/jabref/migrations/PreferencesMigrations.java index 0ac6101a80d..8e901eb8b58 100644 --- a/jabgui/src/main/java/org/jabref/migrations/PreferencesMigrations.java +++ b/jabgui/src/main/java/org/jabref/migrations/PreferencesMigrations.java @@ -448,8 +448,13 @@ static void changeColumnVariableNamesFor51(JabRefCliPreferences preferences) { * they can deal with. */ static void restoreVariablesForBackwardCompatibility(JabRefCliPreferences preferences) { - // 5.0 preference name "columnNames". The new one is {@link JabRefPreferences#COLUMN_NAMES} - List oldColumnNames = preferences.getStringList("columnNames"); + final String V5_0_COLUMN_NAMES = "columnNames"; + final String V5_0_COLUMN_WIDTHS = "columnWidths"; + final String V5_0_COLUMN_SORT_TYPES = "columnSortTypes"; + final String V5_0_COLUMN_SORT_ORDER = "columnSortOrder"; + final String V5_0_MAIN_FONT_SIZE = "mainFontSize"; + + List oldColumnNames = preferences.getStringList(V5_0_COLUMN_NAMES); List fieldColumnNames = oldColumnNames.stream() .filter(columnName -> columnName.startsWith("field:") || columnName.startsWith("special:")) .map(columnName -> { @@ -461,25 +466,29 @@ static void restoreVariablesForBackwardCompatibility(JabRefCliPreferences prefer }).collect(Collectors.toList()); if (!fieldColumnNames.isEmpty()) { - preferences.putStringList("columnNames", fieldColumnNames); + preferences.putStringList(V5_0_COLUMN_NAMES, fieldColumnNames); List fieldColumnWidths = new ArrayList<>(List.of()); for (int i = 0; i < fieldColumnNames.size(); i++) { fieldColumnWidths.add("100"); } - preferences.putStringList("columnWidths", fieldColumnWidths); + preferences.putStringList(V5_0_COLUMN_WIDTHS, fieldColumnWidths); - preferences.put("columnSortTypes", ""); - preferences.put("columnSortOrder", ""); + preferences.put(V5_0_COLUMN_SORT_TYPES, ""); + preferences.put(V5_0_COLUMN_SORT_ORDER, ""); } // Ensure font size is a parsable int variable 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(JabRefGuiPreferences.MAIN_FONT_SIZE); + String fontSizeAsString = preferences.get(V5_0_MAIN_FONT_SIZE); + if (fontSizeAsString == null) { + return; + } + int fontSizeAsInt = (int) Math.round(Double.parseDouble(fontSizeAsString)); - preferences.putInt(JabRefGuiPreferences.MAIN_FONT_SIZE, fontSizeAsInt); + preferences.putInt(V5_0_MAIN_FONT_SIZE, fontSizeAsInt); } catch (ClassCastException e) { // already an integer } diff --git a/jabgui/src/main/resources/org/jabref/gui/preferences/PreferencesDialog.fxml b/jabgui/src/main/resources/org/jabref/gui/preferences/PreferencesDialog.fxml index 76088a729df..861573e783b 100644 --- a/jabgui/src/main/resources/org/jabref/gui/preferences/PreferencesDialog.fxml +++ b/jabgui/src/main/resources/org/jabref/gui/preferences/PreferencesDialog.fxml @@ -77,5 +77,5 @@ - + diff --git a/jabgui/src/main/resources/org/jabref/gui/preferences/general/GeneralTab.fxml b/jabgui/src/main/resources/org/jabref/gui/preferences/general/GeneralTab.fxml index 643c42d0789..c1808f16647 100644 --- a/jabgui/src/main/resources/org/jabref/gui/preferences/general/GeneralTab.fxml +++ b/jabgui/src/main/resources/org/jabref/gui/preferences/general/GeneralTab.fxml @@ -63,14 +63,12 @@ - +