diff --git a/docs/getting-into-the-code/code-howtos.md b/docs/getting-into-the-code/code-howtos.md index 84f37908c98..354f6d26364 100644 --- a/docs/getting-into-the-code/code-howtos.md +++ b/docs/getting-into-the-code/code-howtos.md @@ -211,7 +211,7 @@ Optional file = FileHelper.expandFilename(database, fileText, preferences. ## How to work with Preferences -`model` and `logic` must not know JabRefPreferences. See `ProxyPreferences` for encapsulated preferences and [https://github.com/JabRef/jabref/pull/658](https://github.com/JabRef/jabref/pull/658) for a detailed discussion. +`model` and `logic` must not know `JabRefPreferences`. See `ProxyPreferences` for encapsulated preferences and [https://github.com/JabRef/jabref/pull/658](https://github.com/JabRef/jabref/pull/658) for a detailed discussion. See [https://github.com/JabRef/jabref/blob/master/src/main/java/org/jabref/logic/preferences/TimestampPreferences.java](https://github.com/JabRef/jabref/blob/master/src/main/java/org/jabref/logic/preferences/TimestampPreferences.java) \(via [https://github.com/JabRef/jabref/pull/3092](https://github.com/JabRef/jabref/pull/3092)\) for the current way how to deal with preferences. @@ -291,9 +291,12 @@ Or even better, try to mock the preferences and insert them via dependency injec @Test public void getTypeReturnsBibLatexArticleInBibLatexMode() { // Mock preferences - JabrefPreferences mockedPrefs = mock(JabrefPreferences.class); + PreferencesService mockedPrefs = mock(PreferencesService.class); + GeneralPreferences mockedGeneralPrefs = mock(GeneralPReferences.class); // Switch to BibLatex mode - when(mockedPrefs.getBoolean("BiblatexMode")).thenReturn(true); + when(mockedPrefs.getGeneralPrefs()).thenReturn(mockedGeneralPrefs); + when(mockedGeneralPrefs.getDefaultBibDatabaseMode()) + .thenReturn(BibDatabaseMode.BIBLATEX); // Now test EntryTypes biblatexentrytypes = new EntryTypes(mockedPrefs); diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index eeee79c1366..e52c15bf966 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -456,8 +456,8 @@ private void exportFile(List loaded, String[] data) { private void importPreferences() { try { Globals.prefs.importPreferences(cli.getPreferencesImport()); - Globals.entryTypesManager.addCustomOrModifiedTypes(Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBTEX), - Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBLATEX)); + Globals.entryTypesManager.addCustomOrModifiedTypes(Globals.prefs.getBibEntryTypes(BibDatabaseMode.BIBTEX), + Globals.prefs.getBibEntryTypes(BibDatabaseMode.BIBLATEX)); List customExporters = Globals.prefs.getCustomExportFormats(Globals.journalAbbreviationRepository); LayoutFormatterPreferences layoutPreferences = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository); diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index d78183a3479..d66db4c34a7 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -33,6 +33,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.identifier.DOI; import org.jabref.model.util.OptionalUtil; +import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,15 +48,18 @@ public class ClipBoardManager { private static Clipboard clipboard; private static java.awt.datatransfer.Clipboard primary; private static ImportFormatReader importFormatReader; + private final PreferencesService preferencesService; - public ClipBoardManager() { - this(Clipboard.getSystemClipboard(), Toolkit.getDefaultToolkit().getSystemSelection(), Globals.IMPORT_FORMAT_READER); + public ClipBoardManager(PreferencesService preferencesService) { + this(Clipboard.getSystemClipboard(), Toolkit.getDefaultToolkit().getSystemSelection(), Globals.IMPORT_FORMAT_READER, preferencesService); } - public ClipBoardManager(Clipboard clipboard, java.awt.datatransfer.Clipboard primary, ImportFormatReader importFormatReader) { + public ClipBoardManager(Clipboard clipboard, java.awt.datatransfer.Clipboard primary, ImportFormatReader importFormatReader, PreferencesService preferencesService) { ClipBoardManager.clipboard = clipboard; ClipBoardManager.primary = primary; ClipBoardManager.importFormatReader = importFormatReader; + + this.preferencesService = preferencesService; } /** @@ -154,7 +158,7 @@ public void setContent(String string) { public void setContent(List entries) throws IOException { final ClipboardContent content = new ClipboardContent(); - BibEntryWriter writer = new BibEntryWriter(new FieldWriter(Globals.prefs.getFieldWriterPreferences()), Globals.entryTypesManager); + BibEntryWriter writer = new BibEntryWriter(new FieldWriter(preferencesService.getFieldWriterPreferences()), Globals.entryTypesManager); String serializedEntries = writer.serializeAll(entries, BibDatabaseMode.BIBTEX); content.put(DragAndDropDataFormats.ENTRIES, serializedEntries); content.putString(serializedEntries); @@ -172,7 +176,7 @@ public List extractData() { } private List handleBibTeXData(String entries) { - BibtexParser parser = new BibtexParser(Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor()); + BibtexParser parser = new BibtexParser(preferencesService.getImportFormatPreferences(), Globals.getFileUpdateMonitor()); try { return parser.parseEntries(new ByteArrayInputStream(entries.getBytes(StandardCharsets.UTF_8))); } catch (ParseException ex) { @@ -206,7 +210,7 @@ private List tryImportFormats(String data) { private List fetchByDOI(DOI doi) { LOGGER.info("Found DOI in clipboard"); try { - Optional entry = new DoiFetcher(Globals.prefs.getImportFormatPreferences()).performSearchById(doi.getDOI()); + Optional entry = new DoiFetcher(preferencesService.getImportFormatPreferences()).performSearchById(doi.getDOI()); return OptionalUtil.toList(entry); } catch (FetcherException ex) { LOGGER.error("Error while fetching", ex); diff --git a/src/main/java/org/jabref/gui/EntryTypeView.java b/src/main/java/org/jabref/gui/EntryTypeView.java index 83d7baa191c..944d2d94ad9 100644 --- a/src/main/java/org/jabref/gui/EntryTypeView.java +++ b/src/main/java/org/jabref/gui/EntryTypeView.java @@ -34,7 +34,7 @@ import org.jabref.model.entry.types.IEEETranEntryTypeDefinitions; import org.jabref.model.entry.types.StandardEntryType; import org.jabref.model.strings.StringUtil; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; import com.tobiasdiez.easybind.EasyBind; @@ -63,16 +63,16 @@ public class EntryTypeView extends BaseDialog { private final LibraryTab libraryTab; private final DialogService dialogService; - private final JabRefPreferences prefs; + private final PreferencesService preferencesService; private EntryType type; private EntryTypeViewModel viewModel; private final ControlsFxVisualizer visualizer = new ControlsFxVisualizer(); - public EntryTypeView(LibraryTab libraryTab, DialogService dialogService, JabRefPreferences preferences) { + public EntryTypeView(LibraryTab libraryTab, DialogService dialogService, PreferencesService preferences) { this.libraryTab = libraryTab; this.dialogService = dialogService; - this.prefs = preferences; + this.preferencesService = preferences; this.setTitle(Localization.lang("Select entry type")); ViewLoader.view(this) @@ -121,7 +121,7 @@ private void addEntriesToPane(FlowPane pane, Collection @FXML public void initialize() { visualizer.setDecoration(new IconValidationDecorator()); - viewModel = new EntryTypeViewModel(prefs, libraryTab, dialogService, stateManager); + viewModel = new EntryTypeViewModel(preferencesService, libraryTab, dialogService, stateManager); idBasedFetchers.itemsProperty().bind(viewModel.fetcherItemsProperty()); idTextField.textProperty().bindBidirectional(viewModel.idTextProperty()); diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index 21f60791931..4ca06d9736a 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -25,7 +25,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.model.strings.StringUtil; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; import de.saxsys.mvvmfx.utils.validation.ValidationMessage; @@ -38,7 +38,7 @@ public class EntryTypeViewModel { private static final Logger LOGGER = LoggerFactory.getLogger(EntryTypeViewModel.class); - private final JabRefPreferences prefs; + private final PreferencesService preferencesService; private final BooleanProperty searchingProperty = new SimpleBooleanProperty(); private final BooleanProperty searchSuccesfulProperty = new SimpleBooleanProperty(); private final ObjectProperty selectedItemProperty = new SimpleObjectProperty<>(); @@ -51,9 +51,12 @@ public class EntryTypeViewModel { private final Validator idFieldValidator; private final StateManager stateManager; - public EntryTypeViewModel(JabRefPreferences preferences, LibraryTab libraryTab, DialogService dialogService, StateManager stateManager) { + public EntryTypeViewModel(PreferencesService preferences, + LibraryTab libraryTab, + DialogService dialogService, + StateManager stateManager) { this.libraryTab = libraryTab; - this.prefs = preferences; + this.preferencesService = preferences; this.dialogService = dialogService; this.stateManager = stateManager; fetchers.addAll(WebFetchers.getIdBasedFetchers(preferences.getImportFormatPreferences())); @@ -86,12 +89,12 @@ public BooleanProperty getFocusAndSelectAllProperty() { } public void storeSelectedFetcher() { - prefs.setIdBasedFetcherForEntryGenerator(selectedItemProperty.getValue().getName()); + preferencesService.storeIdBasedFetcherForEntryGenerator(selectedItemProperty.getValue().getName()); } private IdBasedFetcher getLastSelectedFetcher() { - return fetchers.stream().filter(fetcher -> fetcher.getName().equals(prefs.getIdBasedFetcherForEntryGenerator())) - .findFirst().orElse(new DoiFetcher(prefs.getImportFormatPreferences())); + return fetchers.stream().filter(fetcher -> fetcher.getName().equals(preferencesService.getIdBasedFetcherForEntryGenerator())) + .findFirst().orElse(new DoiFetcher(preferencesService.getImportFormatPreferences())); } public ListProperty fetcherItemsProperty() { @@ -170,7 +173,7 @@ public void runFetcherWorker() { } } else { // Regenerate CiteKey of imported BibEntry - new CitationKeyGenerator(libraryTab.getBibDatabaseContext(), prefs.getCitationKeyPatternPreferences()).generateAndSetKey(entry); + new CitationKeyGenerator(libraryTab.getBibDatabaseContext(), preferencesService.getCitationKeyPatternPreferences()).generateAndSetKey(entry); libraryTab.insertEntry(entry); } searchSuccesfulProperty.set(true); diff --git a/src/main/java/org/jabref/gui/Globals.java b/src/main/java/org/jabref/gui/Globals.java index db851799580..19e0ded1798 100644 --- a/src/main/java/org/jabref/gui/Globals.java +++ b/src/main/java/org/jabref/gui/Globals.java @@ -73,7 +73,7 @@ public class Globals { public static ExporterFactory exportFactory; public static CountingUndoManager undoManager = new CountingUndoManager(); public static BibEntryTypesManager entryTypesManager = new BibEntryTypesManager(); - public static ClipBoardManager clipboardManager = new ClipBoardManager(); + public static ClipBoardManager clipboardManager = new ClipBoardManager(prefs); // Key binding preferences private static KeyBindingRepository keyBindingRepository; @@ -97,7 +97,7 @@ public static void startBackgroundTasks() { Globals.fileUpdateMonitor = new DefaultFileUpdateMonitor(); JabRefExecutorService.INSTANCE.executeInterruptableTask(Globals.fileUpdateMonitor, "FileUpdateMonitor"); - if (Globals.prefs.shouldCollectTelemetry() && !GraphicsEnvironment.isHeadless()) { + if (Globals.prefs.getTelemetryPreferences().shouldCollectTelemetry() && !GraphicsEnvironment.isHeadless()) { startTelemetryClient(); } } @@ -112,7 +112,7 @@ private static void stopTelemetryClient() { private static void startTelemetryClient() { TelemetryConfiguration telemetryConfiguration = TelemetryConfiguration.getActive(); telemetryConfiguration.setInstrumentationKey(Globals.BUILD_INFO.azureInstrumentationKey); - telemetryConfiguration.setTrackingIsDisabled(!Globals.prefs.shouldCollectTelemetry()); + telemetryConfiguration.setTrackingIsDisabled(!Globals.prefs.getTelemetryPreferences().shouldCollectTelemetry()); telemetryClient = new TelemetryClient(telemetryConfiguration); telemetryClient.getContext().getProperties().put("JabRef version", Globals.BUILD_INFO.version.toString()); telemetryClient.getContext().getProperties().put("Java version", StandardSystemProperty.JAVA_VERSION.value()); diff --git a/src/main/java/org/jabref/gui/JabRefDialogService.java b/src/main/java/org/jabref/gui/JabRefDialogService.java index 292486b146a..53816e402e8 100644 --- a/src/main/java/org/jabref/gui/JabRefDialogService.java +++ b/src/main/java/org/jabref/gui/JabRefDialogService.java @@ -40,7 +40,7 @@ import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.ZipFileChooser; import org.jabref.logic.l10n.Localization; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.jfoenix.controls.JFXSnackbar; import com.jfoenix.controls.JFXSnackbar.SnackbarEvent; @@ -67,12 +67,12 @@ public class JabRefDialogService implements DialogService { private static final Duration TOAST_MESSAGE_DISPLAY_TIME = Duration.millis(3000); private static final Logger LOGGER = LoggerFactory.getLogger(JabRefDialogService.class); - private static JabRefPreferences preferences; + private static PreferencesService preferences; private final Window mainWindow; private final JFXSnackbar statusLine; - public JabRefDialogService(Window mainWindow, Pane mainPane, JabRefPreferences preferences) { + public JabRefDialogService(Window mainWindow, Pane mainPane, PreferencesService preferences) { this.mainWindow = mainWindow; this.statusLine = new JFXSnackbar(mainPane); JabRefDialogService.preferences = preferences; diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 39e890d86f3..e751db5784a 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -120,6 +120,7 @@ import org.jabref.gui.undo.UndoRedoAction; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.DefaultTaskExecutor; +import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.autosaveandbackup.AutosaveManager; import org.jabref.logic.autosaveandbackup.BackupManager; import org.jabref.logic.citationstyle.CitationStyleOutputFormat; @@ -136,8 +137,8 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.field.SpecialField; import org.jabref.model.entry.types.StandardEntryType; -import org.jabref.preferences.JabRefPreferences; -import org.jabref.preferences.LastFocusedTabPreferences; +import org.jabref.preferences.PreferencesService; +import org.jabref.preferences.TelemetryPreferences; import com.google.common.eventbus.Subscribe; import com.tobiasdiez.easybind.EasyBind; @@ -158,7 +159,7 @@ public class JabRefFrame extends BorderPane { private static final Logger LOGGER = LoggerFactory.getLogger(JabRefFrame.class); private final SplitPane splitPane = new SplitPane(); - private final JabRefPreferences prefs = Globals.prefs; + private final PreferencesService prefs = Globals.prefs; private final GlobalSearchBar globalSearchBar = new GlobalSearchBar(this, Globals.stateManager, prefs); private final FileHistoryMenu fileHistory; @@ -175,6 +176,8 @@ public class JabRefFrame extends BorderPane { private SidePane sidePane; private PopOver progressViewPopOver; + private final TaskExecutor taskExecutor; + public JabRefFrame(Stage mainStage) { this.mainStage = mainStage; this.dialogService = new JabRefDialogService(mainStage, this, prefs); @@ -182,6 +185,7 @@ public JabRefFrame(Stage mainStage) { this.pushToApplicationsManager = new PushToApplicationsManager(dialogService, stateManager, prefs); this.undoManager = Globals.undoManager; this.fileHistory = new FileHistoryMenu(prefs, dialogService, getOpenDatabaseAction()); + this.taskExecutor = Globals.TASK_EXECUTOR; this.setOnKeyTyped(key -> { if (this.fileHistory.isShowing()) { if (this.fileHistory.openFileByKey(key)) { @@ -287,7 +291,7 @@ private void initKeyBindings() { } private void initShowTrackingNotification() { - if (!Globals.prefs.shouldAskToCollectTelemetry()) { + if (Globals.prefs.getTelemetryPreferences().shouldAskToCollectTelemetry()) { JabRefExecutorService.INSTANCE.submit(new TimerTask() { @Override @@ -298,19 +302,20 @@ public void run() { } } - private Void showTrackingNotification() { - if (!Globals.prefs.shouldCollectTelemetry()) { - boolean shouldCollect = dialogService.showConfirmationDialogAndWait( + private void showTrackingNotification() { + TelemetryPreferences telemetryPreferences = Globals.prefs.getTelemetryPreferences(); + boolean shouldCollect = telemetryPreferences.shouldCollectTelemetry(); + + if (!telemetryPreferences.shouldCollectTelemetry()) { + shouldCollect = dialogService.showConfirmationDialogAndWait( Localization.lang("Telemetry: Help make JabRef better"), Localization.lang("To improve the user experience, we would like to collect anonymous statistics on the features you use. We will only record what features you access and how often you do it. We will neither collect any personal data nor the content of bibliographic items. If you choose to allow data collection, you can later disable it via Options -> Preferences -> General."), Localization.lang("Share anonymous statistics"), Localization.lang("Don't share")); - Globals.prefs.setShouldCollectTelemetry(shouldCollect); } - Globals.prefs.askedToCollectTelemetry(); - - return null; + Globals.prefs.storeTelemetryPreferences(telemetryPreferences.withCollectTelemetry(shouldCollect) + .withAskToCollectTelemetry(false)); } /** @@ -329,10 +334,6 @@ public void about() { HelpAction.getMainHelpPageCommand().execute(); } - public JabRefPreferences prefs() { - return prefs; - } - /** * Tears down all things started by JabRef *

@@ -342,18 +343,18 @@ public JabRefPreferences prefs() { * set to true */ private void tearDownJabRef(List filenames) { - // prefs.putBoolean(JabRefPreferences.WINDOW_MAXIMISED, getExtendedState() == Frame.MAXIMIZED_BOTH); - - if (prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED)) { - // Here we store the names of all current files. If - // there is no current file, we remove any + if (prefs.getGuiPreferences().shouldOpenLastEdited()) { + // Here we store the names of all current files. If there is no current file, we remove any // previously stored filename. if (filenames.isEmpty()) { - prefs.remove(JabRefPreferences.LAST_EDITED); + prefs.clearEditedFiles(); } else { - prefs.putStringList(JabRefPreferences.LAST_EDITED, filenames); - Path focusedDatabase = getCurrentLibraryTab().getBibDatabaseContext().getDatabasePath().orElse(null); - new LastFocusedTabPreferences(prefs).setLastFocusedTab(focusedDatabase); + Path focusedDatabase = getCurrentLibraryTab().getBibDatabaseContext() + .getDatabasePath() + .orElse(null); + prefs.storeGuiPreferences(prefs.getGuiPreferences() + .withLastFilesOpened(filenames) + .withLastFocusedFile(focusedDatabase)); } } @@ -458,10 +459,11 @@ public void changed(ObservableValue observable, Boolean oldVa } private void setDividerPosition() { - splitPane.setDividerPositions(prefs.getDouble(JabRefPreferences.SIDE_PANE_WIDTH)); + splitPane.setDividerPositions(prefs.getGuiPreferences().getSidePaneWidth()); if (!splitPane.getDividers().isEmpty()) { EasyBind.subscribe(splitPane.getDividers().get(0).positionProperty(), - position -> prefs.putDouble(JabRefPreferences.SIDE_PANE_WIDTH, position.doubleValue())); + position -> prefs.storeGuiPreferences(prefs.getGuiPreferences() + .withSidePaneWidth(position.doubleValue()))); } } @@ -479,7 +481,7 @@ private Node createToolbar() { new HBox( factory.createIconButton(StandardActions.NEW_LIBRARY, new NewDatabaseAction(this, prefs)), - factory.createIconButton(StandardActions.OPEN_LIBRARY, new OpenDatabaseAction(this)), + factory.createIconButton(StandardActions.OPEN_LIBRARY, new OpenDatabaseAction(this, prefs, dialogService)), factory.createIconButton(StandardActions.SAVE_LIBRARY, new SaveAction(SaveAction.SaveMethod.SAVE, this, stateManager))), leftSpacer, @@ -489,8 +491,8 @@ private Node createToolbar() { rightSpacer, new HBox( - factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(this, StandardEntryType.Article, dialogService, Globals.prefs, stateManager)), - factory.createIconButton(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, Globals.prefs, stateManager)), + factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(this, StandardEntryType.Article, dialogService, prefs, stateManager)), + factory.createIconButton(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, prefs, stateManager)), factory.createIconButton(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(stateManager)), factory.createIconButton(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, this, stateManager)) ), @@ -566,7 +568,7 @@ public void showLibraryTab(LibraryTab libraryTab) { } public void init() { - sidePaneManager = new SidePaneManager(Globals.prefs, this); + sidePaneManager = new SidePaneManager(prefs, this, dialogService, stateManager); sidePane = sidePaneManager.getPane(); tabbedPane = new TabPane(); @@ -683,12 +685,12 @@ private MenuBar createMenu() { new SeparatorMenuItem(), factory.createSubMenu(StandardActions.IMPORT, - factory.createMenuItem(StandardActions.IMPORT_INTO_CURRENT_LIBRARY, new ImportCommand(this, false, stateManager)), - factory.createMenuItem(StandardActions.IMPORT_INTO_NEW_LIBRARY, new ImportCommand(this, true, stateManager))), + factory.createMenuItem(StandardActions.IMPORT_INTO_CURRENT_LIBRARY, new ImportCommand(this, false, prefs, stateManager)), + factory.createMenuItem(StandardActions.IMPORT_INTO_NEW_LIBRARY, new ImportCommand(this, true, prefs, stateManager))), factory.createSubMenu(StandardActions.EXPORT, - factory.createMenuItem(StandardActions.EXPORT_ALL, new ExportCommand(this, false, Globals.prefs)), - factory.createMenuItem(StandardActions.EXPORT_SELECTED, new ExportCommand(this, true, Globals.prefs)), + factory.createMenuItem(StandardActions.EXPORT_ALL, new ExportCommand(this, false, prefs)), + factory.createMenuItem(StandardActions.EXPORT_SELECTED, new ExportCommand(this, true, prefs)), factory.createMenuItem(StandardActions.SAVE_SELECTED_AS_PLAIN_BIBTEX, new SaveAction(SaveAction.SaveMethod.SAVE_SELECTED, this, stateManager))), new SeparatorMenuItem(), @@ -735,7 +737,7 @@ private MenuBar createMenu() { factory.createMenuItem(StandardActions.MASS_SET_FIELDS, new MassSetFieldsAction(stateManager, dialogService, undoManager)) ); - if (Globals.prefs.getSpecialFieldsPreferences().isSpecialFieldsEnabled()) { + if (prefs.getSpecialFieldsPreferences().isSpecialFieldsEnabled()) { edit.getItems().addAll( new SeparatorMenuItem(), // ToDo: SpecialField needs the active BasePanel to mark it as changed. @@ -784,7 +786,7 @@ private MenuBar createMenu() { ); Menu lookupIdentifiers = factory.createSubMenu(StandardActions.LOOKUP_DOC_IDENTIFIER); - for (IdFetcher fetcher : WebFetchers.getIdFetchers(Globals.prefs.getImportFormatPreferences())) { + for (IdFetcher fetcher : WebFetchers.getIdFetchers(prefs.getImportFormatPreferences())) { LookupIdentifierAction identifierAction = new LookupIdentifierAction<>(this, fetcher, stateManager, undoManager); lookupIdentifiers.getItems().add(factory.createMenuItem(identifierAction.getAction(), identifierAction)); } @@ -795,7 +797,7 @@ private MenuBar createMenu() { new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.FIND_UNLINKED_FILES, new FindUnlinkedFilesAction(this, stateManager)) + factory.createMenuItem(StandardActions.FIND_UNLINKED_FILES, new FindUnlinkedFilesAction(dialogService, prefs, undoManager, stateManager)) ); // PushToApplication @@ -814,11 +816,14 @@ private MenuBar createMenu() { new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.SEND_AS_EMAIL, new SendAsEMailAction(dialogService, stateManager)), - pushToApplicationMenuItem); - // Disabled until PR #7126 can be merged - // new SeparatorMenuItem(), - // factory.createMenuItem(StandardActions.START_SYSTEMATIC_LITERATURE_REVIEW, new StartLiteratureReviewAction(this, Globals.getFileUpdateMonitor(), Globals.prefs.getWorkingDir(), Globals.TASK_EXECUTOR) + factory.createMenuItem(StandardActions.SEND_AS_EMAIL, new SendAsEMailAction(dialogService, prefs, stateManager)), + pushToApplicationMenuItem + // Disabled until PR #7126 can be merged + // new SeparatorMenuItem(), + // factory.createMenuItem(StandardActions.START_SYSTEMATIC_LITERATURE_REVIEW, + // new StartLiteratureReviewAction(this, Globals.getFileUpdateMonitor(), prefs.getWorkingDir(), + // taskExecutor, prefs, prefs.getImportFormatPreferences(), prefs.getSavePreferences())) + ); SidePaneComponent webSearch = sidePaneManager.getComponent(SidePaneType.WEB_SEARCH); SidePaneComponent groups = sidePaneManager.getComponent(SidePaneType.GROUPS); @@ -1067,7 +1072,7 @@ public LibraryTab addTab(BibDatabaseContext databaseContext, boolean raisePanel) private boolean readyForAutosave(BibDatabaseContext context) { return ((context.getLocation() == DatabaseLocation.SHARED) || - ((context.getLocation() == DatabaseLocation.LOCAL) && Globals.prefs.getBoolean(JabRefPreferences.LOCAL_AUTO_SAVE))) + ((context.getLocation() == DatabaseLocation.LOCAL) && Globals.prefs.shouldAutosave())) && context.getDatabasePath().isPresent(); } @@ -1115,7 +1120,7 @@ private boolean confirmClose(LibraryTab libraryTab) { if (response.isPresent() && response.get().equals(saveChanges)) { // The user wants to save. try { - SaveDatabaseAction saveAction = new SaveDatabaseAction(libraryTab, Globals.prefs, Globals.entryTypesManager); + SaveDatabaseAction saveAction = new SaveDatabaseAction(libraryTab, prefs, Globals.entryTypesManager); if (saveAction.save()) { return true; } @@ -1169,7 +1174,7 @@ public void closeCurrentTab() { } public OpenDatabaseAction getOpenDatabaseAction() { - return new OpenDatabaseAction(this); + return new OpenDatabaseAction(this, prefs, dialogService); } public SidePaneManager getSidePaneManager() { diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index 0acd1ad01cb..ed62b405ad5 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -26,7 +26,7 @@ import org.jabref.logic.shared.DatabaseNotSupportedException; import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; import org.jabref.logic.shared.exception.NotASharedDatabaseException; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.GuiPreferences; import impl.org.controlsfx.skin.DecorationPane; import org.slf4j.Logger; @@ -62,8 +62,9 @@ private void openWindow(Stage mainStage) { LOGGER.debug("Initializing frame"); mainFrame.init(); + GuiPreferences guiPreferences = Globals.prefs.getGuiPreferences(); // Restore window location and/or maximised state - if (Globals.prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) { + if (guiPreferences.isWindowMaximised()) { mainStage.setMaximized(true); } else if ((Screen.getScreens().size() == 1) && isWindowPositionOutOfBounds()) { // corrects the Window, if its outside of the mainscreen @@ -74,10 +75,10 @@ private void openWindow(Stage mainStage) { mainStage.setHeight(768); correctedWindowPos = true; } else { - mainStage.setX(Globals.prefs.getDouble(JabRefPreferences.POS_X)); - mainStage.setY(Globals.prefs.getDouble(JabRefPreferences.POS_Y)); - mainStage.setWidth(Globals.prefs.getDouble(JabRefPreferences.SIZE_X)); - mainStage.setHeight(Globals.prefs.getDouble(JabRefPreferences.SIZE_Y)); + mainStage.setX(guiPreferences.getPositionX()); + mainStage.setY(guiPreferences.getPositionY()); + mainStage.setWidth(guiPreferences.getSizeX()); + mainStage.setHeight(guiPreferences.getSizeY()); } debugLogWindowState(mainStage); @@ -120,7 +121,7 @@ private void openWindow(Stage mainStage) { private void openDatabases() { // If the option is enabled, open the last edited libraries, if any. - if (!isBlank && Globals.prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED)) { + if (!isBlank && Globals.prefs.getGuiPreferences().shouldOpenLastEdited()) { openLastEditedDatabases(); } @@ -136,7 +137,10 @@ private void openDatabases() { .findFirst() .flatMap(ParserResult::getFile) .map(File::getAbsolutePath) - .orElse(Globals.prefs.get(JabRefPreferences.LAST_FOCUSED)); + .orElse(Globals.prefs.getGuiPreferences() + .getLastFocusedFile() + .toAbsolutePath() + .toString()); // Add all bibDatabases databases to the frame: boolean first = false; @@ -210,11 +214,17 @@ private void openDatabases() { } private void saveWindowState(Stage mainStage) { - Globals.prefs.putBoolean(JabRefPreferences.WINDOW_MAXIMISED, mainStage.isMaximized()); - Globals.prefs.putDouble(JabRefPreferences.POS_X, mainStage.getX()); - Globals.prefs.putDouble(JabRefPreferences.POS_Y, mainStage.getY()); - Globals.prefs.putDouble(JabRefPreferences.SIZE_X, mainStage.getWidth()); - Globals.prefs.putDouble(JabRefPreferences.SIZE_Y, mainStage.getHeight()); + GuiPreferences preferences = Globals.prefs.getGuiPreferences(); + Globals.prefs.storeGuiPreferences(new GuiPreferences( + mainStage.getX(), + mainStage.getY(), + mainStage.getWidth(), + mainStage.getHeight(), + mainStage.isMaximized(), + preferences.shouldOpenLastEdited(), + preferences.getLastFilesOpened(), + preferences.getLastFocusedFile(), + preferences.getSidePaneWidth())); debugLogWindowState(mainStage); } @@ -241,14 +251,16 @@ private void debugLogWindowState(Stage mainStage) { * @return outbounds */ private boolean isWindowPositionOutOfBounds() { - return !Screen.getPrimary().getBounds().contains(Globals.prefs.getDouble(JabRefPreferences.POS_X), Globals.prefs.getDouble(JabRefPreferences.POS_Y)); + return !Screen.getPrimary().getBounds().contains( + Globals.prefs.getGuiPreferences().getPositionX(), + Globals.prefs.getGuiPreferences().getPositionY()); } private void openLastEditedDatabases() { - if (Globals.prefs.get(JabRefPreferences.LAST_EDITED) == null) { + List lastFiles = Globals.prefs.getGuiPreferences().getLastFilesOpened(); + if (lastFiles.isEmpty()) { return; } - List lastFiles = Globals.prefs.getStringList(JabRefPreferences.LAST_EDITED); for (String fileName : lastFiles) { File dbFile = new File(fileName); diff --git a/src/main/java/org/jabref/gui/JabRefMain.java b/src/main/java/org/jabref/gui/JabRefMain.java index 826c561587f..0afc8d7f720 100644 --- a/src/main/java/org/jabref/gui/JabRefMain.java +++ b/src/main/java/org/jabref/gui/JabRefMain.java @@ -25,6 +25,7 @@ import org.jabref.migrations.PreferencesMigrations; import org.jabref.model.database.BibDatabaseMode; import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import org.apache.commons.cli.ParseException; import org.slf4j.Logger; @@ -159,27 +160,27 @@ private static boolean handleMultipleAppInstances(String[] args) { return true; } - private static void applyPreferences(JabRefPreferences preferences) { + private static void applyPreferences(PreferencesService preferences) { // Read list(s) of journal names and abbreviations - Globals.journalAbbreviationRepository = JournalAbbreviationLoader.loadRepository(Globals.prefs.getJournalAbbreviationPreferences()); + Globals.journalAbbreviationRepository = JournalAbbreviationLoader.loadRepository(preferences.getJournalAbbreviationPreferences()); // Build list of Import and Export formats - Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(), - Globals.prefs.getXmpPreferences(), Globals.getFileUpdateMonitor()); - Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.loadBibEntryTypes(BibDatabaseMode.BIBTEX), - preferences.loadBibEntryTypes(BibDatabaseMode.BIBLATEX)); + Globals.IMPORT_FORMAT_READER.resetImportFormats(preferences.getImportFormatPreferences(), + preferences.getXmpPreferences(), Globals.getFileUpdateMonitor()); + Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.getBibEntryTypes(BibDatabaseMode.BIBTEX), + preferences.getBibEntryTypes(BibDatabaseMode.BIBLATEX)); Globals.exportFactory = ExporterFactory.create( - Globals.prefs.getCustomExportFormats(Globals.journalAbbreviationRepository), - Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository), - Globals.prefs.getSavePreferencesForExport(), - Globals.prefs.getXmpPreferences()); + preferences.getCustomExportFormats(Globals.journalAbbreviationRepository), + preferences.getLayoutFormatterPreferences(Globals.journalAbbreviationRepository), + preferences.getSavePreferencesForExport(), + preferences.getXmpPreferences()); // Initialize protected terms loader - Globals.protectedTermsLoader = new ProtectedTermsLoader(Globals.prefs.getProtectedTermsPreferences()); + Globals.protectedTermsLoader = new ProtectedTermsLoader(preferences.getProtectedTermsPreferences()); // Override used newline character with the one stored in the preferences // The preferences return the system newline character sequence as default - OS.NEWLINE = Globals.prefs.get(JabRefPreferences.NEWLINE); + OS.NEWLINE = preferences.getNewLineSeparator().toString(); } private static void configureProxy(ProxyPreferences proxyPreferences) { diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index 5d50d770f9a..eb2706ad36c 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -238,7 +238,7 @@ public void feedData(BibDatabaseContext bibDatabaseContext) { private boolean isDatabaseReadyForAutoSave(BibDatabaseContext context) { return ((context.getLocation() == DatabaseLocation.SHARED) || - ((context.getLocation() == DatabaseLocation.LOCAL) && preferencesService.getShouldAutosave())) + ((context.getLocation() == DatabaseLocation.LOCAL) && preferencesService.shouldAutosave())) && context.getDatabasePath().isPresent(); } @@ -252,7 +252,7 @@ private boolean isDatabaseReadyForAutoSave(BibDatabaseContext context) { * Example: *jabref-authors.bib – testbib */ public void updateTabTitle(boolean isChanged) { - boolean isAutosaveEnabled = preferencesService.getShouldAutosave(); + boolean isAutosaveEnabled = preferencesService.shouldAutosave(); DatabaseLocation databaseLocation = bibDatabaseContext.getLocation(); Optional file = bibDatabaseContext.getDatabasePath(); @@ -755,7 +755,7 @@ public FileAnnotationCache getAnnotationCache() { public void resetChangeMonitorAndChangePane() { changeMonitor.ifPresent(DatabaseChangeMonitor::unregister); - changeMonitor = Optional.of(new DatabaseChangeMonitor(bibDatabaseContext, Globals.getFileUpdateMonitor(), Globals.TASK_EXECUTOR)); + changeMonitor = Optional.of(new DatabaseChangeMonitor(bibDatabaseContext, Globals.getFileUpdateMonitor(), Globals.TASK_EXECUTOR, preferencesService)); changePane = new DatabaseChangePane(splitPane, bibDatabaseContext, changeMonitor.get()); @@ -849,11 +849,11 @@ public void listen(EntriesRemovedEvent removedEntriesEvent) { } public static class Factory { - public LibraryTab createLibraryTab(JabRefFrame frame, Path file, BackgroundTask dataLoadingTask) { + public LibraryTab createLibraryTab(JabRefFrame frame, PreferencesService preferencesService, Path file, BackgroundTask dataLoadingTask) { BibDatabaseContext context = new BibDatabaseContext(); context.setDatabasePath(file); - LibraryTab newTab = new LibraryTab(frame, frame.prefs(), context, ExternalFileTypes.getInstance()); + LibraryTab newTab = new LibraryTab(frame, preferencesService, context, ExternalFileTypes.getInstance()); newTab.setDataLoadingTask(dataLoadingTask); dataLoadingTask.onRunning(newTab::onDatabaseLoadingStarted) diff --git a/src/main/java/org/jabref/gui/SendAsEMailAction.java b/src/main/java/org/jabref/gui/SendAsEMailAction.java index c54dc6fa60e..373d8f7e6f6 100644 --- a/src/main/java/org/jabref/gui/SendAsEMailAction.java +++ b/src/main/java/org/jabref/gui/SendAsEMailAction.java @@ -19,7 +19,7 @@ import org.jabref.logic.util.io.FileUtil; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,11 +38,13 @@ public class SendAsEMailAction extends SimpleCommand { private static final Logger LOGGER = LoggerFactory.getLogger(SendAsEMailAction.class); - private DialogService dialogService; - private StateManager stateManager; + private final DialogService dialogService; + private final PreferencesService preferencesService; + private final StateManager stateManager; - public SendAsEMailAction(DialogService dialogService, StateManager stateManager) { + public SendAsEMailAction(DialogService dialogService, PreferencesService preferencesService, StateManager stateManager) { this.dialogService = dialogService; + this.preferencesService = preferencesService; this.stateManager = stateManager; this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); @@ -74,7 +76,7 @@ private String sendEmail() throws Exception { List entries = stateManager.getSelectedEntries(); // write the entries using sw, which is used later to form the email content - BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new FieldWriter(Globals.prefs.getFieldWriterPreferences()), Globals.entryTypesManager); + BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new FieldWriter(preferencesService.getFieldWriterPreferences()), Globals.entryTypesManager); for (BibEntry entry : entries) { try { @@ -88,9 +90,9 @@ private String sendEmail() throws Exception { // open folders is needed to indirectly support email programs, which cannot handle // the unofficial "mailto:attachment" property - boolean openFolders = JabRefPreferences.getInstance().getBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES); + boolean openFolders = preferencesService.getExternalApplicationsPreferences().shouldAutoOpenEmailAttachmentsFolder(); - List fileList = FileUtil.getListOfLinkedFiles(entries, databaseContext.getFileDirectories(Globals.prefs.getFilePreferences())); + List fileList = FileUtil.getListOfLinkedFiles(entries, databaseContext.getFileDirectories(preferencesService.getFilePreferences())); for (Path path : fileList) { attachments.add(path.toAbsolutePath().toString()); if (openFolders) { @@ -104,7 +106,7 @@ private String sendEmail() throws Exception { String mailTo = "?Body=".concat(rawEntries.getBuffer().toString()); mailTo = mailTo.concat("&Subject="); - mailTo = mailTo.concat(JabRefPreferences.getInstance().get(JabRefPreferences.EMAIL_SUBJECT)); + mailTo = mailTo.concat(preferencesService.getExternalApplicationsPreferences().getEmailSubject()); for (String path : attachments) { mailTo = mailTo.concat("&Attachment=\"").concat(path); mailTo = mailTo.concat("\""); diff --git a/src/main/java/org/jabref/gui/SidePaneManager.java b/src/main/java/org/jabref/gui/SidePaneManager.java index 472589044e3..f87c948b57c 100644 --- a/src/main/java/org/jabref/gui/SidePaneManager.java +++ b/src/main/java/org/jabref/gui/SidePaneManager.java @@ -11,7 +11,7 @@ import org.jabref.gui.importer.fetcher.WebSearchPane; import org.jabref.gui.openoffice.OpenOfficeSidePanel; import org.jabref.logic.openoffice.OpenOfficePreferences; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; /** * Manages which {@link SidePaneComponent}s are shown. @@ -21,20 +21,20 @@ public class SidePaneManager { private final SidePane sidePane; private final Map components = new LinkedHashMap<>(); private final List visibleComponents = new LinkedList<>(); - private final JabRefPreferences preferences; + private final PreferencesService preferencesService; - public SidePaneManager(JabRefPreferences preferences, JabRefFrame frame) { - this.preferences = preferences; + public SidePaneManager(PreferencesService preferencesService, JabRefFrame frame, DialogService dialogService, StateManager stateManager) { + this.preferencesService = preferencesService; this.sidePane = new SidePane(); - OpenOfficePreferences openOfficePreferences = preferences.getOpenOfficePreferences(); + OpenOfficePreferences openOfficePreferences = preferencesService.getOpenOfficePreferences(); Stream.of( - new GroupSidePane(this, preferences, frame.getDialogService()), - new WebSearchPane(this, preferences, frame), - new OpenOfficeSidePanel(this, preferences, frame)) + new GroupSidePane(this, preferencesService, dialogService), + new WebSearchPane(this, preferencesService, dialogService, stateManager), + new OpenOfficeSidePanel(this, preferencesService, frame)) .forEach(pane -> components.put(pane.getType(), pane)); - if (preferences.getBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE)) { + if (preferencesService.getSidePanePreferences().isGroupsPaneVisible()) { show(SidePaneType.GROUPS); } @@ -42,7 +42,7 @@ public SidePaneManager(JabRefPreferences preferences, JabRefFrame frame) { show(SidePaneType.OPEN_OFFICE); } - if (preferences.getBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE)) { + if (preferencesService.getSidePanePreferences().isWebSearchPaneVisible()) { show(SidePaneType.WEB_SEARCH); } @@ -87,7 +87,7 @@ public void show(SidePaneType type) { visibleComponents.add(component); // Sort the visible components by their preferred position - visibleComponents.sort(new PreferredIndexSort()); + visibleComponents.sort(new PreferredIndexSort(preferencesService)); updateView(); @@ -114,7 +114,7 @@ public void hide(SidePaneType type) { * so that we show components at the preferred position next time. */ private void updatePreferredPositions() { - Map preferredPositions = preferences.getSidePanePreferredPositions(); + Map preferredPositions = preferencesService.getSidePanePreferences().getPreferredPositions(); // Use the currently shown positions of all visible components int index = 0; @@ -122,7 +122,7 @@ private void updatePreferredPositions() { preferredPositions.put(comp.getType(), index); index++; } - preferences.storeSidePanePreferredPositions(preferredPositions); + preferencesService.storeSidePanePreferences(preferencesService.getSidePanePreferences().withPreferredPositions(preferredPositions)); } /** @@ -164,12 +164,7 @@ public void moveDown(SidePaneComponent comp) { */ private void updateView() { sidePane.setComponents(visibleComponents); - - if (visibleComponents.isEmpty()) { - sidePane.setVisible(false); - } else { - sidePane.setVisible(true); - } + sidePane.setVisible(!visibleComponents.isEmpty()); } /** @@ -179,8 +174,8 @@ private static class PreferredIndexSort implements Comparator private final Map preferredPositions; - public PreferredIndexSort() { - preferredPositions = Globals.prefs.getSidePanePreferredPositions(); + public PreferredIndexSort(PreferencesService preferencesService) { + preferredPositions = preferencesService.getSidePanePreferences().getPreferredPositions(); } @Override diff --git a/src/main/java/org/jabref/gui/StartLiteratureReviewAction.java b/src/main/java/org/jabref/gui/StartLiteratureReviewAction.java index c67328a4e19..f6db57b4727 100644 --- a/src/main/java/org/jabref/gui/StartLiteratureReviewAction.java +++ b/src/main/java/org/jabref/gui/StartLiteratureReviewAction.java @@ -11,11 +11,13 @@ import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.crawler.Crawler; import org.jabref.logic.crawler.git.GitHandler; +import org.jabref.logic.exporter.SavePreferences; +import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ParseException; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.util.FileUpdateMonitor; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import org.eclipse.jgit.api.errors.GitAPIException; import org.slf4j.Logger; @@ -28,13 +30,19 @@ public class StartLiteratureReviewAction extends SimpleCommand { private final FileUpdateMonitor fileUpdateMonitor; private final Path workingDirectory; private final TaskExecutor taskExecutor; + private final PreferencesService preferencesService; + private final ImportFormatPreferences importFormatPreferneces; + private final SavePreferences savePreferences; - public StartLiteratureReviewAction(JabRefFrame frame, FileUpdateMonitor fileUpdateMonitor, Path standardWorkingDirectory, TaskExecutor taskExecutor) { + public StartLiteratureReviewAction(JabRefFrame frame, FileUpdateMonitor fileUpdateMonitor, Path standardWorkingDirectory, TaskExecutor taskExecutor, PreferencesService preferencesService, ImportFormatPreferences importFormatPreferences, SavePreferences savePreferences) { this.frame = frame; this.dialogService = frame.getDialogService(); this.fileUpdateMonitor = fileUpdateMonitor; this.workingDirectory = getInitialDirectory(standardWorkingDirectory); this.taskExecutor = taskExecutor; + this.preferencesService = preferencesService; + this.importFormatPreferneces = importFormatPreferences; + this.savePreferences = savePreferences; } @Override @@ -50,7 +58,7 @@ public void execute() { } final Crawler crawler; try { - crawler = new Crawler(studyDefinitionFile.get(), new GitHandler(studyDefinitionFile.get().getParent()), fileUpdateMonitor, JabRefPreferences.getInstance().getImportFormatPreferences(), JabRefPreferences.getInstance().getSavePreferences(), new BibEntryTypesManager()); + crawler = new Crawler(studyDefinitionFile.get(), new GitHandler(studyDefinitionFile.get().getParent()), fileUpdateMonitor, importFormatPreferneces, savePreferences, new BibEntryTypesManager()); } catch (IOException | ParseException | GitAPIException e) { LOGGER.error("Error during reading of study definition file.", e); dialogService.showErrorDialogAndWait(Localization.lang("Error during reading of study definition file."), e); @@ -64,7 +72,7 @@ public void execute() { LOGGER.error("Error during persistence of crawling results."); dialogService.showErrorDialogAndWait(Localization.lang("Error during persistence of crawling results."), e); }) - .onSuccess(unused -> new OpenDatabaseAction(frame).openFile(Path.of(studyDefinitionFile.get().getParent().toString(), "studyResult.bib"), true)) + .onSuccess(unused -> new OpenDatabaseAction(frame, preferencesService, dialogService).openFile(Path.of(studyDefinitionFile.get().getParent().toString(), "studyResult.bib"), true)) .executeWith(taskExecutor); } diff --git a/src/main/java/org/jabref/gui/UpdateTimestampListener.java b/src/main/java/org/jabref/gui/UpdateTimestampListener.java index aad998db035..7af68d7a415 100644 --- a/src/main/java/org/jabref/gui/UpdateTimestampListener.java +++ b/src/main/java/org/jabref/gui/UpdateTimestampListener.java @@ -17,7 +17,7 @@ class UpdateTimestampListener { @Subscribe public void listen(EntryChangedEvent event) { - if (preferencesService.getTimestampPreferences().includeTimestamps()) { + if (preferencesService.getTimestampPreferences().shouldIncludeTimestamps()) { event.getBibEntry().setField(preferencesService.getTimestampPreferences().getTimestampField(), preferencesService.getTimestampPreferences().now()); } diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java index 5626bc8b60e..7280deb9819 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java @@ -91,9 +91,9 @@ private void parseActionPerformed() { @FXML private void browseButtonClicked() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .addExtensionFilter(StandardFileType.AUX) - .withDefaultExtension(StandardFileType.AUX) - .withInitialDirectory(preferences.getWorkingDir()).build(); + .addExtensionFilter(StandardFileType.AUX) + .withDefaultExtension(StandardFileType.AUX) + .withInitialDirectory(preferences.getWorkingDir()).build(); dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> auxFileField.setText(file.toAbsolutePath().toString())); } } diff --git a/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java b/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java index f1d99d74331..a7c4d76b8b8 100644 --- a/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java +++ b/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java @@ -21,7 +21,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.util.FileUpdateMonitor; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,20 +38,20 @@ public class BibtexExtractorViewModel { public BibtexExtractorViewModel(BibDatabaseContext bibdatabaseContext, DialogService dialogService, - JabRefPreferences jabRefPreferences, + PreferencesService preferencesService, FileUpdateMonitor fileUpdateMonitor, TaskExecutor taskExecutor, UndoManager undoManager, StateManager stateManager) { this.dialogService = dialogService; - currentCitationfetcher = new GrobidCitationFetcher(jabRefPreferences.getImportFormatPreferences()); + currentCitationfetcher = new GrobidCitationFetcher(preferencesService.getImportFormatPreferences()); this.taskExecutor = taskExecutor; this.importHandler = new ImportHandler( dialogService, bibdatabaseContext, ExternalFileTypes.getInstance(), - jabRefPreferences, + preferencesService, fileUpdateMonitor, undoManager, stateManager); diff --git a/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexDialog.java b/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexDialog.java index 86f22264ee9..b7c33fdf15d 100644 --- a/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexDialog.java +++ b/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexDialog.java @@ -16,7 +16,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.util.FileUpdateMonitor; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; @@ -34,6 +34,7 @@ public class ExtractBibtexDialog extends BaseDialog { @Inject private FileUpdateMonitor fileUpdateMonitor; @Inject private TaskExecutor taskExecutor; @Inject private UndoManager undoManager; + @Inject private PreferencesService preferencesService; public ExtractBibtexDialog() { ViewLoader.view(this) @@ -52,7 +53,7 @@ public ExtractBibtexDialog() { @FXML private void initialize() { BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null")); - this.viewModel = new BibtexExtractorViewModel(database, dialogService, JabRefPreferences.getInstance(), fileUpdateMonitor, taskExecutor, undoManager, stateManager); + this.viewModel = new BibtexExtractorViewModel(database, dialogService, preferencesService, fileUpdateMonitor, taskExecutor, undoManager, stateManager); input.textProperty().bindBidirectional(viewModel.inputTextProperty()); } } diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index 0cf54e3ada9..f1d53b19015 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -14,7 +14,6 @@ import org.jabref.logic.citationkeypattern.CitationKeyGenerator; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; -import org.jabref.preferences.JabRefPreferences; public class GenerateCitationKeyAction extends SimpleCommand { @@ -51,14 +50,15 @@ public void execute() { } public static boolean confirmOverwriteKeys(DialogService dialogService) { - if (Globals.prefs.getBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY)) { + if (Globals.prefs.getCitationKeyPatternPreferences().shouldWarnBeforeOverwriteCiteKey()) { return dialogService.showConfirmationDialogWithOptOutAndWait( Localization.lang("Overwrite keys"), Localization.lang("One or more keys will be overwritten. Continue?"), Localization.lang("Overwrite keys"), Localization.lang("Cancel"), Localization.lang("Disable this confirmation dialog"), - optOut -> Globals.prefs.putBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY, !optOut)); + optOut -> Globals.prefs.storeCitationKeyPatternPreferences( + Globals.prefs.getCitationKeyPatternPreferences().withWarnBeforeOverwriteCiteKey(!optOut))); } else { // Always overwrite keys by default return true; @@ -67,7 +67,7 @@ public static boolean confirmOverwriteKeys(DialogService dialogService) { private void checkOverwriteKeysChosen() { // We don't want to generate keys for entries which already have one thus remove the entries - if (Globals.prefs.getBoolean(JabRefPreferences.AVOID_OVERWRITING_KEY)) { + if (Globals.prefs.getCitationKeyPatternPreferences().shouldAvoidOverwriteCiteKey()) { entries.removeIf(BibEntry::hasCitationKey); // if we're going to override some citation keys warn the user about it } else if (entries.parallelStream().anyMatch(BibEntry::hasCitationKey)) { diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java index 50e7e703c0f..ad7dab14172 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java @@ -18,7 +18,6 @@ import org.jabref.model.FieldChange; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; -import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.PreferencesService; public class CleanupAction extends SimpleCommand { @@ -31,7 +30,7 @@ public class CleanupAction extends SimpleCommand { private boolean isCanceled; private int modifiedEntriesCount; - public CleanupAction(JabRefFrame frame, JabRefPreferences preferences, DialogService dialogService, StateManager stateManager) { + public CleanupAction(JabRefFrame frame, PreferencesService preferences, DialogService dialogService, StateManager stateManager) { this.frame = frame; this.preferences = preferences; this.dialogService = dialogService; @@ -63,14 +62,14 @@ public void execute() { preferences.getFilePreferences()).showAndWait(); chosenPreset.ifPresent(preset -> { - if (preset.isRenamePDFActive() && Globals.prefs.getBoolean(JabRefPreferences.ASK_AUTO_NAMING_PDFS_AGAIN)) { + if (preset.isRenamePDFActive() && preferences.getAutoLinkPreferences().shouldAskAutoNamingPdfs()) { boolean confirmed = dialogService.showConfirmationDialogWithOptOutAndWait(Localization.lang("Autogenerate PDF Names"), Localization.lang("Auto-generating PDF-Names does not support undo. Continue?"), Localization.lang("Autogenerate PDF Names"), Localization.lang("Cancel"), Localization.lang("Disable this confirmation dialog"), - optOut -> Globals.prefs.putBoolean(JabRefPreferences.ASK_AUTO_NAMING_PDFS_AGAIN, !optOut)); - + optOut -> preferences.storeAutoLinkPreferences(preferences.getAutoLinkPreferences() + .withAskAutoNamingPdfs(!optOut))); if (!confirmed) { isCanceled = true; return; diff --git a/src/main/java/org/jabref/gui/collab/ChangeScanner.java b/src/main/java/org/jabref/gui/collab/ChangeScanner.java index f09de7c2bdd..4806d156a86 100644 --- a/src/main/java/org/jabref/gui/collab/ChangeScanner.java +++ b/src/main/java/org/jabref/gui/collab/ChangeScanner.java @@ -5,7 +5,6 @@ import java.util.Collections; import java.util.List; -import org.jabref.gui.Globals; import org.jabref.logic.bibtex.comparator.BibDatabaseDiff; import org.jabref.logic.bibtex.comparator.BibEntryDiff; import org.jabref.logic.bibtex.comparator.BibStringDiff; @@ -14,6 +13,7 @@ import org.jabref.logic.importer.ParserResult; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.util.DummyFileUpdateMonitor; +import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,9 +22,11 @@ public class ChangeScanner { private static final Logger LOGGER = LoggerFactory.getLogger(ChangeScanner.class); private final BibDatabaseContext database; + private final PreferencesService preferencesService; - public ChangeScanner(BibDatabaseContext database) { + public ChangeScanner(BibDatabaseContext database, PreferencesService preferencesService) { this.database = database; + this.preferencesService = preferencesService; } public List scanForChanges() { @@ -37,14 +39,14 @@ public List scanForChanges() { // Parse the modified file // Important: apply all post-load actions - ImportFormatPreferences importFormatPreferences = Globals.prefs.getImportFormatPreferences(); + ImportFormatPreferences importFormatPreferences = preferencesService.getImportFormatPreferences(); ParserResult result = OpenDatabase.loadDatabase(database.getDatabasePath().get(), importFormatPreferences, new DummyFileUpdateMonitor()); BibDatabaseContext databaseOnDisk = result.getDatabaseContext(); // Start looking at changes. BibDatabaseDiff differences = BibDatabaseDiff.compare(database, databaseOnDisk); differences.getMetaDataDifferences().ifPresent(diff -> { - changes.add(new MetaDataChangeViewModel(diff, Globals.prefs)); + changes.add(new MetaDataChangeViewModel(diff, preferencesService)); diff.getGroupDifferences().ifPresent(groupDiff -> changes.add(new GroupChangeViewModel(groupDiff))); }); differences.getPreambleDifferences().ifPresent(diff -> changes.add(new PreambleChangeViewModel(diff))); diff --git a/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java b/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java index 6181129601b..fe1f892ca62 100644 --- a/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java +++ b/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java @@ -9,6 +9,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.util.FileUpdateListener; import org.jabref.model.util.FileUpdateMonitor; +import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,11 +22,16 @@ public class DatabaseChangeMonitor implements FileUpdateListener { private final FileUpdateMonitor fileMonitor; private final List listeners; private final TaskExecutor taskExecutor; + private final PreferencesService preferencesService; - public DatabaseChangeMonitor(BibDatabaseContext database, FileUpdateMonitor fileMonitor, TaskExecutor taskExecutor) { + public DatabaseChangeMonitor(BibDatabaseContext database, + FileUpdateMonitor fileMonitor, + TaskExecutor taskExecutor, + PreferencesService preferencesService) { this.database = database; this.fileMonitor = fileMonitor; this.taskExecutor = taskExecutor; + this.preferencesService = preferencesService; this.listeners = new ArrayList<>(); this.database.getDatabasePath().ifPresent(path -> { @@ -40,7 +46,7 @@ public DatabaseChangeMonitor(BibDatabaseContext database, FileUpdateMonitor file @Override public void fileUpdated() { // File on disk has changed, thus look for notable changes and notify listeners in case there are such changes - ChangeScanner scanner = new ChangeScanner(database); + ChangeScanner scanner = new ChangeScanner(database, preferencesService); BackgroundTask.wrap(scanner::scanForChanges) .onSuccess(changes -> { if (!changes.isEmpty()) { diff --git a/src/main/java/org/jabref/gui/collab/MetaDataChangeViewModel.java b/src/main/java/org/jabref/gui/collab/MetaDataChangeViewModel.java index 1f9b2e6785e..83b6351fd78 100644 --- a/src/main/java/org/jabref/gui/collab/MetaDataChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/MetaDataChangeViewModel.java @@ -8,14 +8,14 @@ import org.jabref.logic.bibtex.comparator.MetaDataDiff; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; class MetaDataChangeViewModel extends DatabaseChangeViewModel { private final MetaDataDiff metaDataDiff; - private final JabRefPreferences preferences; + private final PreferencesService preferences; - public MetaDataChangeViewModel(MetaDataDiff metaDataDiff, JabRefPreferences preferences) { + public MetaDataChangeViewModel(MetaDataDiff metaDataDiff, PreferencesService preferences) { super(Localization.lang("Metadata change")); this.metaDataDiff = metaDataDiff; this.preferences = preferences; diff --git a/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java b/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java index 24c28e38097..07ee7470d6c 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java +++ b/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java @@ -14,7 +14,6 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; -import org.jabref.preferences.JabRefPreferences; import static org.jabref.gui.actions.ActionHelper.needsDatabase; import static org.jabref.gui.actions.ActionHelper.needsEntriesSelected; @@ -46,7 +45,7 @@ public void execute() { List entries = stateManager.getSelectedEntries(); DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(Path.of(Globals.prefs.get(JabRefPreferences.EXPORT_WORKING_DIRECTORY))) + .withInitialDirectory(Globals.prefs.getImportExportPreferences().getExportWorkingDirectory()) .build(); Optional exportPath = dialogService.showDirectorySelectionDialog(dirDialogConfiguration); exportPath.ifPresent(path -> { diff --git a/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java b/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java index 4505f75650d..72ec5c64266 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java +++ b/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java @@ -21,9 +21,10 @@ public class CopySingleFileAction extends SimpleCommand { private final LinkedFile linkedFile; private final DialogService dialogService; private final BibDatabaseContext databaseContext; - private final BiFunction resolvePathFilename = (path, file) -> path.resolve(file.getFileName()); private final PreferencesService preferencesService; + private final BiFunction resolvePathFilename = (path, file) -> path.resolve(file.getFileName()); + public CopySingleFileAction(LinkedFile linkedFile, DialogService dialogService, BibDatabaseContext databaseContext, PreferencesService preferencesService) { this.linkedFile = linkedFile; this.dialogService = dialogService; diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java index d7a034c3225..ac2ba0b697b 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java @@ -178,8 +178,8 @@ public void removeField(FieldViewModel focusedItem) { public void resetAllCustomEntryTypes() { entryTypesManager.clearAllCustomEntryTypes(mode); preferencesService.clearBibEntryTypes(mode); - entryTypesManager.addCustomOrModifiedTypes(preferencesService.loadBibEntryTypes(BibDatabaseMode.BIBTEX), - preferencesService.loadBibEntryTypes(BibDatabaseMode.BIBLATEX)); + entryTypesManager.addCustomOrModifiedTypes(preferencesService.getBibEntryTypes(BibDatabaseMode.BIBTEX), + preferencesService.getBibEntryTypes(BibDatabaseMode.BIBLATEX)); } public void apply() { @@ -199,9 +199,9 @@ public void apply() { entryTypesManager.removeCustomOrModifiedEntryType(entryType, mode); } - preferencesService.saveCustomEntryTypes(entryTypesManager); + preferencesService.storeCustomEntryTypes(entryTypesManager); // Reload types from preferences to make sure any modifications are present when reopening the dialog - entryTypesManager.addCustomOrModifiedTypes(preferencesService.loadBibEntryTypes(BibDatabaseMode.BIBTEX), - preferencesService.loadBibEntryTypes(BibDatabaseMode.BIBLATEX)); + entryTypesManager.addCustomOrModifiedTypes(preferencesService.getBibEntryTypes(BibDatabaseMode.BIBTEX), + preferencesService.getBibEntryTypes(BibDatabaseMode.BIBLATEX)); } } diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index eb12f33a2f2..3cd156c24f3 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -27,7 +27,6 @@ import org.jabref.model.entry.identifier.DOI; import org.jabref.model.entry.identifier.Eprint; import org.jabref.model.util.FileHelper; -import org.jabref.preferences.JabRefPreferences; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -157,19 +156,19 @@ private static void openExternalFilePlatformIndependent(Optional copyTitle(); + case COPY_KEY -> copyKey(); + case COPY_CITE_KEY -> copyCiteKey(); + case COPY_KEY_AND_TITLE -> copyKeyAndTitle(); + case COPY_KEY_AND_LINK -> copyKeyAndLink(); + default -> LOGGER.info("Unknown copy command."); } } @@ -140,7 +127,7 @@ private void copyCiteKey() { return; } - String citeCommand = Optional.ofNullable(Globals.prefs.get(JabRefPreferences.CITE_COMMAND)) + String citeCommand = Optional.ofNullable(Globals.prefs.getExternalApplicationsPreferences().getCiteCommand()) .filter(cite -> cite.contains("\\")) // must contain \ .orElse("\\cite"); diff --git a/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java b/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java index 883bc98da1e..0c52de20ef8 100644 --- a/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java @@ -9,6 +9,7 @@ import javafx.scene.control.Tooltip; import org.jabref.gui.DialogService; +import org.jabref.gui.StateManager; import org.jabref.gui.autocompleter.SuggestionProviders; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.icon.IconTheme; @@ -20,14 +21,23 @@ import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.Field; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; public class DeprecatedFieldsTab extends FieldsEditorTab { private final BibEntryTypesManager entryTypesManager; - public DeprecatedFieldsTab(BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, DialogService dialogService, JabRefPreferences preferences, BibEntryTypesManager entryTypesManager, ExternalFileTypes externalFileTypes, TaskExecutor taskExecutor, JournalAbbreviationRepository journalAbbreviationRepository) { - super(false, databaseContext, suggestionProviders, undoManager, dialogService, preferences, externalFileTypes, taskExecutor, journalAbbreviationRepository); + public DeprecatedFieldsTab(BibDatabaseContext databaseContext, + SuggestionProviders suggestionProviders, + UndoManager undoManager, + DialogService dialogService, + PreferencesService preferences, + StateManager stateManager, + BibEntryTypesManager entryTypesManager, + ExternalFileTypes externalFileTypes, + TaskExecutor taskExecutor, + JournalAbbreviationRepository journalAbbreviationRepository) { + super(false, databaseContext, suggestionProviders, undoManager, dialogService, preferences, stateManager, externalFileTypes, taskExecutor, journalAbbreviationRepository); this.entryTypesManager = entryTypesManager; setText(Localization.lang("Deprecated fields")); diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 7f05300ff00..026d4ba3a5d 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -229,28 +229,28 @@ private void navigateToNextEntry() { private List createTabs() { // Preview tab - entryEditorTabs.add(new PreviewTab(databaseContext, dialogService, Globals.prefs, ExternalFileTypes.getInstance())); + entryEditorTabs.add(new PreviewTab(databaseContext, dialogService, preferencesService, stateManager, ExternalFileTypes.getInstance())); // Required fields - entryEditorTabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); // Optional fields - entryEditorTabs.add(new OptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); - entryEditorTabs.add(new OptionalFields2Tab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); - entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new OptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new OptionalFields2Tab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); // Other fields - entryEditorTabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); // General fields from preferences for (Map.Entry> tab : entryEditorPreferences.getEntryEditorTabList().entrySet()) { - entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); + entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)); } // Special tabs entryEditorTabs.add(new MathSciNetTab()); entryEditorTabs.add(new FileAnnotationTab(libraryTab.getAnnotationCache())); - entryEditorTabs.add(new RelatedArticlesTab(this, entryEditorPreferences, dialogService)); + entryEditorTabs.add(new RelatedArticlesTab(this, entryEditorPreferences, preferencesService, dialogService)); // Source tab sourceTab = new SourceTab( diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java index 278c9a85427..440678504f7 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java @@ -59,7 +59,7 @@ public boolean shouldShowLatexCitationsTab() { return shouldShowLatexCitationsTab; } - public boolean isEnableValidation() { + public boolean shouldEnableValidation() { return enableValidation; } diff --git a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java index 9c3d74f2c6a..9d037e5af2f 100644 --- a/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java @@ -24,6 +24,7 @@ import javafx.scene.layout.RowConstraints; import org.jabref.gui.DialogService; +import org.jabref.gui.StateManager; import org.jabref.gui.autocompleter.SuggestionProviders; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.fieldeditors.FieldEditorFX; @@ -35,7 +36,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.preferences.PreferencesService; /** * A single tab displayed in the EntryEditor holding several FieldEditors. @@ -46,16 +47,26 @@ abstract class FieldsEditorTab extends EntryEditorTab { private final boolean isCompressed; private final SuggestionProviders suggestionProviders; private final DialogService dialogService; - private final JabRefPreferences preferences; + private final PreferencesService preferences; private final ExternalFileTypes externalFileTypes; private final TaskExecutor taskExecutor; private final JournalAbbreviationRepository journalAbbreviationRepository; + private final StateManager stateManager; private PreviewPanel previewPanel; private final UndoManager undoManager; private Collection fields = new ArrayList<>(); private GridPane gridPane; - public FieldsEditorTab(boolean compressed, BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, DialogService dialogService, JabRefPreferences preferences, ExternalFileTypes externalFileTypes, TaskExecutor taskExecutor, JournalAbbreviationRepository journalAbbreviationRepository) { + public FieldsEditorTab(boolean compressed, + BibDatabaseContext databaseContext, + SuggestionProviders suggestionProviders, + UndoManager undoManager, + DialogService dialogService, + PreferencesService preferences, + StateManager stateManager, + ExternalFileTypes externalFileTypes, + TaskExecutor taskExecutor, + JournalAbbreviationRepository journalAbbreviationRepository) { this.isCompressed = compressed; this.databaseContext = Objects.requireNonNull(databaseContext); this.suggestionProviders = Objects.requireNonNull(suggestionProviders); @@ -65,10 +76,11 @@ public FieldsEditorTab(boolean compressed, BibDatabaseContext databaseContext, S this.externalFileTypes = Objects.requireNonNull(externalFileTypes); this.taskExecutor = Objects.requireNonNull(taskExecutor); this.journalAbbreviationRepository = Objects.requireNonNull(journalAbbreviationRepository); + this.stateManager = stateManager; } private static void addColumn(GridPane gridPane, int columnIndex, List