Skip to content

Commit

Permalink
Pull down CoreGuiPreferences and Workspace preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Sep 9, 2024
1 parent c674fee commit c1ab2bf
Show file tree
Hide file tree
Showing 19 changed files with 220 additions and 209 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/exporter/SaveAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,12 +23,12 @@ public enum SaveMethod { SAVE, SAVE_AS, SAVE_SELECTED }
private final Supplier<LibraryTab> tabSupplier;

private final DialogService dialogService;
private final CliPreferences preferences;
private final GuiPreferences preferences;

public SaveAction(SaveMethod saveMethod,
Supplier<LibraryTab> tabSupplier,
DialogService dialogService,
CliPreferences preferences,
GuiPreferences preferences,
StateManager stateManager) {
this.saveMethod = saveMethod;
this.tabSupplier = tabSupplier;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/exporter/SaveAllAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
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;

public class SaveAllAction extends SimpleCommand {

private final Supplier<List<LibraryTab>> tabsSupplier;
private final DialogService dialogService;
private final CliPreferences preferences;
private final GuiPreferences preferences;

public SaveAllAction(Supplier<List<LibraryTab>> tabsSupplier, CliPreferences preferences, DialogService dialogService) {
public SaveAllAction(Supplier<List<LibraryTab>> tabsSupplier, GuiPreferences preferences, DialogService dialogService) {
this.tabsSupplier = tabsSupplier;
this.dialogService = dialogService;
this.preferences = preferences;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<GroupNodeViewModel> groupTree;
private TreeTableColumn<GroupNodeViewModel, GroupNodeViewModel> mainColumn;
Expand All @@ -106,7 +106,7 @@ public class GroupTreeView extends BorderPane {
*/
public GroupTreeView(TaskExecutor taskExecutor,
StateManager stateManager,
CliPreferences preferences,
GuiPreferences preferences,
DialogService dialogService,
ChatHistoryService chatHistoryService
) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/gui/preferences/GuiPreferences.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,4 +12,8 @@ public interface GuiPreferences extends org.jabref.logic.preferences.CliPreferen
MergeDialogPreferences getMergeDialogPreferences();

AutoCompletePreferences getAutoCompletePreferences();

CoreGuiPreferences getGuiPreferences();

WorkspacePreferences getWorkspacePreferences();
}
155 changes: 153 additions & 2 deletions src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package org.jabref.gui.preferences;

import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.SequencedMap;
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;
Expand All @@ -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";

Expand All @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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<Path>) 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<String>) change ->
putStringList(SELECTED_SLR_CATALOGS, workspacePreferences.getSelectedSlrCatalogs()));
return workspacePreferences;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit c1ab2bf

Please sign in to comment.