Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions jabgui/src/main/java/org/jabref/gui/WorkspacePreferences.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String> selectedSlrCatalogs;
Expand All @@ -36,7 +36,6 @@ public WorkspacePreferences(Language language,
boolean themeSyncOs,
boolean shouldOpenLastEdited,
boolean showAdvancedHints,
boolean warnAboutDuplicatesInInspection,
boolean confirmDelete,
boolean confirmHideTabBar,
List<String> selectedSlrCatalogs) {
Expand All @@ -48,12 +47,43 @@ 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
public WorkspacePreferences() {
this(
Language.getLanguageFor(Locale.getDefault().getLanguage()),
false,
9,
9,
new Theme(Theme.BASE_CSS),
false,
true,
true,
true,
true,
List.of()
);
}

public void reset() {
WorkspacePreferences defaults = new WorkspacePreferences();
this.language.set(defaults.getLanguage());
this.shouldOverrideDefaultFontSize.set(defaults.shouldOverrideDefaultFontSize());
this.mainFontSize.set(defaults.getMainFontSize());
this.defaultFontSize.set(defaults.getDefaultFontSize());
this.theme.set(defaults.getTheme());
this.themeSyncOs.set(defaults.shouldThemeSyncOs());
this.shouldOpenLastEdited.set(defaults.shouldOpenLastEdited());
this.showAdvancedHints.set(defaults.shouldShowAdvancedHints());
this.confirmDelete.set(defaults.shouldConfirmDelete());
this.confirmHideTabBar.set(defaults.shouldHideTabBar());
this.selectedSlrCatalogs.setAll(defaults.getSelectedSlrCatalogs());
}

public Language getLanguage() {
return language.get();
}
Expand Down Expand Up @@ -142,18 +172,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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,7 +84,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";
Expand Down Expand Up @@ -111,6 +111,17 @@ public class JabRefGuiPreferences extends JabRefCliPreferences implements GuiPre

private static final Logger LOGGER = LoggerFactory.getLogger(JabRefGuiPreferences.class);

// 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";

// region core GUI preferences
private static final String MAIN_WINDOW_POS_X = "mainWindowPosX";
private static final String MAIN_WINDOW_POS_Y = "mainWindowPosY";
Expand Down Expand Up @@ -150,16 +161,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";

/**
Expand Down Expand Up @@ -196,7 +197,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";
Expand Down Expand Up @@ -269,17 +269,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());
Expand Down Expand Up @@ -429,6 +418,12 @@ public CopyToPreferences getCopyToPreferences() {
return copyToPreferences;
}

@Override
public void clear() throws BackingStoreException {
super.clear();
getWorkspacePreferences().reset();
}

// region EntryEditorPreferences
public EntryEditorPreferences getEntryEditorPreferences() {
if (entryEditorPreferences != null) {
Expand Down Expand Up @@ -641,38 +636,46 @@ public WorkspacePreferences getWorkspacePreferences() {
return workspacePreferences;
}

WorkspacePreferences defaults = new 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),
getBoolean(OVERRIDE_DEFAULT_FONT_SIZE, defaults.shouldOverrideDefaultFontSize()),
getInt(MAIN_FONT_SIZE, defaults.getMainFontSize()),
new WorkspacePreferences().getDefaultFontSize(),
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));

EasyBind.listen(workspacePreferences.languageProperty(), (obs, oldValue, newValue) -> {
EasyBind.listen(workspacePreferences.languageProperty(), (_, 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));
EasyBind.listen(workspacePreferences.hideTabBarProperty(), (obs, oldValue, newValue) -> putBoolean(CONFIRM_HIDE_TAB_BAR, newValue));
workspacePreferences.getSelectedSlrCatalogs().addListener((ListChangeListener<String>) 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<String>) _ ->
putStringList(SELECTED_SLR_CATALOGS, workspacePreferences.getSelectedSlrCatalogs()));
return workspacePreferences;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +38,12 @@

public class GeneralTab extends AbstractPreferenceTabView<GeneralTabViewModel> implements PreferencesTab {

@Inject private HttpServerManager httpServerManager;
@Inject private LanguageServerController languageServerController;
@Inject private UiMessageHandler uiMessageHandler;
@Inject private RemoteListenerServerManager remoteListenerServerManager;
@Inject private StateManager stateManager;

@FXML private ComboBox<Language> language;
@FXML private ComboBox<ThemeTypes> theme;
@FXML private CheckBox themeSyncOs;
Expand All @@ -44,7 +53,6 @@ public class GeneralTab extends AbstractPreferenceTabView<GeneralTabViewModel> i
@FXML private Spinner<Integer> fontSize;
@FXML private CheckBox openLastStartup;
@FXML private CheckBox showAdvancedHints;
@FXML private CheckBox inspectionWarningDuplicate;

@FXML private CheckBox confirmDelete;
@FXML private CheckBox shouldAskForIncludingCrossReferences;
Expand All @@ -63,8 +71,6 @@ public class GeneralTab extends AbstractPreferenceTabView<GeneralTabViewModel> 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();

Expand All @@ -90,7 +96,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<Language>()
.withText(Language::getDisplayName)
Expand Down Expand Up @@ -124,7 +137,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());
Expand Down
Loading
Loading