diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index 74b9c84d3c2..37009e28f25 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -310,20 +310,20 @@ private void writeMetadatatoPDFsOfEntry(BibDatabaseContext databaseContext, Stri try { if (writeXMP) { if (xmpPdfExporter.exportToAllFilesOfEntry(databaseContext, encoding, filePreferences, entry, List.of(entry))) { - System.out.println(String.format("Successfully written XMP metadata on at least one linked file of %s", citeKey)); + System.out.printf("Successfully written XMP metadata on at least one linked file of %s%n", citeKey); } else { - System.err.println(String.format("Cannot write XMP metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.", citeKey)); + System.err.printf("Cannot write XMP metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.%n", citeKey); } } if (embeddBibfile) { if (embeddedBibFilePdfExporter.exportToAllFilesOfEntry(databaseContext, encoding, filePreferences, entry, List.of(entry))) { - System.out.println(String.format("Successfully embedded metadata on at least one linked file of %s", citeKey)); + System.out.printf("Successfully embedded metadata on at least one linked file of %s%n", citeKey); } else { - System.out.println(String.format("Cannot embedd metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.", citeKey)); + System.out.printf("Cannot embedd metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.%n", citeKey); } } } catch (Exception e) { - LOGGER.error(String.format("Failed writing metadata on a linked file of %s.", citeKey)); + LOGGER.error("Failed writing metadata on a linked file of {}.", citeKey); } } @@ -331,7 +331,7 @@ private void writeMetadatatoPdfByCitekey(BibDatabaseContext databaseContext, Bib for (String citeKey : citeKeys) { List bibEntryList = dataBase.getEntriesByCitationKey(citeKey); if (bibEntryList.isEmpty()) { - System.err.println(String.format("Skipped - Cannot find %s in library.", citeKey)); + System.err.printf("Skipped - Cannot find %s in library.%n", citeKey); continue; } for (BibEntry entry : bibEntryList) { @@ -350,25 +350,25 @@ private void writeMetadatatoPdfByFileNames(BibDatabaseContext databaseContext, B try { if (writeXMP) { if (xmpPdfExporter.exportToFileByPath(databaseContext, dataBase, encoding, filePreferences, filePath)) { - System.out.println(String.format("Successfully written XMP metadata of at least one entry to %s", fileName)); + System.out.printf("Successfully written XMP metadata of at least one entry to %s%n", fileName); } else { - System.out.println(String.format("File %s is not linked to any entry in database.", fileName)); + System.out.printf("File %s is not linked to any entry in database.%n", fileName); } } if (embeddBibfile) { if (embeddedBibFilePdfExporter.exportToFileByPath(databaseContext, dataBase, encoding, filePreferences, filePath)) { - System.out.println(String.format("Successfully embedded XMP metadata of at least one entry to %s", fileName)); + System.out.printf("Successfully embedded XMP metadata of at least one entry to %s%n", fileName); } else { - System.out.println(String.format("File %s is not linked to any entry in database.", fileName)); + System.out.printf("File %s is not linked to any entry in database.%n", fileName); } } } catch (IOException e) { LOGGER.error("Error accessing file '{}'.", fileName); } catch (Exception e) { - LOGGER.error(String.format("Error writing entry to %s.", fileName)); + LOGGER.error("Error writing entry to {}.", fileName); } } else { - LOGGER.error(String.format("Skipped - PDF %s does not exist", fileName)); + LOGGER.error("Skipped - PDF {} does not exist", fileName); } } } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 073371ea4bf..bc911a31ac2 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -754,19 +754,20 @@ private MenuBar createMenu() { factory.createMenuItem(StandardActions.MASS_SET_FIELDS, new MassSetFieldsAction(stateManager, dialogService, undoManager)) ); - if (prefs.getSpecialFieldsPreferences().isSpecialFieldsEnabled()) { - edit.getItems().addAll( - new SeparatorMenuItem(), - // ToDo: SpecialField needs the active BasePanel to mark it as changed. - // Refactor BasePanel, should mark the BibDatabaseContext or the UndoManager as dirty instead! - SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, this, dialogService, prefs, undoManager, stateManager), - SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, this, dialogService, prefs, undoManager, stateManager), - SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, this, dialogService, prefs, undoManager, stateManager), - SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, this, dialogService, prefs, undoManager, stateManager), - SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, this, dialogService, prefs, undoManager, stateManager), - SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, this, dialogService, prefs, undoManager, stateManager) - ); - } + SeparatorMenuItem specialFieldsSeparator = new SeparatorMenuItem(); + specialFieldsSeparator.visibleProperty().bind(prefs.getSpecialFieldsPreferences().specialFieldsEnabledProperty()); + + edit.getItems().addAll( + specialFieldsSeparator, + // ToDo: SpecialField needs the active BasePanel to mark it as changed. + // Refactor BasePanel, should mark the BibDatabaseContext or the UndoManager as dirty instead! + SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, this, dialogService, prefs, undoManager, stateManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, this, dialogService, prefs, undoManager, stateManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, this, dialogService, prefs, undoManager, stateManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, this, dialogService, prefs, undoManager, stateManager), + SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, this, dialogService, prefs, undoManager, stateManager), + SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, this, dialogService, prefs, undoManager, stateManager) + ); // @formatter:off library.getItems().addAll( @@ -1192,7 +1193,7 @@ private Boolean confirmEmptyEntry(LibraryTab libraryTab, BibDatabaseContext cont if (response.isPresent() && response.get().equals(deleteEmptyEntries)) { // The user wants to delete. try { - for (BibEntry currentEntry : new ArrayList(context.getEntries())) { + for (BibEntry currentEntry : new ArrayList<>(context.getEntries())) { if (currentEntry.getFields().isEmpty()) { context.getDatabase().removeEntries(Collections.singletonList(currentEntry)); } diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index c139ae93a26..4edab4cd9ff 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -59,9 +59,9 @@ public JabRefGUI(Stage mainStage, List databases, boolean isBlank, openWindow(mainStage); new VersionWorker(Globals.BUILD_INFO.version, - preferencesService.getVersionPreferences().getIgnoredVersion(), mainFrame.getDialogService(), - Globals.TASK_EXECUTOR) + Globals.TASK_EXECUTOR, + preferencesService.getVersionPreferences()) .checkForNewVersionDelayed(); } diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index 2e75f23a18f..cf5504b591f 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -31,7 +31,6 @@ import org.jabref.gui.importer.actions.OpenDatabaseAction; import org.jabref.gui.maintable.MainTable; import org.jabref.gui.maintable.MainTableDataModel; -import org.jabref.gui.specialfields.SpecialFieldDatabaseChangeListener; import org.jabref.gui.undo.CountingUndoManager; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableFieldChange; @@ -465,8 +464,6 @@ public void editEntryAndFocusField(BibEntry entry, Field field) { } private void createMainTable() { - bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.INSTANCE); - mainTable = new MainTable(tableModel, this, bibDatabaseContext, diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java index 7280deb9819..ae7de0b43e0 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java @@ -93,7 +93,7 @@ private void browseButtonClicked() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(StandardFileType.AUX) .withDefaultExtension(StandardFileType.AUX) - .withInitialDirectory(preferences.getWorkingDir()).build(); + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()).build(); dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> auxFileField.setText(file.toAbsolutePath().toString())); } } diff --git a/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java b/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java index 72ec5c64266..29bc0716b59 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java +++ b/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java @@ -14,40 +14,40 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.LinkedFile; import org.jabref.model.util.OptionalUtil; -import org.jabref.preferences.PreferencesService; +import org.jabref.preferences.FilePreferences; public class CopySingleFileAction extends SimpleCommand { private final LinkedFile linkedFile; private final DialogService dialogService; private final BibDatabaseContext databaseContext; - private final PreferencesService preferencesService; + private final FilePreferences filePreferences; private final BiFunction resolvePathFilename = (path, file) -> path.resolve(file.getFileName()); - public CopySingleFileAction(LinkedFile linkedFile, DialogService dialogService, BibDatabaseContext databaseContext, PreferencesService preferencesService) { + public CopySingleFileAction(LinkedFile linkedFile, DialogService dialogService, BibDatabaseContext databaseContext, FilePreferences filePreferences) { this.linkedFile = linkedFile; this.dialogService = dialogService; this.databaseContext = databaseContext; - this.preferencesService = preferencesService; + this.filePreferences = filePreferences; this.executable.bind(Bindings.createBooleanBinding( () -> !linkedFile.isOnlineLink() - && linkedFile.findIn(databaseContext, preferencesService.getFilePreferences()).isPresent(), + && linkedFile.findIn(databaseContext, this.filePreferences).isPresent(), linkedFile.linkProperty())); } @Override public void execute() { DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(preferencesService.getWorkingDir()) + .withInitialDirectory(filePreferences.getWorkingDirectory()) .build(); Optional exportPath = dialogService.showDirectorySelectionDialog(dirDialogConfiguration); exportPath.ifPresent(this::copyFileToDestination); } private void copyFileToDestination(Path exportPath) { - Optional fileToExport = linkedFile.findIn(databaseContext, preferencesService.getFilePreferences()); + Optional fileToExport = linkedFile.findIn(databaseContext, filePreferences); Optional newPath = OptionalUtil.combine(Optional.of(exportPath), fileToExport, resolvePathFilename); if (newPath.isPresent()) { diff --git a/src/main/java/org/jabref/gui/entryeditor/LatexCitationsTabViewModel.java b/src/main/java/org/jabref/gui/entryeditor/LatexCitationsTabViewModel.java index 7673eb62d2b..fbfbb5c37e3 100644 --- a/src/main/java/org/jabref/gui/entryeditor/LatexCitationsTabViewModel.java +++ b/src/main/java/org/jabref/gui/entryeditor/LatexCitationsTabViewModel.java @@ -60,14 +60,16 @@ enum Status { private LatexParserResult latexParserResult; private BibEntry currentEntry; - public LatexCitationsTabViewModel(BibDatabaseContext databaseContext, PreferencesService preferencesService, - TaskExecutor taskExecutor, DialogService dialogService) { + public LatexCitationsTabViewModel(BibDatabaseContext databaseContext, + PreferencesService preferencesService, + TaskExecutor taskExecutor, + DialogService dialogService) { this.databaseContext = databaseContext; this.preferencesService = preferencesService; this.taskExecutor = taskExecutor; this.dialogService = dialogService; - this.directory = new SimpleObjectProperty(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getUser()) - .orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService))); + this.directory = new SimpleObjectProperty<>(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUser()) + .orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService.getFilePreferences().getWorkingDirectory()))); this.citationList = FXCollections.observableArrayList(); this.status = new SimpleObjectProperty<>(Status.IN_PROGRESS); this.searchError = new SimpleStringProperty(""); @@ -128,8 +130,8 @@ private void cancelSearch() { private Collection searchAndParse(String citeKey) throws IOException { // we need to check whether the user meanwhile set the LaTeX file directory or the database changed locations - Path newDirectory = databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getUser()) - .orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService)); + Path newDirectory = databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUser()) + .orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService.getFilePreferences().getWorkingDirectory())); if (latexParserResult == null || !newDirectory.equals(directory.get())) { directory.set(newDirectory); @@ -170,7 +172,7 @@ public void setLatexDirectory() { .withInitialDirectory(directory.get()).build(); dialogService.showDirectorySelectionDialog(directoryDialogConfiguration).ifPresent(selectedDirectory -> - databaseContext.getMetaData().setLatexFileDirectory(preferencesService.getUser(), selectedDirectory.toAbsolutePath())); + databaseContext.getMetaData().setLatexFileDirectory(preferencesService.getFilePreferences().getUser(), selectedDirectory.toAbsolutePath())); init(currentEntry); } diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index 9757b885615..5ae882116e9 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -160,10 +160,10 @@ private Optional askForSavePath() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(StandardFileType.BIBTEX_DB) .withDefaultExtension(StandardFileType.BIBTEX_DB) - .withInitialDirectory(preferences.getWorkingDir()) + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()) .build(); Optional selectedPath = dialogService.showFileSaveDialog(fileDialogConfiguration); - selectedPath.ifPresent(path -> preferences.setWorkingDirectory(path.getParent())); + selectedPath.ifPresent(path -> preferences.getFilePreferences().setWorkingDirectory(path.getParent())); if (selectedPath.isPresent()) { Path savePath = selectedPath.get(); // Workaround for linux systems not adding file extension diff --git a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java index 69c62af874a..c516be37f86 100644 --- a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java @@ -80,8 +80,13 @@ public class UnlinkedFilesDialogViewModel { private final FunctionBasedValidator scanDirectoryValidator; - public UnlinkedFilesDialogViewModel(DialogService dialogService, ExternalFileTypes externalFileTypes, UndoManager undoManager, - FileUpdateMonitor fileUpdateMonitor, PreferencesService preferences, StateManager stateManager, TaskExecutor taskExecutor) { + public UnlinkedFilesDialogViewModel(DialogService dialogService, + ExternalFileTypes externalFileTypes, + UndoManager undoManager, + FileUpdateMonitor fileUpdateMonitor, + PreferencesService preferences, + StateManager stateManager, + TaskExecutor taskExecutor) { this.preferences = preferences; this.dialogService = dialogService; this.taskExecutor = taskExecutor; @@ -95,9 +100,9 @@ public UnlinkedFilesDialogViewModel(DialogService dialogService, ExternalFileTyp stateManager); this.fileFilterList = FXCollections.observableArrayList( - new FileExtensionViewModel(StandardFileType.ANY_FILE, externalFileTypes), - new FileExtensionViewModel(StandardFileType.BIBTEX_DB, externalFileTypes), - new FileExtensionViewModel(StandardFileType.PDF, externalFileTypes)); + new FileExtensionViewModel(StandardFileType.ANY_FILE, externalFileTypes), + new FileExtensionViewModel(StandardFileType.BIBTEX_DB, externalFileTypes), + new FileExtensionViewModel(StandardFileType.PDF, externalFileTypes)); this.dateFilterList = FXCollections.observableArrayList(DateRange.values()); @@ -175,7 +180,7 @@ public void startExport() { } FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .withInitialDirectory(preferences.getWorkingDir()) + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()) .addExtensionFilter(StandardFileType.TXT) .withDefaultExtension(StandardFileType.TXT) .build(); @@ -218,12 +223,12 @@ public void cancelTasks() { public void browseFileDirectory() { DirectoryDialogConfiguration directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(preferences.getWorkingDir()).build(); + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()).build(); dialogService.showDirectorySelectionDialog(directoryDialogConfiguration) .ifPresent(selectedDirectory -> { directoryPath.setValue(selectedDirectory.toAbsolutePath().toString()); - preferences.setWorkingDirectory(selectedDirectory.toAbsolutePath()); + preferences.getFilePreferences().setWorkingDirectory(selectedDirectory.toAbsolutePath()); }); } diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index a13eeb6a310..36aba630f54 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -275,7 +275,7 @@ private ContextMenu createContextMenuForFile(LinkedFileViewModel linkedFile) { factory.createMenuItem(StandardActions.RENAME_FILE_TO_NAME, new ContextAction(StandardActions.RENAME_FILE_TO_NAME, linkedFile, preferencesService)), factory.createMenuItem(StandardActions.MOVE_FILE_TO_FOLDER, new ContextAction(StandardActions.MOVE_FILE_TO_FOLDER, linkedFile, preferencesService)), factory.createMenuItem(StandardActions.MOVE_FILE_TO_FOLDER_AND_RENAME, new ContextAction(StandardActions.MOVE_FILE_TO_FOLDER_AND_RENAME, linkedFile, preferencesService)), - factory.createMenuItem(StandardActions.COPY_FILE_TO_FOLDER, new CopySingleFileAction(linkedFile.getFile(), dialogService, databaseContext, preferencesService)), + factory.createMenuItem(StandardActions.COPY_FILE_TO_FOLDER, new CopySingleFileAction(linkedFile.getFile(), dialogService, databaseContext, preferencesService.getFilePreferences())), factory.createMenuItem(StandardActions.REMOVE_LINK, new ContextAction(StandardActions.REMOVE_LINK, linkedFile, preferencesService)), factory.createMenuItem(StandardActions.DELETE_FILE, new ContextAction(StandardActions.DELETE_FILE, linkedFile, preferencesService)) ); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java index e3f542e4a95..f9c7f1e67e5 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java @@ -137,7 +137,7 @@ public ListProperty filesProperty() { public void addNewFile() { Path workingDirectory = databaseContext.getFirstExistingFileDir(preferences.getFilePreferences()) - .orElse(preferences.getWorkingDir()); + .orElse(preferences.getFilePreferences().getWorkingDirectory()); FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .withInitialDirectory(workingDirectory) diff --git a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java index 7714fcdcfa0..522d129bb08 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java @@ -83,7 +83,7 @@ public class GroupDialogViewModel { private final BooleanProperty keywordGroupRegexProperty = new SimpleBooleanProperty(); private final StringProperty searchGroupSearchTermProperty = new SimpleStringProperty(""); - private final ObjectProperty> searchFlagsProperty = new SimpleObjectProperty(EnumSet.noneOf(SearchFlags.class)); + private final ObjectProperty> searchFlagsProperty = new SimpleObjectProperty<>(EnumSet.noneOf(SearchFlags.class)); private final BooleanProperty autoGroupKeywordsOptionProperty = new SimpleBooleanProperty(); private final StringProperty autoGroupKeywordsFieldProperty = new SimpleStringProperty(""); @@ -236,7 +236,7 @@ private void setupValidation() { return false; } return FileUtil.getFileExtension(input) - .map(extension -> extension.toLowerCase().equals("aux")) + .map(extension -> extension.equalsIgnoreCase("aux")) .orElse(false); } }, @@ -273,7 +273,7 @@ private void setupValidation() { * @return an absolute path if LatexFileDirectory exists; otherwise, returns input */ private Path getAbsoluteTexGroupPath(String input) { - Optional latexFileDirectory = currentDatabase.getMetaData().getLatexFileDirectory(preferencesService.getUser()); + Optional latexFileDirectory = currentDatabase.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUser()); return latexFileDirectory.map(path -> path.resolve(input)).orElse(Path.of(input)); } @@ -436,8 +436,8 @@ public void texGroupBrowse() { .addExtensionFilter(StandardFileType.AUX) .withDefaultExtension(StandardFileType.AUX) .withInitialDirectory(currentDatabase.getMetaData() - .getLatexFileDirectory(preferencesService.getUser()) - .orElse(FileUtil.getInitialDirectory(currentDatabase, preferencesService))).build(); + .getLatexFileDirectory(preferencesService.getFilePreferences().getUser()) + .orElse(FileUtil.getInitialDirectory(currentDatabase, preferencesService.getFilePreferences().getWorkingDirectory()))).build(); dialogService.showFileOpenDialog(fileDialogConfiguration) .ifPresent(file -> texGroupFilePathProperty.setValue( FileUtil.relativize(file.toAbsolutePath(), getFileDirectoriesAsPaths()).toString() diff --git a/src/main/java/org/jabref/gui/help/NewVersionDialog.java b/src/main/java/org/jabref/gui/help/NewVersionDialog.java index 5c61943d2aa..2ab73b250a5 100644 --- a/src/main/java/org/jabref/gui/help/NewVersionDialog.java +++ b/src/main/java/org/jabref/gui/help/NewVersionDialog.java @@ -7,14 +7,12 @@ import javafx.scene.control.Label; import javafx.scene.layout.VBox; -import org.jabref.gui.Globals; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.util.BaseDialog; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.Version; -import org.jabref.preferences.VersionPreferences; -public class NewVersionDialog extends BaseDialog { +public class NewVersionDialog extends BaseDialog { public NewVersionDialog(Version currentVersion, Version latestVersion) { this.setTitle(Localization.lang("New version available")); @@ -25,11 +23,11 @@ public NewVersionDialog(Version currentVersion, Version latestVersion) { this.getDialogPane().getButtonTypes().addAll(btnIgnoreUpdate, btnDownloadUpdate, btnRemindMeLater); this.setResultConverter(button -> { if (button == btnIgnoreUpdate) { - Globals.prefs.storeVersionPreferences(new VersionPreferences(latestVersion)); + return false; } else if (button == btnDownloadUpdate) { JabRefDesktop.openBrowserShowPopup(Version.JABREF_DOWNLOAD_URL); } - return null; + return true; }); Button defaultButton = (Button) this.getDialogPane().lookupButton(btnDownloadUpdate); defaultButton.setDefaultButton(true); diff --git a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java index 5e39a0e6d7c..ddf013c2ded 100644 --- a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java +++ b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java @@ -22,7 +22,7 @@ public SearchForUpdateAction(BuildInfo buildInfo, VersionPreferences versionPref @Override public void execute() { - new VersionWorker(buildInfo.version, versionPreferences.getIgnoredVersion(), dialogService, taskExecutor) + new VersionWorker(buildInfo.version, dialogService, taskExecutor, versionPreferences) .checkForNewVersionAsync(); } } diff --git a/src/main/java/org/jabref/gui/help/VersionWorker.java b/src/main/java/org/jabref/gui/help/VersionWorker.java index 139565c9df8..e22ed8aa583 100644 --- a/src/main/java/org/jabref/gui/help/VersionWorker.java +++ b/src/main/java/org/jabref/gui/help/VersionWorker.java @@ -11,6 +11,7 @@ import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.Version; +import org.jabref.preferences.VersionPreferences; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,19 +33,19 @@ public class VersionWorker { */ private final Version installedVersion; - /** - * The version which was previously ignored by the user - */ - private final Version toBeIgnored; - private final DialogService dialogService; private final TaskExecutor taskExecutor; + private final VersionPreferences versionPreferences; - public VersionWorker(Version installedVersion, Version toBeIgnored, DialogService dialogService, TaskExecutor taskExecutor) { + public VersionWorker(Version installedVersion, + + DialogService dialogService, + TaskExecutor taskExecutor, + VersionPreferences versionPreferences) { this.installedVersion = Objects.requireNonNull(installedVersion); - this.toBeIgnored = Objects.requireNonNull(toBeIgnored); this.dialogService = Objects.requireNonNull(dialogService); this.taskExecutor = Objects.requireNonNull(taskExecutor); + this.versionPreferences = versionPreferences; } /** @@ -88,13 +89,15 @@ private void showConnectionError(Exception exception, boolean manualExecution) { */ private void showUpdateInfo(Optional newerVersion, boolean manualExecution) { // no new version could be found, only respect the ignored version on automated version checks - if (!newerVersion.isPresent() || (newerVersion.get().equals(toBeIgnored) && !manualExecution)) { + if (newerVersion.isEmpty() || (newerVersion.get().equals(versionPreferences.getIgnoredVersion()) && !manualExecution)) { if (manualExecution) { dialogService.notify(Localization.lang("JabRef is up-to-date.")); } } else { // notify the user about a newer version - dialogService.showCustomDialogAndWait(new NewVersionDialog(installedVersion, newerVersion.get())); + if (dialogService.showCustomDialogAndWait(new NewVersionDialog(installedVersion, newerVersion.get())).orElse(true)) { + versionPreferences.setIgnoredVersion(newerVersion.get()); + } } } } diff --git a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java index bd1bbee5af4..39b22f76f55 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -94,10 +94,10 @@ public void execute() { */ private Path getInitialDirectory() { if (frame.getBasePanelCount() == 0) { - return preferencesService.getWorkingDir(); + return preferencesService.getFilePreferences().getWorkingDirectory(); } else { Optional databasePath = frame.getCurrentLibraryTab().getBibDatabaseContext().getDatabasePath(); - return databasePath.map(Path::getParent).orElse(preferencesService.getWorkingDir()); + return databasePath.map(Path::getParent).orElse(preferencesService.getFilePreferences().getWorkingDirectory()); } } @@ -181,7 +181,7 @@ private ParserResult loadDatabase(Path file) throws Exception { dialogService.notify(Localization.lang("Opening") + ": '" + file + "'"); - preferencesService.setWorkingDirectory(fileToLoad.getParent()); + preferencesService.getFilePreferences().setWorkingDirectory(fileToLoad.getParent()); if (BackupManager.backupFileDiffers(fileToLoad)) { BackupUIManager.showRestoreBackupDialog(dialogService, fileToLoad); diff --git a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java index f3a37a6092d..d07206d881b 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java @@ -75,7 +75,7 @@ public LibraryPropertiesDialogViewModel(BibDatabaseContext databaseContext, Dial this.initialSaveOrderConfig = initialMetaData.getSaveOrderConfig().orElseGet(preferences::getExportSaveOrder); this.directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(preferences.getWorkingDir()).build(); + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()).build(); setValues(); } @@ -88,8 +88,8 @@ void setValues() { selectedEncodingPropety.setValue(initialMetaData.getEncoding().orElse(preferences.getGeneralPreferences().getDefaultEncoding())); selectedDatabaseModeProperty.setValue(initialMetaData.getMode().orElse(BibDatabaseMode.BIBLATEX)); generalFileDirectoryProperty.setValue(initialMetaData.getDefaultFileDirectory().orElse("").trim()); - userSpecificFileDirectoryProperty.setValue(initialMetaData.getUserFileDirectory(preferences.getUser()).orElse("").trim()); - laTexFileDirectoryProperty.setValue(initialMetaData.getLatexFileDirectory(preferences.getUser()).map(Path::toString).orElse("")); + userSpecificFileDirectoryProperty.setValue(initialMetaData.getUserFileDirectory(preferences.getFilePreferences().getUser()).orElse("").trim()); + laTexFileDirectoryProperty.setValue(initialMetaData.getLatexFileDirectory(preferences.getFilePreferences().getUser()).map(Path::toString).orElse("")); libraryProtectedProperty.setValue(initialMetaData.isProtected()); // SaveOrderConfigPanel @@ -134,16 +134,16 @@ void storeSettings() { String userSpecificFileDirectory = userSpecificFileDirectoryProperty.getValue(); if (userSpecificFileDirectory.isEmpty()) { - newMetaData.clearUserFileDirectory(preferences.getUser()); + newMetaData.clearUserFileDirectory(preferences.getFilePreferences().getUser()); } else { - newMetaData.setUserFileDirectory(preferences.getUser(), userSpecificFileDirectory); + newMetaData.setUserFileDirectory(preferences.getFilePreferences().getUser(), userSpecificFileDirectory); } String latexFileDirectory = laTexFileDirectoryProperty.getValue(); if (latexFileDirectory.isEmpty()) { - newMetaData.clearLatexFileDirectory(preferences.getUser()); + newMetaData.clearLatexFileDirectory(preferences.getFilePreferences().getUser()); } else { - newMetaData.setLatexFileDirectory(preferences.getUser(), Path.of(latexFileDirectory)); + newMetaData.setLatexFileDirectory(preferences.getFilePreferences().getUser(), Path.of(latexFileDirectory)); } if (libraryProtectedProperty.getValue()) { diff --git a/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java b/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java index a0b6ff4602d..00e0c1f3b4b 100644 --- a/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java +++ b/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java @@ -17,23 +17,23 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.LinkedFile; -import org.jabref.preferences.PreferencesService; +import org.jabref.preferences.FilePreferences; public class AttachFileAction extends SimpleCommand { private final LibraryTab libraryTab; private final StateManager stateManager; private final DialogService dialogService; - private final PreferencesService preferencesService; + private final FilePreferences filePreferences; public AttachFileAction(LibraryTab libraryTab, DialogService dialogService, StateManager stateManager, - PreferencesService preferencesService) { + FilePreferences filePreferences) { this.libraryTab = libraryTab; this.stateManager = stateManager; this.dialogService = dialogService; - this.preferencesService = preferencesService; + this.filePreferences = filePreferences; this.executable.bind(ActionHelper.needsEntriesSelected(1, stateManager)); } @@ -54,8 +54,8 @@ public void execute() { BibEntry entry = stateManager.getSelectedEntries().get(0); - Path workingDirectory = databaseContext.getFirstExistingFileDir(preferencesService.getFilePreferences()) - .orElse(preferencesService.getWorkingDir()); + Path workingDirectory = databaseContext.getFirstExistingFileDir(filePreferences) + .orElse(filePreferences.getWorkingDirectory()); FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .withInitialDirectory(workingDirectory) @@ -63,7 +63,7 @@ public void execute() { dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> { LinkedFile linkedFile = LinkedFilesEditorViewModel.fromFile(newFile, - databaseContext.getFileDirectories(preferencesService.getFilePreferences()), + databaseContext.getFileDirectories(filePreferences), ExternalFileTypes.getInstance()); LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(linkedFile); diff --git a/src/main/java/org/jabref/gui/linkedfile/LinkedFileEditDialogView.java b/src/main/java/org/jabref/gui/linkedfile/LinkedFileEditDialogView.java index 5ea1e9fb344..b470265e78d 100644 --- a/src/main/java/org/jabref/gui/linkedfile/LinkedFileEditDialogView.java +++ b/src/main/java/org/jabref/gui/linkedfile/LinkedFileEditDialogView.java @@ -32,7 +32,7 @@ public class LinkedFileEditDialogView extends BaseDialog { private LinkedFilesEditDialogViewModel viewModel; private final LinkedFile linkedFile; - private ExternalFileTypes externalFileTypes; + private final ExternalFileTypes externalFileTypes; public LinkedFileEditDialogView(LinkedFile linkedFile) { this.linkedFile = linkedFile; @@ -56,7 +56,7 @@ public LinkedFileEditDialogView(LinkedFile linkedFile) { @FXML private void initialize() { - viewModel = new LinkedFilesEditDialogViewModel(linkedFile, stateManager.getActiveDatabase().get(), dialogService, preferences, externalFileTypes); + viewModel = new LinkedFilesEditDialogViewModel(linkedFile, stateManager.getActiveDatabase().get(), dialogService, preferences.getFilePreferences(), externalFileTypes); fileType.itemsProperty().bindBidirectional(viewModel.externalFileTypeProperty()); description.textProperty().bindBidirectional(viewModel.descriptionProperty()); link.textProperty().bindBidirectional(viewModel.linkProperty()); diff --git a/src/main/java/org/jabref/gui/linkedfile/LinkedFilesEditDialogViewModel.java b/src/main/java/org/jabref/gui/linkedfile/LinkedFilesEditDialogViewModel.java index b69789282f9..2d5175bd3d4 100644 --- a/src/main/java/org/jabref/gui/linkedfile/LinkedFilesEditDialogViewModel.java +++ b/src/main/java/org/jabref/gui/linkedfile/LinkedFilesEditDialogViewModel.java @@ -25,7 +25,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.LinkedFile; import org.jabref.model.util.FileHelper; -import org.jabref.preferences.PreferencesService; +import org.jabref.preferences.FilePreferences; import com.tobiasdiez.easybind.EasyBind; import com.tobiasdiez.easybind.optional.ObservableOptionalValue; @@ -40,13 +40,13 @@ public class LinkedFilesEditDialogViewModel extends AbstractViewModel { private final ObservableOptionalValue monadicSelectedExternalFileType; private final BibDatabaseContext database; private final DialogService dialogService; - private final PreferencesService preferences; + private final FilePreferences filePreferences; private final ExternalFileTypes externalFileTypes; - public LinkedFilesEditDialogViewModel(LinkedFile linkedFile, BibDatabaseContext database, DialogService dialogService, PreferencesService preferences, ExternalFileTypes externalFileTypes) { + public LinkedFilesEditDialogViewModel(LinkedFile linkedFile, BibDatabaseContext database, DialogService dialogService, FilePreferences filePreferences, ExternalFileTypes externalFileTypes) { this.database = database; this.dialogService = dialogService; - this.preferences = preferences; + this.filePreferences = filePreferences; this.externalFileTypes = externalFileTypes; allExternalFileTypes.set(FXCollections.observableArrayList(externalFileTypes.getExternalFileTypeSelection())); @@ -71,9 +71,9 @@ private void setExternalFileTypeByExtension(String link) { public void openBrowseDialog() { String fileText = link.get(); - Optional file = FileHelper.find(database, fileText, preferences.getFilePreferences()); + Optional file = FileHelper.find(database, fileText, filePreferences); - Path workingDir = file.orElse(preferences.getWorkingDir()); + Path workingDir = file.orElse(filePreferences.getWorkingDirectory()); String fileName = Path.of(fileText).getFileName().toString(); FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() @@ -83,7 +83,7 @@ public void openBrowseDialog() { dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(path -> { // Store the directory for next time: - preferences.setWorkingDirectory(path); + filePreferences.setWorkingDirectory(path); link.set(relativize(path)); setExternalFileTypeByExtension(link.getValueSafe()); @@ -140,7 +140,7 @@ public LinkedFile getNewLinkedFile() { } private String relativize(Path filePath) { - List fileDirectories = database.getFileDirectories(preferences.getFilePreferences()); + List fileDirectories = database.getFileDirectories(filePreferences); return FileUtil.relativize(filePath, fileDirectories).toString(); } } diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index de00201399b..31fd414d1b0 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -57,18 +57,16 @@ public static ContextMenu create(BibEntryTableViewModel entry, contextMenu.getItems().add(new SeparatorMenuItem()); - if (preferencesService.getSpecialFieldsPreferences().isSpecialFieldsEnabled()) { - contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); - } + contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); contextMenu.getItems().add(new SeparatorMenuItem()); - contextMenu.getItems().add(factory.createMenuItem(StandardActions.ATTACH_FILE, new AttachFileAction(libraryTab, dialogService, stateManager, preferencesService))); + contextMenu.getItems().add(factory.createMenuItem(StandardActions.ATTACH_FILE, new AttachFileAction(libraryTab, dialogService, stateManager, preferencesService.getFilePreferences()))); contextMenu.getItems().add(factory.createMenuItem(StandardActions.OPEN_FOLDER, new OpenFolderAction(dialogService, stateManager, preferencesService))); contextMenu.getItems().add(factory.createMenuItem(StandardActions.OPEN_EXTERNAL_FILE, new OpenExternalFileAction(dialogService, stateManager, preferencesService))); contextMenu.getItems().add(factory.createMenuItem(StandardActions.OPEN_URL, new OpenUrlAction(dialogService, stateManager, preferencesService))); diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java index bd307cd93ba..2fccfd5a332 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java @@ -62,7 +62,7 @@ public void addStyleFile() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(Localization.lang("Style file"), StandardFileType.JSTYLE) .withDefaultExtension(Localization.lang("Style file"), StandardFileType.JSTYLE) - .withInitialDirectory(preferencesService.getWorkingDir()) + .withInitialDirectory(preferencesService.getFilePreferences().getWorkingDirectory()) .build(); Optional path = dialogService.showFileOpenDialog(fileDialogConfiguration); path.map(Path::toAbsolutePath).map(Path::toString).ifPresent(stylePath -> { diff --git a/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java b/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java index 4e0ec263e83..218c76d940a 100644 --- a/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java @@ -84,7 +84,7 @@ public void addImporter() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(StandardFileType.CLASS, StandardFileType.JAR, StandardFileType.ZIP) .withDefaultExtension(StandardFileType.CLASS) - .withInitialDirectory(preferences.getWorkingDir()) + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()) .build(); Optional selectedFile = dialogService.showFileOpenDialog(fileDialogConfiguration); diff --git a/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java index 783f6069aca..eca825e896f 100644 --- a/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java @@ -42,15 +42,13 @@ public class LinkedFilesTabViewModel implements PreferenceTabViewModel { private final Validator mainFileDirValidator; private final DialogService dialogService; - private final PreferencesService preferences; private final FilePreferences filePreferences; - private final AutoLinkPreferences initialAutoLinkPreferences; + private final AutoLinkPreferences autoLinkPreferences; public LinkedFilesTabViewModel(DialogService dialogService, PreferencesService preferences) { this.dialogService = dialogService; - this.preferences = preferences; this.filePreferences = preferences.getFilePreferences(); - this.initialAutoLinkPreferences = preferences.getAutoLinkPreferences(); + this.autoLinkPreferences = preferences.getAutoLinkPreferences(); mainFileDirValidator = new FunctionBasedValidator<>( mainFileDirectoryProperty, @@ -82,13 +80,13 @@ public void setValues() { fileDirectoryPatternProperty.setValue(filePreferences.getFileDirectoryPattern()); // Autolink preferences - switch (initialAutoLinkPreferences.getCitationKeyDependency()) { + switch (autoLinkPreferences.getCitationKeyDependency()) { case START -> autolinkFileStartsBibtexProperty.setValue(true); case EXACT -> autolinkFileExactBibtexProperty.setValue(true); case REGEX -> autolinkUseRegexProperty.setValue(true); } - autolinkRegexKeyProperty.setValue(initialAutoLinkPreferences.getRegularExpression()); + autolinkRegexKeyProperty.setValue(autoLinkPreferences.getRegularExpression()); } @Override @@ -102,14 +100,14 @@ public void storeSettings() { // Autolink preferences if (autolinkFileStartsBibtexProperty.getValue()) { - preferences.getAutoLinkPreferences().setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.START); + autoLinkPreferences.setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.START); } else if (autolinkFileExactBibtexProperty.getValue()) { - preferences.getAutoLinkPreferences().setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.EXACT); + autoLinkPreferences.setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.EXACT); } else if (autolinkUseRegexProperty.getValue()) { - preferences.getAutoLinkPreferences().setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.REGEX); + autoLinkPreferences.setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.REGEX); } - preferences.getAutoLinkPreferences().setRegularExpression(autolinkRegexKeyProperty.getValue()); + autoLinkPreferences.setRegularExpression(autolinkRegexKeyProperty.getValue()); } ValidationStatus mainFileDirValidationStatus() { diff --git a/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTab.java b/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTab.java index 997abc78d9b..03038872af2 100644 --- a/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTab.java +++ b/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTab.java @@ -44,7 +44,7 @@ public String getTabName() { } public void initialize() { - this.viewModel = new NameFormatterTabViewModel(dialogService, preferencesService); + this.viewModel = new NameFormatterTabViewModel(preferencesService.getNameFormatterPreferences()); formatterNameColumn.setSortable(true); formatterNameColumn.setReorderable(false); diff --git a/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTabViewModel.java b/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTabViewModel.java index d0463324446..3bcfb75cc5f 100644 --- a/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTabViewModel.java @@ -9,11 +9,9 @@ import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; -import org.jabref.gui.DialogService; import org.jabref.gui.preferences.PreferenceTabViewModel; import org.jabref.logic.layout.format.NameFormatterPreferences; import org.jabref.model.strings.StringUtil; -import org.jabref.preferences.PreferencesService; public class NameFormatterTabViewModel implements PreferenceTabViewModel { @@ -21,21 +19,17 @@ public class NameFormatterTabViewModel implements PreferenceTabViewModel { private final StringProperty addFormatterNameProperty = new SimpleStringProperty(); private final StringProperty addFormatterStringProperty = new SimpleStringProperty(); - private final DialogService dialogService; - private final PreferencesService preferences; - private final NameFormatterPreferences initialNameFormatterPreferences; + private final NameFormatterPreferences nameFormatterPreferences; - NameFormatterTabViewModel(DialogService dialogService, PreferencesService preferences) { - this.dialogService = dialogService; - this.preferences = preferences; - this.initialNameFormatterPreferences = preferences.getNameFormatterPreferences(); + NameFormatterTabViewModel(NameFormatterPreferences preferences) { + this.nameFormatterPreferences = preferences; } @Override public void setValues() { formatterListProperty.clear(); - List names = initialNameFormatterPreferences.getNameFormatterKey(); - List formats = initialNameFormatterPreferences.getNameFormatterValue(); + List names = nameFormatterPreferences.getNameFormatterKey(); + List formats = nameFormatterPreferences.getNameFormatterValue(); for (int i = 0; i < names.size(); i++) { if (i < formats.size()) { @@ -57,10 +51,8 @@ public void storeSettings() { formats.add(formatterListItem.getFormat()); } - NameFormatterPreferences newNameFormatterPreferences = new NameFormatterPreferences( - names, - formats); - preferences.storeNameFormatterPreferences(newNameFormatterPreferences); + nameFormatterPreferences.setNameFormatterKey(names); + nameFormatterPreferences.setNameFormatterValue(formats); } public void addFormatter() { diff --git a/src/main/java/org/jabref/gui/preferences/protectedterms/NewProtectedTermsFileDialog.java b/src/main/java/org/jabref/gui/preferences/protectedterms/NewProtectedTermsFileDialog.java index 679fc56f17a..7802e7fde1b 100644 --- a/src/main/java/org/jabref/gui/preferences/protectedterms/NewProtectedTermsFileDialog.java +++ b/src/main/java/org/jabref/gui/preferences/protectedterms/NewProtectedTermsFileDialog.java @@ -16,14 +16,14 @@ import org.jabref.logic.l10n.Localization; import org.jabref.logic.protectedterms.ProtectedTermsList; import org.jabref.logic.util.StandardFileType; -import org.jabref.preferences.PreferencesService; +import org.jabref.preferences.FilePreferences; public class NewProtectedTermsFileDialog extends BaseDialog { private final TextField newFile = new TextField(); private final DialogService dialogService; - public NewProtectedTermsFileDialog(List termsLists, DialogService dialogService, PreferencesService preferencesService) { + public NewProtectedTermsFileDialog(List termsLists, DialogService dialogService, FilePreferences filePreferences) { this.dialogService = dialogService; this.setTitle(Localization.lang("New protected terms file")); @@ -31,7 +31,7 @@ public NewProtectedTermsFileDialog(List termsLists, FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(Localization.lang("Protected terms file"), StandardFileType.TERMS) .withDefaultExtension(Localization.lang("Protected terms file"), StandardFileType.TERMS) - .withInitialDirectory(preferencesService.getWorkingDir()) + .withInitialDirectory(filePreferences.getWorkingDirectory()) .build(); Button browse = new Button(Localization.lang("Browse")); diff --git a/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java index c3cc950660c..2382ea04263 100644 --- a/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java @@ -92,7 +92,7 @@ public void addFile() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(Localization.lang("Protected terms file"), StandardFileType.TERMS) .withDefaultExtension(Localization.lang("Protected terms file"), StandardFileType.TERMS) - .withInitialDirectory(preferences.getWorkingDir()) + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()) .build(); dialogService.showFileOpenDialog(fileDialogConfiguration) @@ -121,7 +121,7 @@ public void removeList(ProtectedTermsListItemModel itemModel) { } public void createNewFile() { - dialogService.showCustomDialogAndWait(new NewProtectedTermsFileDialog(termsFilesProperty, dialogService, preferences)); + dialogService.showCustomDialogAndWait(new NewProtectedTermsFileDialog(termsFilesProperty, dialogService, preferences.getFilePreferences())); } public void edit(ProtectedTermsListItemModel file) { diff --git a/src/main/java/org/jabref/gui/preferences/table/TableTab.fxml b/src/main/java/org/jabref/gui/preferences/table/TableTab.fxml index c65b263263f..0ff264f489f 100644 --- a/src/main/java/org/jabref/gui/preferences/table/TableTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/table/TableTab.fxml @@ -17,7 +17,6 @@ xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml" fx:controller="org.jabref.gui.preferences.table.TableTab"> - @@ -88,17 +87,6 @@