diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index 9882bc4df54..9b0d2c1ef59 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -71,16 +71,19 @@ public class ArgumentProcessor { private final Mode startupMode; private final PreferencesService preferencesService; private final FileUpdateMonitor fileUpdateMonitor; + private final BibEntryTypesManager entryTypesManager; private boolean noGUINeeded; public ArgumentProcessor(String[] args, Mode startupMode, PreferencesService preferencesService, - FileUpdateMonitor fileUpdateMonitor) throws org.apache.commons.cli.ParseException { + FileUpdateMonitor fileUpdateMonitor, + BibEntryTypesManager entryTypesManager) throws org.apache.commons.cli.ParseException { this.cli = new JabRefCLI(args); this.startupMode = startupMode; this.preferencesService = preferencesService; this.fileUpdateMonitor = fileUpdateMonitor; + this.entryTypesManager = entryTypesManager; this.parserResults = processArguments(); } @@ -291,13 +294,12 @@ private void writeMetadataToPdf(List loaded, } ParserResult pr = loaded.get(loaded.size() - 1); BibDatabaseContext databaseContext = pr.getDatabaseContext(); - BibDatabase dataBase = pr.getDatabase(); XmpPdfExporter xmpPdfExporter = new XmpPdfExporter(xmpPreferences); EmbeddedBibFilePdfExporter embeddedBibFilePdfExporter = new EmbeddedBibFilePdfExporter(databaseMode, entryTypesManager, fieldPreferences); if ("all".equals(filesAndCitekeys)) { - for (BibEntry entry : dataBase.getEntries()) { + for (BibEntry entry : databaseContext.getEntries()) { writeMetadataToPDFsOfEntry( databaseContext, entry.getCitationKey().orElse(""), @@ -324,7 +326,6 @@ private void writeMetadataToPdf(List loaded, writeMetadataToPdfByCitekey( databaseContext, - dataBase, citeKeys, filePreferences, xmpPdfExporter, @@ -334,7 +335,6 @@ private void writeMetadataToPdf(List loaded, embeddBibfile); writeMetadataToPdfByFileNames( databaseContext, - dataBase, pdfs, filePreferences, xmpPdfExporter, @@ -374,7 +374,6 @@ private void writeMetadataToPDFsOfEntry(BibDatabaseContext databaseContext, } private void writeMetadataToPdfByCitekey(BibDatabaseContext databaseContext, - BibDatabase dataBase, List citeKeys, FilePreferences filePreferences, XmpPdfExporter xmpPdfExporter, @@ -383,7 +382,7 @@ private void writeMetadataToPdfByCitekey(BibDatabaseContext databaseContext, boolean writeXMP, boolean embeddBibfile) { for (String citeKey : citeKeys) { - List bibEntryList = dataBase.getEntriesByCitationKey(citeKey); + List bibEntryList = databaseContext.getDatabase().getEntriesByCitationKey(citeKey); if (bibEntryList.isEmpty()) { System.err.printf("Skipped - Cannot find %s in library.%n", citeKey); continue; @@ -395,7 +394,6 @@ private void writeMetadataToPdfByCitekey(BibDatabaseContext databaseContext, } private void writeMetadataToPdfByFileNames(BibDatabaseContext databaseContext, - BibDatabase dataBase, List pdfs, FilePreferences filePreferences, XmpPdfExporter xmpPdfExporter, @@ -411,14 +409,14 @@ private void writeMetadataToPdfByFileNames(BibDatabaseContext databaseContext, if (Files.exists(filePath)) { try { if (writeXMP) { - if (xmpPdfExporter.exportToFileByPath(databaseContext, dataBase, filePreferences, filePath, abbreviationRepository)) { + if (xmpPdfExporter.exportToFileByPath(databaseContext, filePreferences, filePath, abbreviationRepository)) { System.out.printf("Successfully written XMP metadata of at least one entry to %s%n", fileName); } else { System.out.printf("File %s is not linked to any entry in database.%n", fileName); } } if (embeddBibfile) { - if (embeddedBibFilePdfExporter.exportToFileByPath(databaseContext, dataBase, filePreferences, filePath, abbreviationRepository)) { + if (embeddedBibFilePdfExporter.exportToFileByPath(databaseContext, filePreferences, filePath, abbreviationRepository)) { System.out.printf("Successfully embedded XMP metadata of at least one entry to %s%n", fileName); } else { System.out.printf("File %s is not linked to any entry in database.%n", fileName); @@ -607,7 +605,7 @@ private void saveDatabase(BibDatabase newBase, String subName) { saveConfiguration, preferencesService.getFieldPreferences(), preferencesService.getCitationKeyPatternPreferences(), - Globals.entryTypesManager); + entryTypesManager); databaseWriter.saveDatabase(new BibDatabaseContext(newBase)); // Show just a warning message if encoding did not work for all characters: diff --git a/src/main/java/org/jabref/cli/Launcher.java b/src/main/java/org/jabref/cli/Launcher.java index e7a8bc716d1..bf1554f82e0 100644 --- a/src/main/java/org/jabref/cli/Launcher.java +++ b/src/main/java/org/jabref/cli/Launcher.java @@ -23,6 +23,7 @@ import org.jabref.logic.remote.client.RemoteClient; import org.jabref.logic.util.OS; import org.jabref.migrations.PreferencesMigrations; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.PreferencesService; @@ -59,10 +60,13 @@ public static void main(String[] args) { addLogToDisk(); try { + BibEntryTypesManager entryTypesManager = new BibEntryTypesManager(); + Globals.entryTypesManager = entryTypesManager; + // Init preferences final JabRefPreferences preferences = JabRefPreferences.getInstance(); Globals.prefs = preferences; - PreferencesMigrations.runMigrations(preferences); + PreferencesMigrations.runMigrations(preferences, entryTypesManager); // Early exit in case another instance is already running if (!handleMultipleAppInstances(ARGUMENTS, preferences)) { @@ -82,7 +86,8 @@ public static void main(String[] args) { ArgumentProcessor argumentProcessor = new ArgumentProcessor( ARGUMENTS, ArgumentProcessor.Mode.INITIAL_START, preferences, - fileUpdateMonitor); + fileUpdateMonitor, + entryTypesManager); if (argumentProcessor.shouldShutDown()) { LOGGER.debug("JabRef shut down after processing command line arguments"); return; diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index 8b80078c30c..8ff63a59374 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -20,6 +20,7 @@ import org.jabref.logic.bibtex.FieldWriter; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; @@ -141,9 +142,9 @@ public void setContent(String string) { setPrimaryClipboardContent(content); } - public void setContent(List entries) throws IOException { + public void setContent(List entries, BibEntryTypesManager entryTypesManager) throws IOException { final ClipboardContent content = new ClipboardContent(); - BibEntryWriter writer = new BibEntryWriter(new FieldWriter(preferencesService.getFieldPreferences()), Globals.entryTypesManager); + BibEntryWriter writer = new BibEntryWriter(new FieldWriter(preferencesService.getFieldPreferences()), entryTypesManager); String serializedEntries = writer.serializeAll(entries, BibDatabaseMode.BIBTEX); // BibEntry is not Java serializable. Thus, we need to do the serialization manually // At reading of the clipboard in JabRef, we parse the plain string in all cases, so we don't need to flag we put BibEntries here diff --git a/src/main/java/org/jabref/gui/Globals.java b/src/main/java/org/jabref/gui/Globals.java index 1e3ca75f30d..117361bb72f 100644 --- a/src/main/java/org/jabref/gui/Globals.java +++ b/src/main/java/org/jabref/gui/Globals.java @@ -70,7 +70,7 @@ public class Globals { public static ProtectedTermsLoader protectedTermsLoader; public static CountingUndoManager undoManager = new CountingUndoManager(); - public static BibEntryTypesManager entryTypesManager = new BibEntryTypesManager(); + public static BibEntryTypesManager entryTypesManager; private static ClipBoardManager clipBoardManager = null; private static KeyBindingRepository keyBindingRepository; @@ -123,7 +123,7 @@ public static void startBackgroundTasks() { } */ RemotePreferences remotePreferences = prefs.getRemotePreferences(); if (remotePreferences.useRemoteServer()) { - Globals.REMOTE_LISTENER.openAndStart(new CLIMessageHandler(prefs, fileUpdateMonitor), remotePreferences.getPort()); + Globals.REMOTE_LISTENER.openAndStart(new CLIMessageHandler(prefs, fileUpdateMonitor, entryTypesManager), remotePreferences.getPort()); } } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index d30d2753b72..2458b5a4127 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -134,6 +134,7 @@ import org.jabref.logic.util.OS; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.SpecialField; import org.jabref.model.entry.types.StandardEntryType; import org.jabref.model.groups.GroupTreeNode; @@ -174,6 +175,7 @@ public class JabRefFrame extends BorderPane { private final CountingUndoManager undoManager; private final DialogService dialogService; private final FileUpdateMonitor fileUpdateMonitor; + private final BibEntryTypesManager entryTypesManager; private final PushToApplicationCommand pushToApplicationCommand; private SidePane sidePane; private TabPane tabbedPane; @@ -190,6 +192,7 @@ public JabRefFrame(Stage mainStage) { this.dialogService = new JabRefDialogService(mainStage); this.undoManager = Globals.undoManager; this.fileUpdateMonitor = Globals.getFileUpdateMonitor(); + this.entryTypesManager = Globals.entryTypesManager; this.globalSearchBar = new GlobalSearchBar(this, stateManager, prefs, undoManager, dialogService); this.pushToApplicationCommand = new PushToApplicationCommand(stateManager, dialogService, prefs); this.fileHistory = new FileHistoryMenu(prefs.getGuiPreferences().getFileHistory(), dialogService, getOpenDatabaseAction()); @@ -414,7 +417,7 @@ public void openAction(String filePath) { * The MacAdapter calls this method when "About" is selected from the application menu. */ public void about() { - new HelpAction(HelpFile.CONTENTS, dialogService).execute(); + new HelpAction(HelpFile.CONTENTS, dialogService, prefs.getFilePreferences()).execute(); } /** @@ -593,7 +596,7 @@ private Node createToolbar() { ToolBar toolBar = new ToolBar( new HBox( factory.createIconButton(StandardActions.NEW_LIBRARY, new NewDatabaseAction(this, prefs)), - factory.createIconButton(StandardActions.OPEN_LIBRARY, new OpenDatabaseAction(this, prefs, dialogService, stateManager, fileUpdateMonitor)), + factory.createIconButton(StandardActions.OPEN_LIBRARY, new OpenDatabaseAction(this, prefs, dialogService, stateManager, fileUpdateMonitor, entryTypesManager)), factory.createIconButton(StandardActions.SAVE_LIBRARY, new SaveAction(SaveAction.SaveMethod.SAVE, this, prefs, stateManager))), leftSpacer, @@ -633,7 +636,7 @@ private Node createToolbar() { new Separator(Orientation.VERTICAL), new HBox( - factory.createIconButton(StandardActions.OPEN_GITHUB, new OpenBrowserAction("https://github.com/JabRef/jabref", dialogService)))); + factory.createIconButton(StandardActions.OPEN_GITHUB, new OpenBrowserAction("https://github.com/JabRef/jabref", dialogService, prefs.getFilePreferences())))); leftSpacer.setPrefWidth(50); leftSpacer.setMinWidth(Region.USE_PREF_SIZE); @@ -892,8 +895,8 @@ private MenuBar createMenu() { quality.getItems().addAll( factory.createMenuItem(StandardActions.FIND_DUPLICATES, new DuplicateSearch(this, dialogService, stateManager, prefs)), - factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(dialogService, stateManager, prefs.getBibEntryPreferences())), - factory.createMenuItem(StandardActions.CHECK_INTEGRITY, new IntegrityCheckAction(this, stateManager, Globals.TASK_EXECUTOR)), + factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(dialogService, stateManager, prefs)), + factory.createMenuItem(StandardActions.CHECK_INTEGRITY, new IntegrityCheckAction(this, prefs, dialogService, stateManager, Globals.TASK_EXECUTOR, Globals.journalAbbreviationRepository)), factory.createMenuItem(StandardActions.CLEANUP_ENTRIES, new CleanupAction(this, this.prefs, dialogService, stateManager)), new SeparatorMenuItem(), @@ -934,7 +937,7 @@ private MenuBar createMenu() { new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.WRITE_METADATA_TO_PDF, new WriteMetadataToPdfAction(stateManager, Globals.entryTypesManager, prefs.getFieldPreferences(), dialogService, taskExecutor, prefs.getFilePreferences(), prefs.getXmpPreferences())), + factory.createMenuItem(StandardActions.WRITE_METADATA_TO_PDF, new WriteMetadataToPdfAction(stateManager, Globals.entryTypesManager, prefs.getFieldPreferences(), dialogService, taskExecutor, prefs.getFilePreferences(), prefs.getXmpPreferences(), Globals.journalAbbreviationRepository)), factory.createMenuItem(StandardActions.COPY_LINKED_FILES, new CopyFilesAction(dialogService, prefs, stateManager)), new SeparatorMenuItem(), @@ -974,8 +977,8 @@ private MenuBar createMenu() { ); help.getItems().addAll( - factory.createMenuItem(StandardActions.HELP, new HelpAction(HelpFile.CONTENTS, dialogService)), - factory.createMenuItem(StandardActions.OPEN_FORUM, new OpenBrowserAction("http://discourse.jabref.org/", dialogService)), + factory.createMenuItem(StandardActions.HELP, new HelpAction(HelpFile.CONTENTS, dialogService, prefs.getFilePreferences())), + factory.createMenuItem(StandardActions.OPEN_FORUM, new OpenBrowserAction("http://discourse.jabref.org/", dialogService, prefs.getFilePreferences())), new SeparatorMenuItem(), @@ -983,19 +986,19 @@ private MenuBar createMenu() { new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.DONATE, new OpenBrowserAction("https://donations.jabref.org", dialogService)), - factory.createMenuItem(StandardActions.SEARCH_FOR_UPDATES, new SearchForUpdateAction(Globals.BUILD_INFO, prefs.getInternalPreferences(), dialogService, Globals.TASK_EXECUTOR)), + factory.createMenuItem(StandardActions.DONATE, new OpenBrowserAction("https://donations.jabref.org", dialogService, prefs.getFilePreferences())), + factory.createMenuItem(StandardActions.SEARCH_FOR_UPDATES, new SearchForUpdateAction(Globals.BUILD_INFO, prefs, dialogService, Globals.TASK_EXECUTOR)), factory.createSubMenu(StandardActions.WEB_MENU, - factory.createMenuItem(StandardActions.OPEN_WEBPAGE, new OpenBrowserAction("https://jabref.org/", dialogService)), - factory.createMenuItem(StandardActions.OPEN_BLOG, new OpenBrowserAction("https://blog.jabref.org/", dialogService)), - factory.createMenuItem(StandardActions.OPEN_FACEBOOK, new OpenBrowserAction("https://www.facebook.com/JabRef/", dialogService)), - factory.createMenuItem(StandardActions.OPEN_TWITTER, new OpenBrowserAction("https://twitter.com/jabref_org", dialogService)), - factory.createMenuItem(StandardActions.OPEN_GITHUB, new OpenBrowserAction("https://github.com/JabRef/jabref", dialogService)), + factory.createMenuItem(StandardActions.OPEN_WEBPAGE, new OpenBrowserAction("https://jabref.org/", dialogService, prefs.getFilePreferences())), + factory.createMenuItem(StandardActions.OPEN_BLOG, new OpenBrowserAction("https://blog.jabref.org/", dialogService, prefs.getFilePreferences())), + factory.createMenuItem(StandardActions.OPEN_FACEBOOK, new OpenBrowserAction("https://www.facebook.com/JabRef/", dialogService, prefs.getFilePreferences())), + factory.createMenuItem(StandardActions.OPEN_TWITTER, new OpenBrowserAction("https://twitter.com/jabref_org", dialogService, prefs.getFilePreferences())), + factory.createMenuItem(StandardActions.OPEN_GITHUB, new OpenBrowserAction("https://github.com/JabRef/jabref", dialogService, prefs.getFilePreferences())), new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.OPEN_DEV_VERSION_LINK, new OpenBrowserAction("https://builds.jabref.org/master/", dialogService)), - factory.createMenuItem(StandardActions.OPEN_CHANGELOG, new OpenBrowserAction("https://github.com/JabRef/jabref/blob/main/CHANGELOG.md", dialogService)) + factory.createMenuItem(StandardActions.OPEN_DEV_VERSION_LINK, new OpenBrowserAction("https://builds.jabref.org/master/", dialogService, prefs.getFilePreferences())), + factory.createMenuItem(StandardActions.OPEN_CHANGELOG, new OpenBrowserAction("https://github.com/JabRef/jabref/blob/main/CHANGELOG.md", dialogService, prefs.getFilePreferences())) ), factory.createMenuItem(StandardActions.ABOUT, new AboutAction()) ); @@ -1188,7 +1191,7 @@ public void addTab(LibraryTab libraryTab, boolean raisePanel) { public LibraryTab addTab(BibDatabaseContext databaseContext, boolean raisePanel) { Objects.requireNonNull(databaseContext); - LibraryTab libraryTab = new LibraryTab(databaseContext, this, prefs, stateManager, fileUpdateMonitor); + LibraryTab libraryTab = new LibraryTab(databaseContext, this, prefs, stateManager, fileUpdateMonitor, entryTypesManager); addTab(libraryTab, raisePanel); return libraryTab; } @@ -1306,7 +1309,7 @@ public void closeCurrentTab() { } public OpenDatabaseAction getOpenDatabaseAction() { - return new OpenDatabaseAction(this, prefs, dialogService, stateManager, fileUpdateMonitor); + return new OpenDatabaseAction(this, prefs, dialogService, stateManager, fileUpdateMonitor, entryTypesManager); } public GlobalSearchBar getGlobalSearchBar() { @@ -1363,7 +1366,7 @@ private Menu createSendSubMenu(ActionFactory factory, PreferencesService preferencesService) { Menu sendMenu = factory.createMenu(StandardActions.SEND); sendMenu.getItems().addAll( - factory.createMenuItem(StandardActions.SEND_AS_EMAIL, new SendAsStandardEmailAction(dialogService, preferencesService, stateManager)), + factory.createMenuItem(StandardActions.SEND_AS_EMAIL, new SendAsStandardEmailAction(dialogService, preferencesService, stateManager, entryTypesManager)), factory.createMenuItem(StandardActions.SEND_TO_KINDLE, new SendAsKindleEmailAction(dialogService, preferencesService, stateManager)) ); @@ -1445,7 +1448,7 @@ public OpenDatabaseFolder(Supplier databaseContext) { public void execute() { Optional.of(databaseContext.get()).flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> { try { - JabRefDesktop.openFolderAndSelectFile(path, prefs, dialogService); + JabRefDesktop.openFolderAndSelectFile(path, prefs.getExternalApplicationsPreferences(), dialogService); } catch (IOException e) { LOGGER.info("Could not open folder", e); } diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index 49297aaa5bb..f0497c11c28 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -73,7 +73,7 @@ public JabRefGUI(Stage mainStage, new VersionWorker(Globals.BUILD_INFO.version, mainFrame.getDialogService(), Globals.TASK_EXECUTOR, - preferencesService.getInternalPreferences()) + preferencesService) .checkForNewVersionDelayed(); } }); diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index 2f80b63ca54..4beabbfea92 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -59,6 +59,7 @@ import org.jabref.model.database.event.EntriesAddedEvent; import org.jabref.model.database.event.EntriesRemovedEvent; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.LinkedFile; import org.jabref.model.entry.event.EntriesEventSource; import org.jabref.model.entry.event.EntryChangedEvent; @@ -86,6 +87,7 @@ public class LibraryTab extends Tab { private final PreferencesService preferencesService; private final FileUpdateMonitor fileUpdateMonitor; private final StateManager stateManager; + private final BibEntryTypesManager entryTypesManager; private final BooleanProperty changedProperty = new SimpleBooleanProperty(false); private final BooleanProperty nonUndoableChangeProperty = new SimpleBooleanProperty(false); @@ -122,7 +124,8 @@ public LibraryTab(BibDatabaseContext bibDatabaseContext, JabRefFrame frame, PreferencesService preferencesService, StateManager stateManager, - FileUpdateMonitor fileUpdateMonitor) { + FileUpdateMonitor fileUpdateMonitor, + BibEntryTypesManager entryTypesManager) { this.frame = Objects.requireNonNull(frame); this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext); this.undoManager = frame.getUndoManager(); @@ -130,6 +133,7 @@ public LibraryTab(BibDatabaseContext bibDatabaseContext, this.preferencesService = Objects.requireNonNull(preferencesService); this.stateManager = Objects.requireNonNull(stateManager); this.fileUpdateMonitor = fileUpdateMonitor; + this.entryTypesManager = entryTypesManager; bibDatabaseContext.getDatabase().registerListener(this); bibDatabaseContext.getMetaData().registerListener(this); @@ -287,7 +291,7 @@ public void feedData(BibDatabaseContext bibDatabaseContextFromParserResult) { public void installAutosaveManagerAndBackupManager() { if (isDatabaseReadyForAutoSave(bibDatabaseContext)) { AutosaveManager autosaveManager = AutosaveManager.start(bibDatabaseContext); - autosaveManager.registerListener(new AutosaveUiManager(this)); + autosaveManager.registerListener(new AutosaveUiManager(this, preferencesService, entryTypesManager)); } if (isDatabaseReadyForBackup(bibDatabaseContext) && preferencesService.getFilePreferences().shouldCreateBackup()) { BackupManager.start(bibDatabaseContext, Globals.entryTypesManager, preferencesService); @@ -501,6 +505,7 @@ private void createMainTable() { stateManager, Globals.getKeyPrefs(), Globals.getClipboardManager(), + entryTypesManager, Globals.TASK_EXECUTOR, fileUpdateMonitor); @@ -824,11 +829,12 @@ public static LibraryTab createLibraryTab(BackgroundTask dataLoadi PreferencesService preferencesService, StateManager stateManager, JabRefFrame frame, - FileUpdateMonitor fileUpdateMonitor) { + FileUpdateMonitor fileUpdateMonitor, + BibEntryTypesManager entryTypesManager) { BibDatabaseContext context = new BibDatabaseContext(); context.setDatabasePath(file); - LibraryTab newTab = new LibraryTab(context, frame, preferencesService, stateManager, fileUpdateMonitor); + LibraryTab newTab = new LibraryTab(context, frame, preferencesService, stateManager, fileUpdateMonitor, entryTypesManager); 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 1cd721dc3db..f8a9bba6ad6 100644 --- a/src/main/java/org/jabref/gui/SendAsEMailAction.java +++ b/src/main/java/org/jabref/gui/SendAsEMailAction.java @@ -104,7 +104,7 @@ private List getAttachments(List entries) { attachments.add(path.toAbsolutePath().toString()); if (openFolders) { try { - JabRefDesktop.openFolderAndSelectFile(path.toAbsolutePath(), preferencesService, dialogService); + JabRefDesktop.openFolderAndSelectFile(path.toAbsolutePath(), preferencesService.getExternalApplicationsPreferences(), dialogService); } catch (IOException e) { LOGGER.debug("Cannot open file", e); } diff --git a/src/main/java/org/jabref/gui/SendAsStandardEmailAction.java b/src/main/java/org/jabref/gui/SendAsStandardEmailAction.java index da0a229820d..0faf359b371 100644 --- a/src/main/java/org/jabref/gui/SendAsStandardEmailAction.java +++ b/src/main/java/org/jabref/gui/SendAsStandardEmailAction.java @@ -11,6 +11,7 @@ import org.jabref.logic.util.OS; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; @@ -24,11 +25,13 @@ public class SendAsStandardEmailAction extends SendAsEMailAction { private static final Logger LOGGER = LoggerFactory.getLogger(SendAsStandardEmailAction.class); private final PreferencesService preferencesService; private final StateManager stateManager; + private final BibEntryTypesManager entryTypesManager; - public SendAsStandardEmailAction(DialogService dialogService, PreferencesService preferencesService, StateManager stateManager) { + public SendAsStandardEmailAction(DialogService dialogService, PreferencesService preferencesService, StateManager stateManager, BibEntryTypesManager entryTypesManager) { super(dialogService, preferencesService, stateManager); this.preferencesService = preferencesService; this.stateManager = stateManager; + this.entryTypesManager = entryTypesManager; this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); } @@ -49,7 +52,7 @@ protected String getBody() { StringWriter rawEntries = new StringWriter(); BibWriter bibWriter = new BibWriter(rawEntries, OS.NEWLINE); - BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new FieldWriter(preferencesService.getFieldPreferences()), Globals.entryTypesManager); + BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new FieldWriter(preferencesService.getFieldPreferences()), entryTypesManager); for (BibEntry entry : entries) { try { diff --git a/src/main/java/org/jabref/gui/backup/BackupResolverDialog.java b/src/main/java/org/jabref/gui/backup/BackupResolverDialog.java index 619aaa88770..502ed96740f 100644 --- a/src/main/java/org/jabref/gui/backup/BackupResolverDialog.java +++ b/src/main/java/org/jabref/gui/backup/BackupResolverDialog.java @@ -9,11 +9,11 @@ import javafx.scene.control.Hyperlink; import org.jabref.gui.FXDialog; -import org.jabref.gui.Globals; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.BackupFileType; import org.jabref.logic.util.io.BackupFileUtil; +import org.jabref.preferences.ExternalApplicationsPreferences; import org.controlsfx.control.HyperlinkLabel; import org.slf4j.Logger; @@ -26,7 +26,7 @@ public class BackupResolverDialog extends FXDialog { private static final Logger LOGGER = LoggerFactory.getLogger(BackupResolverDialog.class); - public BackupResolverDialog(Path originalPath, Path backupDir) { + public BackupResolverDialog(Path originalPath, Path backupDir, ExternalApplicationsPreferences externalApplicationsPreferences) { super(AlertType.CONFIRMATION, Localization.lang("Backup found"), true); setHeaderText(null); getDialogPane().setMinHeight(180); @@ -34,15 +34,9 @@ public BackupResolverDialog(Path originalPath, Path backupDir) { Optional backupPathOpt = BackupFileUtil.getPathOfLatestExistingBackupFile(originalPath, BackupFileType.BACKUP, backupDir); String backupFilename = backupPathOpt.map(Path::getFileName).map(Path::toString).orElse(Localization.lang("File not found")); - String content = new StringBuilder() - .append(Localization.lang("A backup file for '%0' was found at [%1]", - originalPath.getFileName().toString(), - backupFilename)) - .append("\n") - .append(Localization.lang("This could indicate that JabRef did not shut down cleanly last time the file was used.")) - .append("\n\n") - .append(Localization.lang("Do you want to recover the library from the backup file?")) - .toString(); + String content = Localization.lang("A backup file for '%0' was found at [%1]", originalPath.getFileName().toString(), backupFilename) + "\n" + + Localization.lang("This could indicate that JabRef did not shut down cleanly last time the file was used.") + "\n\n" + + Localization.lang("Do you want to recover the library from the backup file?"); setContentText(content); HyperlinkLabel contentLabel = new HyperlinkLabel(content); @@ -55,7 +49,7 @@ public BackupResolverDialog(Path originalPath, Path backupDir) { String clickedLinkText = ((Hyperlink) (e.getSource())).getText(); if (backupFilename.equals(clickedLinkText)) { try { - JabRefDesktop.openFolderAndSelectFile(backupPathOpt.get(), Globals.prefs, null); + JabRefDesktop.openFolderAndSelectFile(backupPathOpt.get(), externalApplicationsPreferences, null); } catch (IOException ex) { LOGGER.error("Could not open backup folder", ex); } diff --git a/src/main/java/org/jabref/gui/collab/ChangeScanner.java b/src/main/java/org/jabref/gui/collab/ChangeScanner.java index 72ea8768613..64936e47de4 100644 --- a/src/main/java/org/jabref/gui/collab/ChangeScanner.java +++ b/src/main/java/org/jabref/gui/collab/ChangeScanner.java @@ -28,7 +28,7 @@ public ChangeScanner(BibDatabaseContext database, PreferencesService preferencesService) { this.database = database; this.preferencesService = preferencesService; - this.databaseChangeResolverFactory = new DatabaseChangeResolverFactory(dialogService, database, preferencesService.getBibEntryPreferences()); + this.databaseChangeResolverFactory = new DatabaseChangeResolverFactory(dialogService, database, preferencesService); } public List scanForChanges() { diff --git a/src/main/java/org/jabref/gui/collab/DatabaseChangeResolverFactory.java b/src/main/java/org/jabref/gui/collab/DatabaseChangeResolverFactory.java index 2aed7bb22ed..c27c7c600db 100644 --- a/src/main/java/org/jabref/gui/collab/DatabaseChangeResolverFactory.java +++ b/src/main/java/org/jabref/gui/collab/DatabaseChangeResolverFactory.java @@ -6,22 +6,22 @@ import org.jabref.gui.collab.entrychange.EntryChange; import org.jabref.gui.collab.entrychange.EntryChangeResolver; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.preferences.BibEntryPreferences; +import org.jabref.preferences.PreferencesService; public class DatabaseChangeResolverFactory { private final DialogService dialogService; private final BibDatabaseContext databaseContext; - private final BibEntryPreferences bibEntryPreferences; + private final PreferencesService preferencesService; - public DatabaseChangeResolverFactory(DialogService dialogService, BibDatabaseContext databaseContext, BibEntryPreferences bibEntryPreferences) { + public DatabaseChangeResolverFactory(DialogService dialogService, BibDatabaseContext databaseContext, PreferencesService preferencesService) { this.dialogService = dialogService; this.databaseContext = databaseContext; - this.bibEntryPreferences = bibEntryPreferences; + this.preferencesService = preferencesService; } public Optional create(DatabaseChange change) { if (change instanceof EntryChange entryChange) { - return Optional.of(new EntryChangeResolver(entryChange, dialogService, databaseContext, bibEntryPreferences)); + return Optional.of(new EntryChangeResolver(entryChange, dialogService, databaseContext, preferencesService)); } return Optional.empty(); diff --git a/src/main/java/org/jabref/gui/collab/DatabaseChangesResolverDialog.java b/src/main/java/org/jabref/gui/collab/DatabaseChangesResolverDialog.java index a0d5c3420cd..7dcb21b0bf4 100644 --- a/src/main/java/org/jabref/gui/collab/DatabaseChangesResolverDialog.java +++ b/src/main/java/org/jabref/gui/collab/DatabaseChangesResolverDialog.java @@ -88,7 +88,7 @@ public DatabaseChangesResolverDialog(List changes, BibDatabaseCo @FXML private void initialize() { - PreviewViewer previewViewer = new PreviewViewer(database, dialogService, stateManager, themeManager); + PreviewViewer previewViewer = new PreviewViewer(database, dialogService, preferencesService, stateManager, themeManager); DatabaseChangeDetailsViewFactory databaseChangeDetailsViewFactory = new DatabaseChangeDetailsViewFactory(database, dialogService, stateManager, themeManager, preferencesService, entryTypesManager, previewViewer); viewModel = new ExternalChangesResolverViewModel(changes, undoManager); diff --git a/src/main/java/org/jabref/gui/collab/entrychange/EntryChangeDetailsView.java b/src/main/java/org/jabref/gui/collab/entrychange/EntryChangeDetailsView.java index 7782a6919bc..880341921ef 100644 --- a/src/main/java/org/jabref/gui/collab/entrychange/EntryChangeDetailsView.java +++ b/src/main/java/org/jabref/gui/collab/entrychange/EntryChangeDetailsView.java @@ -30,7 +30,7 @@ public EntryChangeDetailsView(BibEntry oldEntry, BibEntry newEntry, BibDatabaseC onDisk.getStyleClass().add("lib-change-header"); // we need a copy here as we otherwise would set the same entry twice - PreviewViewer previewClone = new PreviewViewer(databaseContext, dialogService, stateManager, themeManager); + PreviewViewer previewClone = new PreviewViewer(databaseContext, dialogService, preferencesService, stateManager, themeManager); TabPane oldEntryTabPane = oldPreviewWithSourcesTab.getPreviewWithSourceTab(oldEntry, databaseContext, preferencesService, entryTypesManager, previewClone, Localization.lang("Entry Preview")); TabPane newEntryTabPane = newPreviewWithSourcesTab.getPreviewWithSourceTab(newEntry, databaseContext, preferencesService, entryTypesManager, previewViewer, Localization.lang("Entry Preview")); diff --git a/src/main/java/org/jabref/gui/collab/entrychange/EntryChangeResolver.java b/src/main/java/org/jabref/gui/collab/entrychange/EntryChangeResolver.java index 8e5575f4196..8555a2ec517 100644 --- a/src/main/java/org/jabref/gui/collab/entrychange/EntryChangeResolver.java +++ b/src/main/java/org/jabref/gui/collab/entrychange/EntryChangeResolver.java @@ -12,24 +12,24 @@ import org.jabref.gui.mergeentries.newmergedialog.toolbar.ThreeWayMergeToolbar; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.preferences.BibEntryPreferences; +import org.jabref.preferences.PreferencesService; public final class EntryChangeResolver extends DatabaseChangeResolver { private final EntryChange entryChange; private final BibDatabaseContext databaseContext; - private final BibEntryPreferences bibEntryPreferences; + private final PreferencesService preferencesService; - public EntryChangeResolver(EntryChange entryChange, DialogService dialogService, BibDatabaseContext databaseContext, BibEntryPreferences bibEntryPreferences) { + public EntryChangeResolver(EntryChange entryChange, DialogService dialogService, BibDatabaseContext databaseContext, PreferencesService preferencesService) { super(dialogService); this.entryChange = entryChange; this.databaseContext = databaseContext; - this.bibEntryPreferences = bibEntryPreferences; + this.preferencesService = preferencesService; } @Override public Optional askUserToResolveChange() { - MergeEntriesDialog mergeEntriesDialog = new MergeEntriesDialog(entryChange.getOldEntry(), entryChange.getNewEntry(), bibEntryPreferences); + MergeEntriesDialog mergeEntriesDialog = new MergeEntriesDialog(entryChange.getOldEntry(), entryChange.getNewEntry(), preferencesService); mergeEntriesDialog.setLeftHeaderText(Localization.lang("In JabRef")); mergeEntriesDialog.setRightHeaderText(Localization.lang("On disk")); mergeEntriesDialog.configureDiff(new ShowDiffConfig(ThreeWayMergeToolbar.DiffView.SPLIT, BasicDiffMethod.WORDS)); diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index 669d3c7ca71..5c4b332a029 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -25,6 +25,8 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.identifier.DOI; import org.jabref.model.entry.identifier.Identifier; +import org.jabref.preferences.ExternalApplicationsPreferences; +import org.jabref.preferences.FilePreferences; import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; @@ -81,10 +83,10 @@ public static void openExternalViewer(BibDatabaseContext databaseContext, } } } else if (StandardField.DOI == field) { - openDoi(link); + openDoi(link, preferencesService); return; } else if (StandardField.ISBN == field) { - openIsbn(link); + openIsbn(link, preferencesService); return; } else if (StandardField.EPRINT == field) { IdentifierParser identifierParser = new IdentifierParser(entry); @@ -106,16 +108,16 @@ public static void openExternalViewer(BibDatabaseContext databaseContext, } if (StandardField.URL == field) { - openBrowser(link); + openBrowser(link, preferencesService.getFilePreferences()); } else if (StandardField.PS == field) { try { - NATIVE_DESKTOP.openFile(link, StandardField.PS.getName()); + NATIVE_DESKTOP.openFile(link, StandardField.PS.getName(), preferencesService.getFilePreferences()); } catch (IOException e) { LOGGER.error("An error occurred on the command: " + link, e); } } else if (StandardField.PDF == field) { try { - NATIVE_DESKTOP.openFile(link, StandardField.PDF.getName()); + NATIVE_DESKTOP.openFile(link, StandardField.PDF.getName(), preferencesService.getFilePreferences()); } catch (IOException e) { LOGGER.error("An error occurred on the command: " + link, e); } @@ -124,9 +126,9 @@ public static void openExternalViewer(BibDatabaseContext databaseContext, } } - private static void openDoi(String doi) throws IOException { + private static void openDoi(String doi, PreferencesService preferencesService) throws IOException { String link = DOI.parse(doi).map(DOI::getURIAsASCIIString).orElse(doi); - openBrowser(link); + openBrowser(link, preferencesService.getFilePreferences()); } public static void openCustomDoi(String link, PreferencesService preferences, DialogService dialogService) { @@ -134,16 +136,16 @@ public static void openCustomDoi(String link, PreferencesService preferences, Di .flatMap(doi -> doi.getExternalURIWithCustomBase(preferences.getDOIPreferences().getDefaultBaseURI())) .ifPresent(uri -> { try { - JabRefDesktop.openBrowser(uri); + JabRefDesktop.openBrowser(uri, preferences.getFilePreferences()); } catch (IOException e) { dialogService.showErrorDialogAndWait(Localization.lang("Unable to open link."), e); } }); } - private static void openIsbn(String isbn) throws IOException { + private static void openIsbn(String isbn, PreferencesService preferencesService) throws IOException { String link = "https://openlibrary.org/isbn/" + isbn; - openBrowser(link); + openBrowser(link, preferencesService.getFilePreferences()); } /** @@ -154,40 +156,42 @@ private static void openIsbn(String isbn) throws IOException { * @return false if the link couldn't be resolved, true otherwise. */ public static boolean openExternalFileAnyFormat(final BibDatabaseContext databaseContext, - PreferencesService preferencesService, + FilePreferences filePreferences, String link, final Optional type) throws IOException { if (REMOTE_LINK_PATTERN.matcher(link.toLowerCase(Locale.ROOT)).matches()) { - openExternalFilePlatformIndependent(type, link); + openExternalFilePlatformIndependent(type, link, filePreferences); return true; } - Optional file = FileUtil.find(databaseContext, link, preferencesService.getFilePreferences()); + Optional file = FileUtil.find(databaseContext, link, filePreferences); if (file.isPresent() && Files.exists(file.get())) { // Open the file: String filePath = file.get().toString(); - openExternalFilePlatformIndependent(type, filePath); + openExternalFilePlatformIndependent(type, filePath, filePreferences); return true; } // No file matched the name, try to open it directly using the given app - openExternalFilePlatformIndependent(type, link); + openExternalFilePlatformIndependent(type, link, filePreferences); return true; } - private static void openExternalFilePlatformIndependent(Optional fileType, String filePath) + private static void openExternalFilePlatformIndependent(Optional fileType, + String filePath, + FilePreferences filePreferences) throws IOException { if (fileType.isPresent()) { String application = fileType.get().getOpenWithApplication(); if (application.isEmpty()) { - NATIVE_DESKTOP.openFile(filePath, fileType.get().getExtension()); + NATIVE_DESKTOP.openFile(filePath, fileType.get().getExtension(), filePreferences); } else { NATIVE_DESKTOP.openFileWithApplication(filePath, application); } } else { // File type is not given and therefore no application specified // Let the OS handle the opening of the file - NATIVE_DESKTOP.openFile(filePath, ""); + NATIVE_DESKTOP.openFile(filePath, "", filePreferences); } } @@ -197,18 +201,20 @@ private static void openExternalFilePlatformIndependent(Optional fileType = ExternalFileTypes.getExternalFileTypeByExt("html", Globals.prefs.getFilePreferences()); - openExternalFilePlatformIndependent(fileType, url); + public static void openBrowser(String url, FilePreferences filePreferences) throws IOException { + Optional fileType = ExternalFileTypes.getExternalFileTypeByExt("html", filePreferences); + openExternalFilePlatformIndependent(fileType, url, filePreferences); } - public static void openBrowser(URI url) throws IOException { - openBrowser(url.toASCIIString()); + public static void openBrowser(URI url, FilePreferences filePreferences) throws IOException { + openBrowser(url.toASCIIString(), filePreferences); } /** @@ -285,9 +291,9 @@ public static void openBrowser(URI url) throws IOException { * * @param url the URL to open */ - public static void openBrowserShowPopup(String url, DialogService dialogService) { + public static void openBrowserShowPopup(String url, DialogService dialogService, FilePreferences filePreferences) { try { - openBrowser(url); + openBrowser(url, filePreferences); } catch (IOException exception) { Globals.getClipboardManager().setContent(url); LOGGER.error("Could not open browser", exception); diff --git a/src/main/java/org/jabref/gui/desktop/os/DefaultDesktop.java b/src/main/java/org/jabref/gui/desktop/os/DefaultDesktop.java index 02608d60f7b..7ab380efcb7 100644 --- a/src/main/java/org/jabref/gui/desktop/os/DefaultDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/os/DefaultDesktop.java @@ -8,6 +8,7 @@ import org.jabref.architecture.AllowedToUseAwt; import org.jabref.cli.Launcher; import org.jabref.gui.DialogService; +import org.jabref.preferences.FilePreferences; import org.slf4j.LoggerFactory; @@ -21,7 +22,7 @@ public class DefaultDesktop extends NativeDesktop { @Override - public void openFile(String filePath, String fileType) throws IOException { + public void openFile(String filePath, String fileType, FilePreferences filePreferences) throws IOException { Desktop.getDesktop().open(new File(filePath)); } diff --git a/src/main/java/org/jabref/gui/desktop/os/Linux.java b/src/main/java/org/jabref/gui/desktop/os/Linux.java index 7ff673136bd..eba3745c0e9 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Linux.java +++ b/src/main/java/org/jabref/gui/desktop/os/Linux.java @@ -15,12 +15,12 @@ import org.jabref.architecture.AllowedToUseAwt; import org.jabref.cli.Launcher; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; import org.jabref.gui.JabRefExecutorService; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.util.StreamGobbler; import org.jabref.logic.l10n.Localization; +import org.jabref.preferences.FilePreferences; import org.slf4j.LoggerFactory; @@ -56,8 +56,8 @@ private void nativeOpenFile(String filePath) { } @Override - public void openFile(String filePath, String fileType) throws IOException { - Optional type = ExternalFileTypes.getExternalFileTypeByExt(fileType, Globals.prefs.getFilePreferences()); + public void openFile(String filePath, String fileType, FilePreferences filePreferences) throws IOException { + Optional type = ExternalFileTypes.getExternalFileTypeByExt(fileType, filePreferences); String viewer; if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) { diff --git a/src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java b/src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java index 29842c772dd..7e6c4c8fae4 100644 --- a/src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/os/NativeDesktop.java @@ -13,6 +13,7 @@ import org.jabref.logic.util.OS; import org.jabref.model.pdf.search.SearchFieldConstants; import org.jabref.model.strings.StringUtil; +import org.jabref.preferences.FilePreferences; import net.harawata.appdirs.AppDirsFactory; import org.slf4j.LoggerFactory; @@ -29,7 +30,7 @@ */ public abstract class NativeDesktop { - public abstract void openFile(String filePath, String fileType) throws IOException; + public abstract void openFile(String filePath, String fileType, FilePreferences filePreferences) throws IOException; /** * Opens a file on an Operating System, using the given application. diff --git a/src/main/java/org/jabref/gui/desktop/os/OSX.java b/src/main/java/org/jabref/gui/desktop/os/OSX.java index 84bad205b84..7adbd087927 100644 --- a/src/main/java/org/jabref/gui/desktop/os/OSX.java +++ b/src/main/java/org/jabref/gui/desktop/os/OSX.java @@ -7,9 +7,9 @@ import org.jabref.architecture.AllowedToUseAwt; import org.jabref.cli.Launcher; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; +import org.jabref.preferences.FilePreferences; /** * This class contains macOS (OSX) specific implementations for file directories and file/application open handling methods
@@ -21,8 +21,8 @@ public class OSX extends NativeDesktop { @Override - public void openFile(String filePath, String fileType) throws IOException { - Optional type = ExternalFileTypes.getExternalFileTypeByExt(fileType, Globals.prefs.getFilePreferences()); + public void openFile(String filePath, String fileType, FilePreferences filePreferences) throws IOException { + Optional type = ExternalFileTypes.getExternalFileTypeByExt(fileType, filePreferences); if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) { openFileWithApplication(filePath, type.get().getOpenWithApplication()); } else { diff --git a/src/main/java/org/jabref/gui/desktop/os/Windows.java b/src/main/java/org/jabref/gui/desktop/os/Windows.java index 994bc785c90..bacf32f6406 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Windows.java +++ b/src/main/java/org/jabref/gui/desktop/os/Windows.java @@ -8,9 +8,9 @@ import org.jabref.cli.Launcher; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; +import org.jabref.preferences.FilePreferences; import com.sun.jna.platform.win32.KnownFolders; import com.sun.jna.platform.win32.Shell32Util; @@ -29,8 +29,8 @@ public class Windows extends NativeDesktop { private static final String DEFAULT_EXECUTABLE_EXTENSION = ".exe"; @Override - public void openFile(String filePath, String fileType) throws IOException { - Optional type = ExternalFileTypes.getExternalFileTypeByExt(fileType, Globals.prefs.getFilePreferences()); + public void openFile(String filePath, String fileType, FilePreferences filePreferences) throws IOException { + Optional type = ExternalFileTypes.getExternalFileTypeByExt(fileType, filePreferences); if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) { openFileWithApplication(filePath, type.get().getOpenWithApplication()); diff --git a/src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java b/src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java index a7bc85890ee..56fe6777872 100644 --- a/src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java +++ b/src/main/java/org/jabref/gui/dialogs/AutosaveUiManager.java @@ -1,9 +1,10 @@ package org.jabref.gui.dialogs; -import org.jabref.gui.Globals; import org.jabref.gui.LibraryTab; import org.jabref.gui.exporter.SaveDatabaseAction; import org.jabref.model.database.event.AutosaveEvent; +import org.jabref.model.entry.BibEntryTypesManager; +import org.jabref.preferences.PreferencesService; import com.google.common.eventbus.Subscribe; import org.slf4j.Logger; @@ -16,10 +17,10 @@ public class AutosaveUiManager { private static final Logger LOGGER = LoggerFactory.getLogger(AutosaveUiManager.class); - private SaveDatabaseAction saveDatabaseAction; + private final SaveDatabaseAction saveDatabaseAction; - public AutosaveUiManager(LibraryTab libraryTab) { - this.saveDatabaseAction = new SaveDatabaseAction(libraryTab, Globals.prefs, Globals.entryTypesManager); + public AutosaveUiManager(LibraryTab libraryTab, PreferencesService preferencesService, BibEntryTypesManager entryTypesManager) { + this.saveDatabaseAction = new SaveDatabaseAction(libraryTab, preferencesService, entryTypesManager); } @Subscribe diff --git a/src/main/java/org/jabref/gui/dialogs/BackupUIManager.java b/src/main/java/org/jabref/gui/dialogs/BackupUIManager.java index 6291f5b779a..e416615ad23 100644 --- a/src/main/java/org/jabref/gui/dialogs/BackupUIManager.java +++ b/src/main/java/org/jabref/gui/dialogs/BackupUIManager.java @@ -23,6 +23,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.util.DummyFileUpdateMonitor; import org.jabref.model.util.FileUpdateMonitor; +import org.jabref.preferences.ExternalApplicationsPreferences; import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; @@ -41,7 +42,11 @@ public static Optional showRestoreBackupDialog(DialogService dialo Path originalPath, PreferencesService preferencesService, FileUpdateMonitor fileUpdateMonitor) { - var actionOpt = showBackupResolverDialog(dialogService, originalPath, preferencesService.getFilePreferences().getBackupDirectory()); + var actionOpt = showBackupResolverDialog( + dialogService, + preferencesService.getExternalApplicationsPreferences(), + originalPath, + preferencesService.getFilePreferences().getBackupDirectory()); return actionOpt.flatMap(action -> { if (action == BackupResolverDialog.RESTORE_FROM_BACKUP) { BackupManager.restoreBackup(originalPath, preferencesService.getFilePreferences().getBackupDirectory()); @@ -53,8 +58,12 @@ public static Optional showRestoreBackupDialog(DialogService dialo }); } - private static Optional showBackupResolverDialog(DialogService dialogService, Path originalPath, Path backupDir) { - return DefaultTaskExecutor.runInJavaFXThread(() -> dialogService.showCustomDialogAndWait(new BackupResolverDialog(originalPath, backupDir))); + private static Optional showBackupResolverDialog(DialogService dialogService, + ExternalApplicationsPreferences externalApplicationsPreferences, + Path originalPath, + Path backupDir) { + return DefaultTaskExecutor.runInJavaFXThread( + () -> dialogService.showCustomDialogAndWait(new BackupResolverDialog(originalPath, backupDir, externalApplicationsPreferences))); } private static Optional showReviewBackupDialog( @@ -73,7 +82,7 @@ private static Optional showReviewBackupDialog( Path backupPath = BackupFileUtil.getPathOfLatestExistingBackupFile(originalPath, BackupFileType.BACKUP, preferencesService.getFilePreferences().getBackupDirectory()).orElseThrow(); BibDatabaseContext backupDatabase = OpenDatabase.loadDatabase(backupPath, importFormatPreferences, new DummyFileUpdateMonitor()).getDatabaseContext(); - DatabaseChangeResolverFactory changeResolverFactory = new DatabaseChangeResolverFactory(dialogService, originalDatabase, preferencesService.getBibEntryPreferences()); + DatabaseChangeResolverFactory changeResolverFactory = new DatabaseChangeResolverFactory(dialogService, originalDatabase, preferencesService); return DefaultTaskExecutor.runInJavaFXThread(() -> { List changes = DatabaseChangeList.compareAndGetChanges(originalDatabase, backupDatabase, changeResolverFactory); diff --git a/src/main/java/org/jabref/gui/duplicationFinder/DuplicateResolverDialog.java b/src/main/java/org/jabref/gui/duplicationFinder/DuplicateResolverDialog.java index 063cad00abb..9cdf97b0de9 100644 --- a/src/main/java/org/jabref/gui/duplicationFinder/DuplicateResolverDialog.java +++ b/src/main/java/org/jabref/gui/duplicationFinder/DuplicateResolverDialog.java @@ -77,21 +77,21 @@ private void init(BibEntry one, BibEntry two, DuplicateResolverType type) { first = new ButtonType(Localization.lang("Keep left"), ButtonData.LEFT); second = new ButtonType(Localization.lang("Keep right"), ButtonData.LEFT); both = new ButtonType(Localization.lang("Keep both"), ButtonData.LEFT); - threeWayMerge = new ThreeWayMergeView(one, two, preferencesService.getBibEntryPreferences()); + threeWayMerge = new ThreeWayMergeView(one, two, preferencesService); } case DUPLICATE_SEARCH_WITH_EXACT -> { first = new ButtonType(Localization.lang("Keep left"), ButtonData.LEFT); second = new ButtonType(Localization.lang("Keep right"), ButtonData.LEFT); both = new ButtonType(Localization.lang("Keep both"), ButtonData.LEFT); removeExactVisible = true; - threeWayMerge = new ThreeWayMergeView(one, two, preferencesService.getBibEntryPreferences()); + threeWayMerge = new ThreeWayMergeView(one, two, preferencesService); } case IMPORT_CHECK -> { first = new ButtonType(Localization.lang("Keep old entry"), ButtonData.LEFT); second = new ButtonType(Localization.lang("Keep from import"), ButtonData.LEFT); both = new ButtonType(Localization.lang("Keep both"), ButtonData.LEFT); threeWayMerge = new ThreeWayMergeView(one, two, Localization.lang("Old entry"), - Localization.lang("From import"), preferencesService.getBibEntryPreferences()); + Localization.lang("From import"), preferencesService); } default -> throw new IllegalStateException("Switch expression should be exhaustive"); } @@ -138,7 +138,7 @@ private void init(BibEntry one, BibEntry two, DuplicateResolverType type) { return null; }); - HelpAction helpCommand = new HelpAction(HelpFile.FIND_DUPLICATES, dialogService); + HelpAction helpCommand = new HelpAction(HelpFile.FIND_DUPLICATES, dialogService, preferencesService.getFilePreferences()); Button helpButton = actionFactory.createIconButton(StandardActions.HELP, helpCommand); borderPane.setRight(helpButton); diff --git a/src/main/java/org/jabref/gui/edit/OpenBrowserAction.java b/src/main/java/org/jabref/gui/edit/OpenBrowserAction.java index c6eb7653ae8..967ffef9e42 100644 --- a/src/main/java/org/jabref/gui/edit/OpenBrowserAction.java +++ b/src/main/java/org/jabref/gui/edit/OpenBrowserAction.java @@ -3,19 +3,22 @@ import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.desktop.JabRefDesktop; +import org.jabref.preferences.FilePreferences; public class OpenBrowserAction extends SimpleCommand { private final String urlToOpen; private final DialogService dialogService; + private final FilePreferences filePreferences; - public OpenBrowserAction(String urlToOpen, DialogService dialogService) { + public OpenBrowserAction(String urlToOpen, DialogService dialogService, FilePreferences filePreferences) { this.urlToOpen = urlToOpen; this.dialogService = dialogService; + this.filePreferences = filePreferences; } @Override public void execute() { - JabRefDesktop.openBrowserShowPopup(urlToOpen, dialogService); + JabRefDesktop.openBrowserShowPopup(urlToOpen, dialogService, filePreferences); } } diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index b8d412dc594..349f01cded2 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -197,7 +197,7 @@ private void setupKeyBindings() { event.consume(); break; case HELP: - new HelpAction(HelpFile.ENTRY_EDITOR, dialogService).execute(); + new HelpAction(HelpFile.ENTRY_EDITOR, dialogService, preferencesService.getFilePreferences()).execute(); event.consume(); break; case CLOSE: @@ -291,6 +291,7 @@ private List createTabs() { fileMonitor, dialogService, stateManager, + bibEntryTypesManager, keyBindingRepository); entryEditorTabs.add(sourceTab); diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index c0e22a5b66a..08047d1aae9 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -128,7 +128,7 @@ private ScrollPane getRelatedArticleInfo(List list, MrDLibFetcher fetc titleLink.setOnAction(event -> { if (entry.getField(StandardField.URL).isPresent()) { try { - JabRefDesktop.openBrowser(entry.getField(StandardField.URL).get()); + JabRefDesktop.openBrowser(entry.getField(StandardField.URL).get(), preferencesService.getFilePreferences()); } catch (IOException e) { LOGGER.error("Error opening the browser to: " + entry.getField(StandardField.URL).get(), e); dialogService.showErrorDialogAndWait(e); @@ -192,7 +192,7 @@ private ScrollPane getPrivacyDialog(BibEntry entry) { Hyperlink mdlLink = new Hyperlink(Localization.lang("Further information about Mr. DLib for JabRef users.")); mdlLink.setOnAction(event -> { try { - JabRefDesktop.openBrowser("http://mr-dlib.org/information-for-users/information-about-mr-dlib-for-jabref-users/"); + JabRefDesktop.openBrowser("http://mr-dlib.org/information-for-users/information-about-mr-dlib-for-jabref-users/", preferencesService.getFilePreferences()); } catch (IOException e) { LOGGER.error("Error opening the browser to Mr. DLib information page.", e); dialogService.showErrorDialogAndWait(e); diff --git a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java index 9bf912248e8..05c8f94a8a3 100644 --- a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java @@ -21,7 +21,6 @@ import javafx.scene.input.KeyEvent; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.SimpleCommand; @@ -49,6 +48,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.Field; import org.jabref.model.util.FileUpdateMonitor; @@ -72,8 +72,9 @@ public class SourceTab extends EntryEditorTab { private final FileUpdateMonitor fileMonitor; private final DialogService dialogService; private final StateManager stateManager; - private Optional searchHighlightPattern = Optional.empty(); + private final BibEntryTypesManager entryTypesManager; private final KeyBindingRepository keyBindingRepository; + private Optional searchHighlightPattern = Optional.empty(); private CodeArea codeArea; private BibEntry previousEntry; @@ -98,7 +99,15 @@ public void execute() { } } - public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager, FieldPreferences fieldPreferences, ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor, DialogService dialogService, StateManager stateManager, KeyBindingRepository keyBindingRepository) { + public SourceTab(BibDatabaseContext bibDatabaseContext, + CountingUndoManager undoManager, + FieldPreferences fieldPreferences, + ImportFormatPreferences importFormatPreferences, + FileUpdateMonitor fileMonitor, + DialogService dialogService, + StateManager stateManager, + BibEntryTypesManager entryTypesManager, + KeyBindingRepository keyBindingRepository) { this.mode = bibDatabaseContext.getMode(); this.setText(Localization.lang("%0 source", mode.getFormattedName())); this.setTooltip(new Tooltip(Localization.lang("Show/edit %0 source", mode.getFormattedName()))); @@ -109,6 +118,7 @@ public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undo this.fileMonitor = fileMonitor; this.dialogService = dialogService; this.stateManager = stateManager; + this.entryTypesManager = entryTypesManager; this.keyBindingRepository = keyBindingRepository; stateManager.activeSearchQueryProperty().addListener((observable, oldValue, newValue) -> { @@ -133,7 +143,7 @@ private String getSourceString(BibEntry entry, BibDatabaseMode type, FieldPrefer StringWriter writer = new StringWriter(); BibWriter bibWriter = new BibWriter(writer, OS.NEWLINE); FieldWriter fieldWriter = FieldWriter.buildIgnoreHashes(fieldPreferences); - new BibEntryWriter(fieldWriter, Globals.entryTypesManager).write(entry, bibWriter, type); + new BibEntryWriter(fieldWriter, entryTypesManager).write(entry, bibWriter, type); return writer.toString(); } diff --git a/src/main/java/org/jabref/gui/entryeditor/fileannotationtab/FulltextSearchResultsTab.java b/src/main/java/org/jabref/gui/entryeditor/fileannotationtab/FulltextSearchResultsTab.java index 539307e3152..9058e549768 100644 --- a/src/main/java/org/jabref/gui/entryeditor/fileannotationtab/FulltextSearchResultsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/fileannotationtab/FulltextSearchResultsTab.java @@ -127,7 +127,7 @@ private Text createFileLink(String pathToFile) { fileLinkText.setOnMouseClicked(event -> { if (MouseButton.PRIMARY.equals(event.getButton())) { try { - JabRefDesktop.openBrowser(resolvedPath.toUri()); + JabRefDesktop.openBrowser(resolvedPath.toUri(), preferencesService.getFilePreferences()); } catch (IOException e) { LOGGER.error("Cannot open {}.", resolvedPath.toString(), e); } diff --git a/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleView.java b/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleView.java index e29940c7717..daf9fb35fe9 100644 --- a/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleView.java +++ b/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleView.java @@ -26,6 +26,7 @@ import org.jabref.gui.util.ControlHelper; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.BuildInfo; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; import jakarta.inject.Inject; @@ -41,6 +42,7 @@ public class ErrorConsoleView extends BaseDialog { @FXML private Label descriptionLabel; @Inject private DialogService dialogService; + @Inject private PreferencesService preferencesService; @Inject private ClipBoardManager clipBoardManager; @Inject private BuildInfo buildInfo; @Inject private KeyBindingRepository keyBindingRepository; @@ -63,7 +65,7 @@ public ErrorConsoleView() { @FXML private void initialize() { - viewModel = new ErrorConsoleViewModel(dialogService, clipBoardManager, buildInfo); + viewModel = new ErrorConsoleViewModel(dialogService, preferencesService, clipBoardManager, buildInfo); messagesListView.setCellFactory(createCellFactory()); messagesListView.itemsProperty().bind(viewModel.allMessagesDataProperty()); messagesListView.scrollTo(viewModel.allMessagesDataProperty().getSize() - 1); diff --git a/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleViewModel.java b/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleViewModel.java index 959224f3a5d..5f346cdcd4e 100644 --- a/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleViewModel.java +++ b/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleViewModel.java @@ -19,6 +19,7 @@ import org.jabref.logic.logging.LogMessages; import org.jabref.logic.util.BuildInfo; import org.jabref.logic.util.OS; +import org.jabref.preferences.PreferencesService; import com.tobiasdiez.easybind.EasyBind; import org.apache.http.client.utils.URIBuilder; @@ -30,12 +31,14 @@ public class ErrorConsoleViewModel extends AbstractViewModel { private static final Logger LOGGER = LoggerFactory.getLogger(ErrorConsoleViewModel.class); private final DialogService dialogService; + private final PreferencesService preferencesService; private final ClipBoardManager clipBoardManager; private final BuildInfo buildInfo; private final ListProperty allMessagesData; - public ErrorConsoleViewModel(DialogService dialogService, ClipBoardManager clipBoardManager, BuildInfo buildInfo) { + public ErrorConsoleViewModel(DialogService dialogService, PreferencesService preferencesService, ClipBoardManager clipBoardManager, BuildInfo buildInfo) { this.dialogService = Objects.requireNonNull(dialogService); + this.preferencesService = Objects.requireNonNull(preferencesService); this.clipBoardManager = Objects.requireNonNull(clipBoardManager); this.buildInfo = Objects.requireNonNull(buildInfo); ObservableList eventViewModels = EasyBind.map(BindingsHelper.forUI(LogMessages.getInstance().getMessages()), LogEventViewModel::new); @@ -47,7 +50,7 @@ public ListProperty allMessagesDataProperty() { } /** - * Concatenates the formatted message of the given {@link LogEvent}s by using the a new line separator. + * Concatenates the formatted message of the given {@link LogEventViewModel}s by using a new line separator. * * @return all messages as String */ @@ -65,7 +68,7 @@ public void copyLog() { } /** - * Copies the given list of {@link LogEvent}s to the clipboard. + * Copies the given list of {@link LogEventViewModel}s to the clipboard. */ public void copyLog(List messages) { if (messages.isEmpty()) { @@ -110,7 +113,7 @@ public void reportIssue() { .setScheme("https").setHost("github.com") .setPath("/JabRef/jabref/issues/new") .setParameter("body", issueBody); - JabRefDesktop.openBrowser(uriBuilder.build().toString()); + JabRefDesktop.openBrowser(uriBuilder.build().toString(), preferencesService.getFilePreferences()); } catch (IOException | URISyntaxException e) { LOGGER.error("Problem opening url", e); } diff --git a/src/main/java/org/jabref/gui/exporter/ExportCommand.java b/src/main/java/org/jabref/gui/exporter/ExportCommand.java index b120ba1aed2..96eebc80160 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCommand.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCommand.java @@ -130,7 +130,7 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt Localization.lang("Export operation finished successfully."), List.of(new Action(Localization.lang("Reveal in File Explorer"), event -> { try { - JabRefDesktop.openFolderAndSelectFile(file, preferences, dialogService); + JabRefDesktop.openFolderAndSelectFile(file, preferences.getExternalApplicationsPreferences(), dialogService); } catch (IOException e) { LOGGER.error("Could not open export folder.", e); } diff --git a/src/main/java/org/jabref/gui/exporter/WriteMetadataToPdfAction.java b/src/main/java/org/jabref/gui/exporter/WriteMetadataToPdfAction.java index 44d1b56bf7c..6e579b4965a 100644 --- a/src/main/java/org/jabref/gui/exporter/WriteMetadataToPdfAction.java +++ b/src/main/java/org/jabref/gui/exporter/WriteMetadataToPdfAction.java @@ -21,13 +21,13 @@ import org.jabref.gui.DialogService; import org.jabref.gui.FXDialog; -import org.jabref.gui.Globals; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.bibtex.FieldPreferences; import org.jabref.logic.exporter.EmbeddedBibFilePdfExporter; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.io.FileUtil; import org.jabref.logic.xmp.XmpPreferences; @@ -49,6 +49,7 @@ public class WriteMetadataToPdfAction extends SimpleCommand { private final TaskExecutor taskExecutor; private final FilePreferences filePreferences; private final XmpPreferences xmpPreferences; + private final JournalAbbreviationRepository abbreviationRepository; private OptionsDialog optionsDialog; @@ -60,7 +61,14 @@ public class WriteMetadataToPdfAction extends SimpleCommand { private int entriesChanged; private int errors; - public WriteMetadataToPdfAction(StateManager stateManager, BibEntryTypesManager entryTypesManager, FieldPreferences fieldPreferences, DialogService dialogService, TaskExecutor taskExecutor, FilePreferences filePreferences, XmpPreferences xmpPreferences) { + public WriteMetadataToPdfAction(StateManager stateManager, + BibEntryTypesManager entryTypesManager, + FieldPreferences fieldPreferences, + DialogService dialogService, + TaskExecutor taskExecutor, + FilePreferences filePreferences, + XmpPreferences xmpPreferences, + JournalAbbreviationRepository abbreviationRepository) { this.stateManager = stateManager; this.entryTypesManager = entryTypesManager; this.fieldPreferences = fieldPreferences; @@ -68,6 +76,7 @@ public WriteMetadataToPdfAction(StateManager stateManager, BibEntryTypesManager this.taskExecutor = taskExecutor; this.filePreferences = filePreferences; this.xmpPreferences = xmpPreferences; + this.abbreviationRepository = abbreviationRepository; this.executable.bind(needsDatabase(stateManager)); } @@ -197,7 +206,7 @@ synchronized private void writeMetadataToFile(Path file, BibEntry entry, BibData new XmpUtilWriter(xmpPreferences).writeXmp(file, entry, database); EmbeddedBibFilePdfExporter embeddedBibExporter = new EmbeddedBibFilePdfExporter(databaseContext.getMode(), entryTypesManager, fieldPreferences); - embeddedBibExporter.exportToFileByPath(databaseContext, database, filePreferences, file, Globals.journalAbbreviationRepository); + embeddedBibExporter.exportToFileByPath(databaseContext, filePreferences, file, abbreviationRepository); } class OptionsDialog extends FXDialog { diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 8124240b4a2..b82dca6afed 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -82,7 +82,7 @@ public class LinkedFileViewModel extends AbstractViewModel { private final DialogService dialogService; private final BibEntry entry; private final TaskExecutor taskExecutor; - private final PreferencesService preferences; + private final PreferencesService preferencesService; private final LinkedFileHandler linkedFileHandler; private ObjectBinding linkedFileIconBinding; @@ -94,11 +94,11 @@ public LinkedFileViewModel(LinkedFile linkedFile, BibDatabaseContext databaseContext, TaskExecutor taskExecutor, DialogService dialogService, - PreferencesService preferences) { + PreferencesService preferencesService) { this.linkedFile = linkedFile; - this.preferences = preferences; - this.linkedFileHandler = new LinkedFileHandler(linkedFile, entry, databaseContext, preferences.getFilePreferences()); + this.preferencesService = preferencesService; + this.linkedFileHandler = new LinkedFileHandler(linkedFile, entry, databaseContext, preferencesService.getFilePreferences()); this.databaseContext = databaseContext; this.entry = entry; this.dialogService = dialogService; @@ -110,7 +110,7 @@ public LinkedFileViewModel(LinkedFile linkedFile, if (linkedFile.isOnlineLink()) { return true; } else { - Optional path = FileUtil.find(databaseContext, link, preferences.getFilePreferences()); + Optional path = FileUtil.find(databaseContext, link, preferencesService.getFilePreferences()); return path.isPresent() && Files.exists(path.get()); } }, @@ -177,7 +177,7 @@ public Optional findIn(List directories) { } public JabRefIcon getTypeIcon() { - return ExternalFileTypes.getExternalFileTypeByLinkedFile(linkedFile, false, preferences.getFilePreferences()) + return ExternalFileTypes.getExternalFileTypeByLinkedFile(linkedFile, false, preferencesService.getFilePreferences()) .map(ExternalFileType::getIcon) .orElse(IconTheme.JabRefIcons.FILE); } @@ -208,8 +208,8 @@ public Observable[] getObservables() { public void open() { try { - Optional type = ExternalFileTypes.getExternalFileTypeByLinkedFile(linkedFile, true, preferences.getFilePreferences()); - boolean successful = JabRefDesktop.openExternalFileAnyFormat(databaseContext, preferences, linkedFile.getLink(), type); + Optional type = ExternalFileTypes.getExternalFileTypeByLinkedFile(linkedFile, true, preferencesService.getFilePreferences()); + boolean successful = JabRefDesktop.openExternalFileAnyFormat(databaseContext, preferencesService.getFilePreferences(), linkedFile.getLink(), type); if (!successful) { dialogService.showErrorDialogAndWait(Localization.lang("File not found"), Localization.lang("Could not find file '%0'.", linkedFile.getLink())); } @@ -224,9 +224,9 @@ public void openFolder() { Optional resolvedPath = FileUtil.find( databaseContext, linkedFile.getLink(), - preferences.getFilePreferences()); + preferencesService.getFilePreferences()); if (resolvedPath.isPresent()) { - JabRefDesktop.openFolderAndSelectFile(resolvedPath.get(), preferences, dialogService); + JabRefDesktop.openFolderAndSelectFile(resolvedPath.get(), preferencesService.getExternalApplicationsPreferences(), dialogService); } else { dialogService.showErrorDialogAndWait(Localization.lang("File not found")); } @@ -258,7 +258,7 @@ public void renameFileToName(String targetFileName) { return; } - Optional file = linkedFile.findIn(databaseContext, preferences.getFilePreferences()); + Optional file = linkedFile.findIn(databaseContext, preferencesService.getFilePreferences()); if (file.isPresent()) { performRenameWithConflictCheck(targetFileName); } else { @@ -295,13 +295,13 @@ public void moveToDefaultDirectory() { } // Get target folder - Optional fileDir = databaseContext.getFirstExistingFileDir(preferences.getFilePreferences()); + Optional fileDir = databaseContext.getFirstExistingFileDir(preferencesService.getFilePreferences()); if (fileDir.isEmpty()) { dialogService.showErrorDialogAndWait(Localization.lang("Move file"), Localization.lang("File directory is not set or does not exist!")); return; } - Optional file = linkedFile.findIn(databaseContext, preferences.getFilePreferences()); + Optional file = linkedFile.findIn(databaseContext, preferencesService.getFilePreferences()); if (file.isPresent()) { // Found the linked file, so move it try { @@ -337,7 +337,7 @@ public boolean isGeneratedNameSameAsOriginal() { * @return true if suggested filepath is same as existing filepath. */ public boolean isGeneratedPathSameAsOriginal() { - FilePreferences filePreferences = preferences.getFilePreferences(); + FilePreferences filePreferences = preferencesService.getFilePreferences(); Optional baseDir = databaseContext.getFirstExistingFileDir(filePreferences); if (baseDir.isEmpty()) { // could not find default path @@ -352,7 +352,7 @@ public boolean isGeneratedPathSameAsOriginal() { Optional targetDir = baseDir.map(dir -> dir.resolve(targetDirectoryName)); - Optional currentDir = linkedFile.findIn(databaseContext, preferences.getFilePreferences()).map(Path::getParent); + Optional currentDir = linkedFile.findIn(databaseContext, preferencesService.getFilePreferences()).map(Path::getParent); if (currentDir.isEmpty()) { // Could not find file return false; @@ -380,7 +380,7 @@ public void moveToDefaultDirectoryAndRename() { * successfully, does not exist in the first place or the user choose to remove it) */ public boolean delete() { - Optional file = linkedFile.findIn(databaseContext, preferences.getFilePreferences()); + Optional file = linkedFile.findIn(databaseContext, preferencesService.getFilePreferences()); if (file.isEmpty()) { LOGGER.warn("Could not find file {}", linkedFile.getLink()); @@ -421,16 +421,12 @@ public void edit() { }); } - public WriteMetadataToPdfCommand createWriteMetadataToPdfCommand() { - return new WriteMetadataToPdfCommand(linkedFile, databaseContext, preferences, dialogService, entry, LOGGER, taskExecutor); - } - public void download() { if (!linkedFile.isOnlineLink()) { throw new UnsupportedOperationException("In order to download the file it has to be an online link"); } try { - Optional targetDirectory = databaseContext.getFirstExistingFileDir(preferences.getFilePreferences()); + Optional targetDirectory = databaseContext.getFirstExistingFileDir(preferencesService.getFilePreferences()); if (targetDirectory.isEmpty()) { dialogService.showErrorDialogAndWait(Localization.lang("Download file"), Localization.lang("File directory is not set or does not exist!")); return; @@ -455,8 +451,8 @@ public void download() { // we need to call LinkedFileViewModel#fromFile, because we need to make the path relative to the configured directories LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile( destination, - databaseContext.getFileDirectories(preferences.getFilePreferences()), - preferences.getFilePreferences()); + databaseContext.getFileDirectories(preferencesService.getFilePreferences()), + preferencesService.getFilePreferences()); entry.replaceDownloadedFile(linkedFile.getLink(), newLinkedFile); // Notify in bar when the file type is HTML. @@ -512,7 +508,7 @@ public BackgroundTask prepareDownloadTask(Path targetDirectory, URLDownloa ExternalFileType externalFileType = suggestedType.orElse(StandardExternalFileType.PDF); String suggestedName = linkedFileHandler.getSuggestedFileName(externalFileType.getExtension()); - String fulltextDir = FileUtil.createDirNameFromPattern(databaseContext.getDatabase(), entry, preferences.getFilePreferences().getFileDirectoryPattern()); + String fulltextDir = FileUtil.createDirNameFromPattern(databaseContext.getDatabase(), entry, preferencesService.getFilePreferences().getFileDirectoryPattern()); suggestedName = FileNameUniqueness.getNonOverWritingFileName(targetDirectory.resolve(fulltextDir), suggestedName); return targetDirectory.resolve(fulltextDir).resolve(suggestedName); }) @@ -536,15 +532,15 @@ private Optional inferFileTypeFromMimeType(URLDownload urlDown if (mimeType != null) { LOGGER.debug("MIME Type suggested: " + mimeType); - return ExternalFileTypes.getExternalFileTypeByMimeType(mimeType, preferences.getFilePreferences()); + return ExternalFileTypes.getExternalFileTypeByMimeType(mimeType, preferencesService.getFilePreferences()); } else { return Optional.empty(); } } private Optional inferFileTypeFromURL(String url) { - return URLUtil.getSuffix(url, preferences.getFilePreferences()) - .flatMap(extension -> ExternalFileTypes.getExternalFileTypeByExt(extension, preferences.getFilePreferences())); + return URLUtil.getSuffix(url, preferencesService.getFilePreferences()) + .flatMap(extension -> ExternalFileTypes.getExternalFileTypeByExt(extension, preferencesService.getFilePreferences())); } public LinkedFile getFile() { @@ -556,17 +552,17 @@ public ValidationStatus fileExistsValidationStatus() { } public void parsePdfMetadataAndShowMergeDialog() { - linkedFile.findIn(databaseContext, preferences.getFilePreferences()).ifPresent(filePath -> { - MultiMergeEntriesView dialog = new MultiMergeEntriesView(preferences, taskExecutor); + linkedFile.findIn(databaseContext, preferencesService.getFilePreferences()).ifPresent(filePath -> { + MultiMergeEntriesView dialog = new MultiMergeEntriesView(preferencesService, taskExecutor); dialog.setTitle(Localization.lang("Merge PDF metadata")); dialog.addSource(Localization.lang("Entry"), entry); - dialog.addSource(Localization.lang("Verbatim"), wrapImporterToSupplier(new PdfVerbatimBibTextImporter(preferences.getImportFormatPreferences()), filePath)); - dialog.addSource(Localization.lang("Embedded"), wrapImporterToSupplier(new PdfEmbeddedBibFileImporter(preferences.getImportFormatPreferences()), filePath)); - if (preferences.getGrobidPreferences().isGrobidEnabled()) { - dialog.addSource("Grobid", wrapImporterToSupplier(new PdfGrobidImporter(preferences.getImportFormatPreferences()), filePath)); + dialog.addSource(Localization.lang("Verbatim"), wrapImporterToSupplier(new PdfVerbatimBibTextImporter(preferencesService.getImportFormatPreferences()), filePath)); + dialog.addSource(Localization.lang("Embedded"), wrapImporterToSupplier(new PdfEmbeddedBibFileImporter(preferencesService.getImportFormatPreferences()), filePath)); + if (preferencesService.getGrobidPreferences().isGrobidEnabled()) { + dialog.addSource("Grobid", wrapImporterToSupplier(new PdfGrobidImporter(preferencesService.getImportFormatPreferences()), filePath)); } - dialog.addSource(Localization.lang("XMP metadata"), wrapImporterToSupplier(new PdfXmpImporter(preferences.getXmpPreferences()), filePath)); - dialog.addSource(Localization.lang("Content"), wrapImporterToSupplier(new PdfContentImporter(preferences.getImportFormatPreferences()), filePath)); + dialog.addSource(Localization.lang("XMP metadata"), wrapImporterToSupplier(new PdfXmpImporter(preferencesService.getXmpPreferences()), filePath)); + dialog.addSource(Localization.lang("Content"), wrapImporterToSupplier(new PdfContentImporter(preferencesService.getImportFormatPreferences()), filePath)); dialogService.showCustomDialogAndWait(dialog).ifPresent(newEntry -> { databaseContext.getDatabase().removeEntry(entry); databaseContext.getDatabase().insertEntry(newEntry); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index 7a44a9e758a..2f687be78e1 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -47,9 +47,11 @@ import org.jabref.gui.util.ViewModelListCellFactory; import org.jabref.gui.util.uithreadaware.UiThreadObservableList; import org.jabref.logic.integrity.FieldCheckers; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.LinkedFile; import org.jabref.model.entry.field.Field; import org.jabref.preferences.PreferencesService; @@ -71,6 +73,8 @@ public class LinkedFilesEditor extends HBox implements FieldEditorFX { @Inject private DialogService dialogService; @Inject private PreferencesService preferencesService; + @Inject private BibEntryTypesManager bibEntryTypesManager; + @Inject private JournalAbbreviationRepository abbreviationRepository; @Inject private TaskExecutor taskExecutor; private LinkedFilesEditorViewModel viewModel; @@ -203,8 +207,14 @@ private Node createFileDisplay(LinkedFileViewModel linkedFile) { writeMetadataToPdf.setTooltip(new Tooltip(Localization.lang("Write BibTeXEntry metadata to PDF."))); writeMetadataToPdf.visibleProperty().bind(linkedFile.isOfflinePdfProperty()); writeMetadataToPdf.getStyleClass().setAll("icon-button"); - - WriteMetadataToPdfCommand writeMetadataToPdfCommand = linkedFile.createWriteMetadataToPdfCommand(); + WriteMetadataToPdfCommand writeMetadataToPdfCommand = new WriteMetadataToPdfCommand( + linkedFile.getFile(), + bibEntry.getValueOrElse(new BibEntry()), databaseContext, + dialogService, + preferencesService, + bibEntryTypesManager, + abbreviationRepository, + taskExecutor); writeMetadataToPdf.disableProperty().bind(writeMetadataToPdfCommand.executableProperty().not()); writeMetadataToPdf.setOnAction(event -> writeMetadataToPdfCommand.execute()); diff --git a/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java b/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java index 8510b5fe95f..4a71d689c6f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/UrlEditor.java @@ -30,8 +30,8 @@ public UrlEditor(Field field, DialogService dialogService, SuggestionProvider suggestionProvider, FieldCheckers fieldCheckers, - PreferencesService preferences) { - this.viewModel = new UrlEditorViewModel(field, suggestionProvider, dialogService, fieldCheckers); + PreferencesService preferencesService) { + this.viewModel = new UrlEditorViewModel(field, suggestionProvider, dialogService, preferencesService, fieldCheckers); ViewLoader.view(this) .root(this) @@ -44,7 +44,7 @@ public UrlEditor(Field field, // init paste handler for UrlEditor to format pasted url link in textArea textArea.setPasteActionHandler(() -> textArea.setText(new CleanupUrlFormatter().format(new TrimWhitespaceFormatter().format(textArea.getText())))); - new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textArea); + new EditorValidator(preferencesService).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textArea); } public UrlEditorViewModel getViewModel() { diff --git a/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java index 5e2dfdb7cdd..f8f6670ec77 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/UrlEditorViewModel.java @@ -12,16 +12,19 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.field.Field; import org.jabref.model.strings.StringUtil; +import org.jabref.preferences.PreferencesService; import com.tobiasdiez.easybind.EasyBind; public class UrlEditorViewModel extends AbstractEditorViewModel { private final DialogService dialogService; + private final PreferencesService preferencesService; private final BooleanProperty validUrlIsNotPresent = new SimpleBooleanProperty(true); - public UrlEditorViewModel(Field field, SuggestionProvider suggestionProvider, DialogService dialogService, FieldCheckers fieldCheckers) { + public UrlEditorViewModel(Field field, SuggestionProvider suggestionProvider, DialogService dialogService, PreferencesService preferencesService, FieldCheckers fieldCheckers) { super(field, suggestionProvider, fieldCheckers); this.dialogService = dialogService; + this.preferencesService = preferencesService; validUrlIsNotPresent.bind( EasyBind.map(text, input -> StringUtil.isBlank(input) || !URLUtil.isURL(input)) @@ -42,7 +45,7 @@ public void openExternalLink() { } try { - JabRefDesktop.openBrowser(text.get()); + JabRefDesktop.openBrowser(text.get(), preferencesService.getFilePreferences()); } catch (IOException ex) { dialogService.notify(Localization.lang("Unable to open link.")); } diff --git a/src/main/java/org/jabref/gui/fieldeditors/WriteMetadataToPdfCommand.java b/src/main/java/org/jabref/gui/fieldeditors/WriteMetadataToPdfCommand.java index a0e2c67a62d..328182e2958 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/WriteMetadataToPdfCommand.java +++ b/src/main/java/org/jabref/gui/fieldeditors/WriteMetadataToPdfCommand.java @@ -7,36 +7,50 @@ import javax.xml.transform.TransformerException; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.exporter.EmbeddedBibFilePdfExporter; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; import org.jabref.logic.xmp.XmpUtilWriter; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.LinkedFile; import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class WriteMetadataToPdfCommand extends SimpleCommand { + + private static final Logger LOGGER = LoggerFactory.getLogger(WriteMetadataToPdfCommand.class); + private final LinkedFile linkedFile; + private final BibEntry entry; private final BibDatabaseContext databaseContext; private final PreferencesService preferences; private final DialogService dialogService; - private final BibEntry entry; - private final Logger logger; + private final BibEntryTypesManager bibEntryTypesManager; + private final JournalAbbreviationRepository abbreviationRepository; private final TaskExecutor taskExecutor; - public WriteMetadataToPdfCommand(LinkedFile linkedFile, BibDatabaseContext databaseContext, PreferencesService preferences, DialogService dialogService, BibEntry entry, Logger logger, TaskExecutor taskExecutor) { + public WriteMetadataToPdfCommand(LinkedFile linkedFile, + BibEntry entry, + BibDatabaseContext databaseContext, + DialogService dialogService, + PreferencesService preferences, + BibEntryTypesManager bibEntryTypesManager, + JournalAbbreviationRepository abbreviationRepository, + TaskExecutor taskExecutor) { this.linkedFile = linkedFile; + this.entry = entry; this.databaseContext = databaseContext; this.preferences = preferences; this.dialogService = dialogService; - this.entry = entry; - this.logger = logger; + this.bibEntryTypesManager = bibEntryTypesManager; + this.abbreviationRepository = abbreviationRepository; this.taskExecutor = taskExecutor; } @@ -52,13 +66,20 @@ public void execute() { // Similar code can be found at {@link org.jabref.gui.exporter.WriteMetadataToPdfAction.writeMetadataToFile} new XmpUtilWriter(preferences.getXmpPreferences()).writeXmp(file.get(), entry, databaseContext.getDatabase()); - EmbeddedBibFilePdfExporter embeddedBibExporter = new EmbeddedBibFilePdfExporter(databaseContext.getMode(), Globals.entryTypesManager, preferences.getFieldPreferences()); - embeddedBibExporter.exportToFileByPath(databaseContext, databaseContext.getDatabase(), preferences.getFilePreferences(), file.get(), Globals.journalAbbreviationRepository); + EmbeddedBibFilePdfExporter embeddedBibExporter = new EmbeddedBibFilePdfExporter( + databaseContext.getMode(), + bibEntryTypesManager, + preferences.getFieldPreferences()); + embeddedBibExporter.exportToFileByPath( + databaseContext, + preferences.getFilePreferences(), + file.get(), + abbreviationRepository); dialogService.notify(Localization.lang("Success! Finished writing metadata.")); } catch (IOException | TransformerException ex) { dialogService.notify(Localization.lang("Error while writing metadata. See the error log for details.")); - logger.error("Error while writing metadata to {}", file.map(Path::toString).orElse(""), ex); + LOGGER.error("Error while writing metadata to {}", file.map(Path::toString).orElse(""), ex); } } } diff --git a/src/main/java/org/jabref/gui/fieldeditors/identifier/BaseIdentifierEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/identifier/BaseIdentifierEditorViewModel.java index 9e6e42cd2be..457df38e15d 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/identifier/BaseIdentifierEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/identifier/BaseIdentifierEditorViewModel.java @@ -124,7 +124,7 @@ public void lookupIdentifier(BibEntry bibEntry) { public void openExternalLink() { identifier.get().flatMap(Identifier::getExternalURI).ifPresent(url -> { try { - JabRefDesktop.openBrowser(url); + JabRefDesktop.openBrowser(url, preferences.getFilePreferences()); } catch (IOException ex) { dialogService.showErrorDialogAndWait(Localization.lang("Unable to open link."), ex); } diff --git a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java index 12c6300980b..41e2a0e0260 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java @@ -456,7 +456,7 @@ public void texGroupBrowse() { } public void openHelpPage() { - new HelpAction(HelpFile.GROUPS, dialogService).execute(); + new HelpAction(HelpFile.GROUPS, dialogService, preferencesService.getFilePreferences()).execute(); } private List getFileDirectoriesAsPaths() { diff --git a/src/main/java/org/jabref/gui/help/AboutDialogView.java b/src/main/java/org/jabref/gui/help/AboutDialogView.java index b0647f2d1df..6698ecce3ca 100644 --- a/src/main/java/org/jabref/gui/help/AboutDialogView.java +++ b/src/main/java/org/jabref/gui/help/AboutDialogView.java @@ -10,6 +10,7 @@ import org.jabref.gui.util.ControlHelper; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.BuildInfo; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; import jakarta.inject.Inject; @@ -20,6 +21,7 @@ public class AboutDialogView extends BaseDialog { @FXML private TextArea textAreaVersions; @Inject private DialogService dialogService; + @Inject private PreferencesService preferencesService; @Inject private ClipBoardManager clipBoardManager; @Inject private BuildInfo buildInfo; @@ -41,7 +43,7 @@ public AboutDialogViewModel getViewModel() { @FXML private void initialize() { - viewModel = new AboutDialogViewModel(dialogService, clipBoardManager, buildInfo); + viewModel = new AboutDialogViewModel(dialogService, preferencesService, clipBoardManager, buildInfo); textAreaVersions.setText(viewModel.getVersionInfo()); this.setResizable(false); diff --git a/src/main/java/org/jabref/gui/help/AboutDialogViewModel.java b/src/main/java/org/jabref/gui/help/AboutDialogViewModel.java index f74c1176137..4a14c8b836c 100644 --- a/src/main/java/org/jabref/gui/help/AboutDialogViewModel.java +++ b/src/main/java/org/jabref/gui/help/AboutDialogViewModel.java @@ -16,6 +16,7 @@ import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.BuildInfo; +import org.jabref.preferences.PreferencesService; import com.google.common.collect.Lists; import org.slf4j.Logger; @@ -39,11 +40,13 @@ public class AboutDialogViewModel extends AbstractViewModel { private final ReadOnlyStringWrapper license = new ReadOnlyStringWrapper(); private final ReadOnlyBooleanWrapper isDevelopmentVersion = new ReadOnlyBooleanWrapper(); private final DialogService dialogService; + private final PreferencesService preferencesService; private final ReadOnlyStringWrapper developmentVersion = new ReadOnlyStringWrapper(); private final ClipBoardManager clipBoardManager; - public AboutDialogViewModel(DialogService dialogService, ClipBoardManager clipBoardManager, BuildInfo buildInfo) { + public AboutDialogViewModel(DialogService dialogService, PreferencesService preferencesService, ClipBoardManager clipBoardManager, BuildInfo buildInfo) { this.dialogService = Objects.requireNonNull(dialogService); + this.preferencesService = Objects.requireNonNull(preferencesService); this.clipBoardManager = Objects.requireNonNull(clipBoardManager); String[] version = buildInfo.version.getFullVersion().split("--"); heading.set("JabRef " + version[0]); @@ -149,7 +152,7 @@ public void openDonation() { private void openWebsite(String url) { try { - JabRefDesktop.openBrowser(url); + JabRefDesktop.openBrowser(url, preferencesService.getFilePreferences()); } catch (IOException e) { dialogService.showErrorDialogAndWait(Localization.lang("Could not open website."), e); logger.error("Could not open default browser.", e); diff --git a/src/main/java/org/jabref/gui/help/HelpAction.java b/src/main/java/org/jabref/gui/help/HelpAction.java index 0447f7331ed..816e215731d 100644 --- a/src/main/java/org/jabref/gui/help/HelpAction.java +++ b/src/main/java/org/jabref/gui/help/HelpAction.java @@ -4,6 +4,7 @@ import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.logic.help.HelpFile; +import org.jabref.preferences.FilePreferences; /** * This Action keeps a reference to a URL. When activated, it shows the help @@ -13,16 +14,18 @@ public class HelpAction extends SimpleCommand { private final HelpFile helpPage; private final DialogService dialogService; + private final FilePreferences filePreferences; - public HelpAction(HelpFile helpPage, DialogService dialogService) { + public HelpAction(HelpFile helpPage, DialogService dialogService, FilePreferences filePreferences) { this.helpPage = helpPage; this.dialogService = dialogService; + this.filePreferences = filePreferences; } void openHelpPage(HelpFile helpPage) { StringBuilder sb = new StringBuilder("https://docs.jabref.org/"); sb.append(helpPage.getPageName()); - JabRefDesktop.openBrowserShowPopup(sb.toString(), dialogService); + JabRefDesktop.openBrowserShowPopup(sb.toString(), dialogService, filePreferences); } @Override diff --git a/src/main/java/org/jabref/gui/help/NewVersionDialog.java b/src/main/java/org/jabref/gui/help/NewVersionDialog.java index f026d0d7295..7f51da7b2a9 100644 --- a/src/main/java/org/jabref/gui/help/NewVersionDialog.java +++ b/src/main/java/org/jabref/gui/help/NewVersionDialog.java @@ -12,10 +12,11 @@ import org.jabref.gui.util.BaseDialog; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.Version; +import org.jabref.preferences.FilePreferences; public class NewVersionDialog extends BaseDialog { - public NewVersionDialog(Version currentVersion, Version latestVersion, DialogService dialogService) { + public NewVersionDialog(Version currentVersion, Version latestVersion, DialogService dialogService, FilePreferences filePreferences) { this.setTitle(Localization.lang("New version available")); ButtonType btnIgnoreUpdate = new ButtonType(Localization.lang("Ignore this update"), ButtonBar.ButtonData.CANCEL_CLOSE); @@ -26,7 +27,7 @@ public NewVersionDialog(Version currentVersion, Version latestVersion, DialogSer if (button == btnIgnoreUpdate) { return false; } else if (button == btnDownloadUpdate) { - JabRefDesktop.openBrowserShowPopup(Version.JABREF_DOWNLOAD_URL, dialogService); + JabRefDesktop.openBrowserShowPopup(Version.JABREF_DOWNLOAD_URL, dialogService, filePreferences); } return true; }); @@ -35,7 +36,7 @@ public NewVersionDialog(Version currentVersion, Version latestVersion, DialogSer Hyperlink lblMoreInformation = new Hyperlink(Localization.lang("To see what is new view the changelog.")); lblMoreInformation.setOnAction(event -> - JabRefDesktop.openBrowserShowPopup(latestVersion.getChangelogUrl(), dialogService) + JabRefDesktop.openBrowserShowPopup(latestVersion.getChangelogUrl(), dialogService, filePreferences) ); VBox container = new VBox( diff --git a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java index 3b39dbb473f..9c9d4d9d21f 100644 --- a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java +++ b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java @@ -4,27 +4,27 @@ import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.util.BuildInfo; -import org.jabref.preferences.InternalPreferences; +import org.jabref.preferences.PreferencesService; public class SearchForUpdateAction extends SimpleCommand { private final BuildInfo buildInfo; - private final InternalPreferences internalPreferences; + private final PreferencesService preferencesService; private final DialogService dialogService; private final TaskExecutor taskExecutor; - public SearchForUpdateAction(BuildInfo buildInfo, InternalPreferences internalPreferences, DialogService dialogService, TaskExecutor taskExecutor) { + public SearchForUpdateAction(BuildInfo buildInfo, PreferencesService preferencesService, DialogService dialogService, TaskExecutor taskExecutor) { this.buildInfo = buildInfo; - this.internalPreferences = internalPreferences; + this.preferencesService = preferencesService; this.dialogService = dialogService; this.taskExecutor = taskExecutor; - this.executable.bind(internalPreferences.versionCheckEnabledProperty()); + this.executable.bind(preferencesService.getInternalPreferences().versionCheckEnabledProperty()); } @Override public void execute() { - new VersionWorker(buildInfo.version, dialogService, taskExecutor, internalPreferences) + new VersionWorker(buildInfo.version, dialogService, taskExecutor, preferencesService) .checkForNewVersionAsync(); } } diff --git a/src/main/java/org/jabref/gui/help/VersionWorker.java b/src/main/java/org/jabref/gui/help/VersionWorker.java index 0bbad589ab2..5a21e89cf78 100644 --- a/src/main/java/org/jabref/gui/help/VersionWorker.java +++ b/src/main/java/org/jabref/gui/help/VersionWorker.java @@ -11,7 +11,9 @@ import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.Version; +import org.jabref.preferences.FilePreferences; import org.jabref.preferences.InternalPreferences; +import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,16 +38,17 @@ public class VersionWorker { private final DialogService dialogService; private final TaskExecutor taskExecutor; private final InternalPreferences internalPreferences; + private final FilePreferences filePreferences; public VersionWorker(Version installedVersion, - DialogService dialogService, TaskExecutor taskExecutor, - InternalPreferences internalPreferences) { + PreferencesService preferencesService) { this.installedVersion = Objects.requireNonNull(installedVersion); this.dialogService = Objects.requireNonNull(dialogService); this.taskExecutor = Objects.requireNonNull(taskExecutor); - this.internalPreferences = internalPreferences; + this.internalPreferences = preferencesService.getInternalPreferences(); + this.filePreferences = preferencesService.getFilePreferences(); } /** @@ -103,7 +106,8 @@ private void showUpdateInfo(Optional newerVersion, boolean manualExecut } } else { // notify the user about a newer version - if (dialogService.showCustomDialogAndWait(new NewVersionDialog(installedVersion, newerVersion.get(), dialogService)).orElse(true)) { + if (dialogService.showCustomDialogAndWait(new NewVersionDialog(installedVersion, newerVersion.get(), dialogService, filePreferences)) + .orElse(true)) { internalPreferences.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 63ba10bf3d1..1778074a444 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -31,6 +31,7 @@ import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; import org.jabref.logic.shared.exception.NotASharedDatabaseException; import org.jabref.logic.util.StandardFileType; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.PreferencesService; @@ -56,17 +57,20 @@ public class OpenDatabaseAction extends SimpleCommand { private final StateManager stateManager; private final FileUpdateMonitor fileUpdateMonitor; private final DialogService dialogService; + private final BibEntryTypesManager entryTypesManager; public OpenDatabaseAction(JabRefFrame frame, PreferencesService preferencesService, DialogService dialogService, StateManager stateManager, - FileUpdateMonitor fileUpdateMonitor) { + FileUpdateMonitor fileUpdateMonitor, + BibEntryTypesManager entryTypesManager) { this.frame = frame; this.preferencesService = preferencesService; this.dialogService = dialogService; this.stateManager = stateManager; this.fileUpdateMonitor = fileUpdateMonitor; + this.entryTypesManager = entryTypesManager; } /** @@ -178,7 +182,7 @@ private void openTheFile(Path file) { BackgroundTask backgroundTask = BackgroundTask.wrap(() -> loadDatabase(file)); // The backgroundTask is executed within the method createLibraryTab - LibraryTab newTab = LibraryTab.createLibraryTab(backgroundTask, file, preferencesService, stateManager, frame, fileUpdateMonitor); + LibraryTab newTab = LibraryTab.createLibraryTab(backgroundTask, file, preferencesService, stateManager, frame, fileUpdateMonitor, entryTypesManager); backgroundTask.onFinished(() -> trackOpenNewDatabase(newTab)); } diff --git a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneView.java b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneView.java index 3d163fd9cb2..7b1db9e9af5 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneView.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneView.java @@ -54,7 +54,7 @@ private void initialize() { ActionFactory factory = new ActionFactory(preferences.getKeyBindingRepository()); EasyBind.subscribe(viewModel.selectedFetcherProperty(), fetcher -> { if ((fetcher != null) && fetcher.getHelpPage().isPresent()) { - Button helpButton = factory.createIconButton(StandardActions.HELP, new HelpAction(fetcher.getHelpPage().get(), dialogService)); + Button helpButton = factory.createIconButton(StandardActions.HELP, new HelpAction(fetcher.getHelpPage().get(), dialogService, preferences.getFilePreferences())); helpButtonContainer.getChildren().setAll(helpButton); } else { helpButtonContainer.getChildren().clear(); diff --git a/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java b/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java index 809a2020c78..61922765b80 100644 --- a/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java +++ b/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java @@ -7,16 +7,17 @@ import javafx.concurrent.Task; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; import org.jabref.gui.JabRefFrame; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.integrity.IntegrityCheck; import org.jabref.logic.integrity.IntegrityMessage; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.preferences.PreferencesService; import static org.jabref.gui.actions.ActionHelper.needsDatabase; @@ -25,13 +26,22 @@ public class IntegrityCheckAction extends SimpleCommand { private final TaskExecutor taskExecutor; private final DialogService dialogService; private final JabRefFrame frame; + private final PreferencesService preferencesService; private final StateManager stateManager; + private final JournalAbbreviationRepository abbreviationRepository; - public IntegrityCheckAction(JabRefFrame frame, StateManager stateManager, TaskExecutor taskExecutor) { + public IntegrityCheckAction(JabRefFrame frame, + PreferencesService preferencesService, + DialogService dialogService, + StateManager stateManager, + TaskExecutor taskExecutor, + JournalAbbreviationRepository abbreviationRepository) { this.frame = frame; this.stateManager = stateManager; this.taskExecutor = taskExecutor; - this.dialogService = frame.getDialogService(); + this.preferencesService = preferencesService; + this.dialogService = dialogService; + this.abbreviationRepository = abbreviationRepository; this.executable.bind(needsDatabase(this.stateManager)); } @@ -40,10 +50,10 @@ public IntegrityCheckAction(JabRefFrame frame, StateManager stateManager, TaskEx public void execute() { BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null")); IntegrityCheck check = new IntegrityCheck(database, - Globals.prefs.getFilePreferences(), - Globals.prefs.getCitationKeyPatternPreferences(), - Globals.journalAbbreviationRepository, - Globals.prefs.getEntryEditorPreferences().shouldAllowIntegerEditionBibtex()); + preferencesService.getFilePreferences(), + preferencesService.getCitationKeyPatternPreferences(), + abbreviationRepository, + preferencesService.getEntryEditorPreferences().shouldAllowIntegerEditionBibtex()); Task> task = new Task<>() { @Override diff --git a/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesView.java b/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesView.java index 7e7ceaa022e..76b0debf639 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesView.java +++ b/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesView.java @@ -49,7 +49,7 @@ public String getTabName() { } public void initialize() { - this.viewModel = new ConstantsPropertiesViewModel(databaseContext, dialogService); + this.viewModel = new ConstantsPropertiesViewModel(databaseContext, dialogService, preferencesService.getFilePreferences()); addStringButton.setTooltip(new Tooltip(Localization.lang("New string"))); diff --git a/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModel.java b/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModel.java index 386323599e8..36f4ddeff07 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModel.java +++ b/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModel.java @@ -20,6 +20,7 @@ import org.jabref.logic.help.HelpFile; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibtexString; +import org.jabref.preferences.FilePreferences; import com.tobiasdiez.easybind.EasyBind; @@ -35,10 +36,12 @@ public class ConstantsPropertiesViewModel implements PropertiesTabViewModel { private final BibDatabaseContext databaseContext; private final DialogService dialogService; + private final FilePreferences filePreferences; - public ConstantsPropertiesViewModel(BibDatabaseContext databaseContext, DialogService dialogService) { + public ConstantsPropertiesViewModel(BibDatabaseContext databaseContext, DialogService dialogService, FilePreferences filePreferences) { this.databaseContext = databaseContext; this.dialogService = dialogService; + this.filePreferences = filePreferences; ObservableList> allValidProperty = EasyBind.map(stringsListProperty, ConstantsItemModel::combinedValidationValidProperty); @@ -101,7 +104,7 @@ public Optional labelAlreadyExists(String label) { } public void openHelpPage() { - new HelpAction(HelpFile.STRING_EDITOR, dialogService).execute(); + new HelpAction(HelpFile.STRING_EDITOR, dialogService, filePreferences).execute(); } public ListProperty stringsListProperty() { diff --git a/src/main/java/org/jabref/gui/libraryproperties/keypattern/KeyPatternPropertiesView.java b/src/main/java/org/jabref/gui/libraryproperties/keypattern/KeyPatternPropertiesView.java index 0c65d449942..42a573f335d 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/keypattern/KeyPatternPropertiesView.java +++ b/src/main/java/org/jabref/gui/libraryproperties/keypattern/KeyPatternPropertiesView.java @@ -47,7 +47,7 @@ public void initialize() { bibtexKeyPatternTable.defaultKeyPatternProperty().bindBidirectional(viewModel.defaultKeyPatternProperty()); ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); - actionFactory.configureIconButton(StandardActions.HELP_KEY_PATTERNS, new HelpAction(HelpFile.CITATION_KEY_PATTERN, dialogService), keyPatternHelp); + actionFactory.configureIconButton(StandardActions.HELP_KEY_PATTERNS, new HelpAction(HelpFile.CITATION_KEY_PATTERN, dialogService, preferencesService.getFilePreferences()), keyPatternHelp); } @Override diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 8ea7731ba3d..ee5242099ca 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -49,6 +49,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.event.EntriesAddedEvent; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.PreferencesService; @@ -69,6 +70,7 @@ public class MainTable extends TableView { private final ImportHandler importHandler; private final CustomLocalDragboard localDragboard; private final ClipBoardManager clipBoardManager; + private final BibEntryTypesManager entryTypesManager; private long lastKeyPressTime; private String columnSearchTerm; @@ -80,6 +82,7 @@ public MainTable(MainTableDataModel model, StateManager stateManager, KeyBindingRepository keyBindingRepository, ClipBoardManager clipBoardManager, + BibEntryTypesManager entryTypesManager, TaskExecutor taskExecutor, FileUpdateMonitor fileUpdateMonitor) { super(); @@ -90,6 +93,7 @@ public MainTable(MainTableDataModel model, this.database = Objects.requireNonNull(database); this.model = model; this.clipBoardManager = clipBoardManager; + this.entryTypesManager = entryTypesManager; UndoManager undoManager = libraryTab.getUndoManager(); MainTablePreferences mainTablePreferences = preferencesService.getMainTablePreferences(); @@ -253,7 +257,7 @@ public void copy() { if (!selectedEntries.isEmpty()) { try { - clipBoardManager.setContent(selectedEntries); + clipBoardManager.setContent(selectedEntries, entryTypesManager); dialogService.notify(libraryTab.formatOutputMessage(Localization.lang("Copied"), selectedEntries.size())); } catch (IOException e) { LOGGER.error("Error while copying selected entries to clipboard", e); diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index a375fdaed0d..fca260455dc 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -55,12 +55,12 @@ public static ContextMenu create(BibEntryTableViewModel entry, createCopySubMenu(factory, dialogService, stateManager, preferencesService, clipBoardManager, abbreviationRepository, taskExecutor), factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, libraryTab.frame(), stateManager)), factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, libraryTab.frame(), stateManager)), - factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(dialogService, stateManager, preferencesService.getBibEntryPreferences())), + factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(dialogService, stateManager, preferencesService)), factory.createMenuItem(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, libraryTab.frame(), stateManager)), new SeparatorMenuItem(), - createSendSubMenu(factory, dialogService, stateManager, preferencesService), + createSendSubMenu(factory, dialogService, stateManager, preferencesService, entryTypesManager), SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager), SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager), @@ -128,10 +128,11 @@ private static Menu createCopySubMenu(ActionFactory factory, private static Menu createSendSubMenu(ActionFactory factory, DialogService dialogService, StateManager stateManager, - PreferencesService preferencesService) { + PreferencesService preferencesService, + BibEntryTypesManager entryTypesManager) { Menu sendMenu = factory.createMenu(StandardActions.SEND); sendMenu.getItems().addAll( - factory.createMenuItem(StandardActions.SEND_AS_EMAIL, new SendAsStandardEmailAction(dialogService, preferencesService, stateManager)), + factory.createMenuItem(StandardActions.SEND_AS_EMAIL, new SendAsStandardEmailAction(dialogService, preferencesService, stateManager, entryTypesManager)), factory.createMenuItem(StandardActions.SEND_TO_KINDLE, new SendAsKindleEmailAction(dialogService, preferencesService, stateManager)), new SeparatorMenuItem() ); diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index a63e55822dd..c779eea8ed9 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -29,7 +29,6 @@ import org.jabref.model.entry.field.FieldFactory; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.EntryType; -import org.jabref.preferences.BibEntryPreferences; import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; @@ -77,7 +76,7 @@ public void fetchAndMerge(BibEntry entry, List fields) { String type = field.getDisplayName(); if (fetchedEntry.isPresent()) { cleanup.doPostCleanup(fetchedEntry.get()); - showMergeDialog(entry, fetchedEntry.get(), fetcher.get(), preferencesService.getBibEntryPreferences()); + showMergeDialog(entry, fetchedEntry.get(), fetcher.get()); } else { dialogService.notify(Localization.lang("Cannot get info based on given %0: %1", type, fieldContent.get())); } @@ -100,8 +99,8 @@ public void fetchAndMerge(BibEntry entry, List fields) { } } - private void showMergeDialog(BibEntry originalEntry, BibEntry fetchedEntry, WebFetcher fetcher, BibEntryPreferences bibEntryPreferences) { - MergeEntriesDialog dialog = new MergeEntriesDialog(originalEntry, fetchedEntry, bibEntryPreferences); + private void showMergeDialog(BibEntry originalEntry, BibEntry fetchedEntry, WebFetcher fetcher) { + MergeEntriesDialog dialog = new MergeEntriesDialog(originalEntry, fetchedEntry, preferencesService); dialog.setTitle(Localization.lang("Merge entry with %0 information", fetcher.getName())); dialog.setLeftHeaderText(Localization.lang("Original entry")); dialog.setRightHeaderText(Localization.lang("Entry from %0", fetcher.getName())); @@ -167,7 +166,7 @@ public void fetchAndMerge(BibEntry entry, EntryBasedFetcher fetcher) { if (fetchedEntry.isPresent()) { ImportCleanup cleanup = new ImportCleanup(libraryTab.getBibDatabaseContext().getMode()); cleanup.doPostCleanup(fetchedEntry.get()); - showMergeDialog(entry, fetchedEntry.get(), fetcher, preferencesService.getBibEntryPreferences()); + showMergeDialog(entry, fetchedEntry.get(), fetcher); } else { dialogService.notify(Localization.lang("Could not find any bibliographic information.")); } diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java index 9c40605d11d..acb97eb167c 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java @@ -11,18 +11,18 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.InternalField; -import org.jabref.preferences.BibEntryPreferences; +import org.jabref.preferences.PreferencesService; public class MergeEntriesAction extends SimpleCommand { private static final int NUMBER_OF_ENTRIES_NEEDED = 2; private final DialogService dialogService; private final StateManager stateManager; - private final BibEntryPreferences bibEntryPreferences; + private final PreferencesService preferencesService; - public MergeEntriesAction(DialogService dialogService, StateManager stateManager, BibEntryPreferences bibEntryPreferences) { + public MergeEntriesAction(DialogService dialogService, StateManager stateManager, PreferencesService preferencesService) { this.dialogService = dialogService; this.stateManager = stateManager; - this.bibEntryPreferences = bibEntryPreferences; + this.preferencesService = preferencesService; this.executable.bind(ActionHelper.needsEntriesSelected(NUMBER_OF_ENTRIES_NEEDED, stateManager)); } @@ -59,7 +59,7 @@ public void execute() { second = one; } - MergeEntriesDialog dialog = new MergeEntriesDialog(first, second, bibEntryPreferences); + MergeEntriesDialog dialog = new MergeEntriesDialog(first, second, preferencesService); dialog.setTitle(Localization.lang("Merge entries")); Optional mergeResultOpt = dialogService.showCustomDialogAndWait(dialog); diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java index 8be99e1bfee..6766050972a 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesDialog.java @@ -8,15 +8,15 @@ import org.jabref.gui.util.BaseDialog; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; -import org.jabref.preferences.BibEntryPreferences; +import org.jabref.preferences.PreferencesService; public class MergeEntriesDialog extends BaseDialog { private final ThreeWayMergeView threeWayMergeView; private final BibEntry one; private final BibEntry two; - public MergeEntriesDialog(BibEntry one, BibEntry two, BibEntryPreferences bibEntryPreferences) { - threeWayMergeView = new ThreeWayMergeView(one, two, bibEntryPreferences); + public MergeEntriesDialog(BibEntry one, BibEntry two, PreferencesService preferencesService) { + threeWayMergeView = new ThreeWayMergeView(one, two, preferencesService); this.one = one; this.two = two; diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java index e2522a05f21..afb25d2a4a8 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/FieldRowView.java @@ -18,6 +18,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; import org.jabref.model.strings.StringUtil; +import org.jabref.preferences.PreferencesService; import com.tobiasdiez.easybind.EasyBind; import org.fxmisc.richtext.StyleClassedTextArea; @@ -42,12 +43,12 @@ public class FieldRowView { private GridPane parent; - public FieldRowView(Field field, BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry, FieldMergerFactory fieldMergerFactory, int rowIndex) { + public FieldRowView(Field field, BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry, FieldMergerFactory fieldMergerFactory, PreferencesService preferencesService, int rowIndex) { viewModel = new FieldRowViewModel(field, leftEntry, rightEntry, mergedEntry, fieldMergerFactory); fieldNameCell = new FieldNameCell(field.getDisplayName(), rowIndex); - leftValueCell = new FieldValueCell(viewModel.getLeftFieldValue(), rowIndex); - rightValueCell = new FieldValueCell(viewModel.getRightFieldValue(), rowIndex); + leftValueCell = new FieldValueCell(viewModel.getLeftFieldValue(), rowIndex, preferencesService); + rightValueCell = new FieldValueCell(viewModel.getRightFieldValue(), rowIndex, preferencesService); mergedValueCell = new MergedFieldCell(viewModel.getMergedFieldValue(), rowIndex); // As a workaround we need to have a reference to the parent grid pane to be able to show/hide the row. diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java index 8d707f34b0f..84544d77efd 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java @@ -8,13 +8,14 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldProperty; +import org.jabref.preferences.PreferencesService; public class PersonsNameFieldRowView extends FieldRowView { private final AuthorList leftEntryNames; private final AuthorList rightEntryNames; - public PersonsNameFieldRowView(Field field, BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry, FieldMergerFactory fieldMergerFactory, int rowIndex) { - super(field, leftEntry, rightEntry, mergedEntry, fieldMergerFactory, rowIndex); + public PersonsNameFieldRowView(Field field, BibEntry leftEntry, BibEntry rightEntry, BibEntry mergedEntry, FieldMergerFactory fieldMergerFactory, PreferencesService preferencesService, int rowIndex) { + super(field, leftEntry, rightEntry, mergedEntry, fieldMergerFactory, preferencesService, rowIndex); assert field.getProperties().contains(FieldProperty.PERSON_NAMES); var authorsParser = new AuthorListParser(); diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java index 2b2d03b4926..ac04d895b11 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/ThreeWayMergeView.java @@ -17,7 +17,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldProperty; -import org.jabref.preferences.BibEntryPreferences; +import org.jabref.preferences.PreferencesService; public class ThreeWayMergeView extends VBox { public static final int GRID_COLUMN_MIN_WIDTH = 250; @@ -37,14 +37,18 @@ public class ThreeWayMergeView extends VBox { private final ThreeWayMergeViewModel viewModel; private final List fieldRows = new ArrayList<>(); + private final PreferencesService preferencesService; + private final FieldMergerFactory fieldMergerFactory; private final String keywordSeparator; - public ThreeWayMergeView(BibEntry leftEntry, BibEntry rightEntry, String leftHeader, String rightHeader, BibEntryPreferences bibEntryPreferences) { + public ThreeWayMergeView(BibEntry leftEntry, BibEntry rightEntry, String leftHeader, String rightHeader, PreferencesService preferencesService) { + this.preferencesService = preferencesService; + getStylesheets().add(ThreeWayMergeView.class.getResource("ThreeWayMergeView.css").toExternalForm()); viewModel = new ThreeWayMergeViewModel((BibEntry) leftEntry.clone(), (BibEntry) rightEntry.clone(), leftHeader, rightHeader); - this.fieldMergerFactory = new FieldMergerFactory(bibEntryPreferences); - this.keywordSeparator = bibEntryPreferences.getKeywordSeparator().toString(); + this.fieldMergerFactory = new FieldMergerFactory(preferencesService.getBibEntryPreferences()); + this.keywordSeparator = preferencesService.getBibEntryPreferences().getKeywordSeparator().toString(); mergeGridPane = new GridPane(); scrollPane = new ScrollPane(); @@ -63,8 +67,8 @@ public ThreeWayMergeView(BibEntry leftEntry, BibEntry rightEntry, String leftHea getChildren().addAll(toolbar, headerView, scrollPane); } - public ThreeWayMergeView(BibEntry leftEntry, BibEntry rightEntry, BibEntryPreferences bibEntryPreferences) { - this(leftEntry, rightEntry, LEFT_DEFAULT_HEADER, RIGHT_DEFAULT_HEADER, bibEntryPreferences); + public ThreeWayMergeView(BibEntry leftEntry, BibEntry rightEntry, PreferencesService preferencesService) { + this(leftEntry, rightEntry, LEFT_DEFAULT_HEADER, RIGHT_DEFAULT_HEADER, preferencesService); } private void initializeToolbar() { @@ -145,9 +149,9 @@ private void addRow(int fieldIndex) { FieldRowView fieldRow; if (field.getProperties().contains(FieldProperty.PERSON_NAMES)) { - fieldRow = new PersonsNameFieldRowView(field, getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, fieldIndex); + fieldRow = new PersonsNameFieldRowView(field, getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, preferencesService, fieldIndex); } else { - fieldRow = new FieldRowView(field, getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, fieldIndex); + fieldRow = new FieldRowView(field, getLeftEntry(), getRightEntry(), getMergedEntry(), fieldMergerFactory, preferencesService, fieldIndex); } fieldRows.add(fieldIndex, fieldRow); diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/FieldValueCell.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/FieldValueCell.java index 2a3c3030ac6..3b7d0036722 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/FieldValueCell.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/FieldValueCell.java @@ -26,6 +26,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.identifier.DOI; import org.jabref.model.strings.StringUtil; +import org.jabref.preferences.PreferencesService; import com.tobiasdiez.easybind.EasyBind; import org.fxmisc.flowless.VirtualizedScrollPane; @@ -46,10 +47,11 @@ public class FieldValueCell extends ThreeWayMergeCell implements Toggle { private static final PseudoClass SELECTED_PSEUDO_CLASS = PseudoClass.getPseudoClass("selected"); - private final StyleClassedTextArea label = new StyleClassedTextArea(); + private final PreferencesService preferencesService; - private final ActionFactory factory = new ActionFactory(Globals.getKeyPrefs()); + private final ActionFactory factory; + private final StyleClassedTextArea label = new StyleClassedTextArea(); private final VirtualizedScrollPane scrollPane = new VirtualizedScrollPane<>(label); HBox labelBox = new HBox(scrollPane); @@ -57,14 +59,20 @@ public class FieldValueCell extends ThreeWayMergeCell implements Toggle { private final HBox actionsContainer = new HBox(); private final FieldValueCellViewModel viewModel; - public FieldValueCell(String text, int rowIndex) { + public FieldValueCell(String text, int rowIndex, PreferencesService preferencesService) { super(text, rowIndex); - viewModel = new FieldValueCellViewModel(text); + + this.preferencesService = preferencesService; + this.factory = new ActionFactory(Globals.getKeyPrefs()); + this.viewModel = new FieldValueCellViewModel(text); + EasyBind.listen(viewModel.selectedProperty(), (observable, old, isSelected) -> { pseudoClassStateChanged(SELECTED_PSEUDO_CLASS, isSelected); getToggleGroup().selectToggle(FieldValueCell.this); }); + viewModel.fieldValueProperty().bind(textProperty()); + initialize(); } @@ -123,7 +131,7 @@ private Button createCopyButton() { FontIcon copyIcon = FontIcon.of(MaterialDesignC.CONTENT_COPY); copyIcon.getStyleClass().add("action-icon"); - Button copyButton = factory.createIconButton(() -> Localization.lang("Copy"), new CopyFieldValueCommand(Globals.prefs, getText())); + Button copyButton = factory.createIconButton(() -> Localization.lang("Copy"), new CopyFieldValueCommand(preferencesService, getText())); copyButton.setGraphic(copyIcon); copyButton.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); copyButton.setMaxHeight(Double.MAX_VALUE); @@ -136,7 +144,7 @@ public Button createOpenLinkButton() { Node openLinkIcon = IconTheme.JabRefIcons.OPEN_LINK.getGraphicNode(); openLinkIcon.getStyleClass().add("action-icon"); - Button openLinkButton = factory.createIconButton(() -> Localization.lang("Open Link"), new OpenExternalLinkAction(getText())); + Button openLinkButton = factory.createIconButton(() -> Localization.lang("Open Link"), new OpenExternalLinkAction(getText(), preferencesService.getFilePreferences())); openLinkButton.setGraphic(openLinkIcon); openLinkButton.setContentDisplay(ContentDisplay.GRAPHIC_ONLY); openLinkButton.setMaxHeight(Double.MAX_VALUE); diff --git a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/OpenExternalLinkAction.java b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/OpenExternalLinkAction.java index 0d0a2e08230..abc43d3f049 100644 --- a/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/OpenExternalLinkAction.java +++ b/src/main/java/org/jabref/gui/mergeentries/newmergedialog/cell/OpenExternalLinkAction.java @@ -6,6 +6,7 @@ import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.model.entry.identifier.DOI; +import org.jabref.preferences.FilePreferences; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,10 +15,14 @@ * A command for opening DOIs and URLs. This was created primarily for simplifying {@link FieldValueCell}. */ public class OpenExternalLinkAction extends SimpleCommand { - private final String urlOrDoi; private final Logger LOGGER = LoggerFactory.getLogger(OpenExternalLinkAction.class); - public OpenExternalLinkAction(String urlOrDoi) { + private final FilePreferences filePreferences; + + private final String urlOrDoi; + + public OpenExternalLinkAction(String urlOrDoi, FilePreferences filePreferences) { + this.filePreferences = filePreferences; this.urlOrDoi = urlOrDoi; } @@ -29,12 +34,11 @@ public void execute() { DOI.parse(urlOrDoi) .flatMap(DOI::getExternalURI) .map(URI::toString) - .orElse("") + .orElse(""), + filePreferences ); } else { - JabRefDesktop.openBrowser( - urlOrDoi - ); + JabRefDesktop.openBrowser(urlOrDoi, filePreferences); } } catch (IOException e) { LOGGER.warn("Cannot open the given external link '{}'", urlOrDoi, e); diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index a8b06a0b700..94c54289125 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -117,7 +117,7 @@ public OpenOfficePanel(PreferencesService preferencesService, manualConnect.setTooltip(new Tooltip(Localization.lang("Manual connect"))); manualConnect.setMaxWidth(Double.MAX_VALUE); - help = factory.createIconButton(StandardActions.HELP, new HelpAction(HelpFile.OPENOFFICE_LIBREOFFICE, dialogService)); + help = factory.createIconButton(StandardActions.HELP, new HelpAction(HelpFile.OPENOFFICE_LIBREOFFICE, dialogService, preferencesService.getFilePreferences())); help.setMaxWidth(Double.MAX_VALUE); selectDocument = new Button(); diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogView.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogView.java index 77870845ba8..f2c8a835345 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogView.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogView.java @@ -74,11 +74,11 @@ public StyleSelectDialogView(StyleLoader loader) { private void initialize() { viewModel = new StyleSelectDialogViewModel(dialogService, loader, preferencesService); - previewArticle = new PreviewViewer(new BibDatabaseContext(), dialogService, stateManager, themeManager); + previewArticle = new PreviewViewer(new BibDatabaseContext(), dialogService, preferencesService, stateManager, themeManager); previewArticle.setEntry(TestEntry.getTestEntry()); vbox.getChildren().add(previewArticle); - previewBook = new PreviewViewer(new BibDatabaseContext(), dialogService, stateManager, themeManager); + previewBook = new PreviewViewer(new BibDatabaseContext(), dialogService, preferencesService, stateManager, themeManager); previewBook.setEntry(TestEntry.getTestEntryBook()); vbox.getChildren().add(previewBook); diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java index 91752c95407..3fc36eec238 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java @@ -27,6 +27,7 @@ import org.jabref.logic.openoffice.style.StyleLoader; import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabaseContext; +import org.jabref.preferences.FilePreferences; import org.jabref.preferences.PreferencesService; public class StyleSelectDialogViewModel { @@ -34,13 +35,13 @@ public class StyleSelectDialogViewModel { private final DialogService dialogService; private final StyleLoader styleLoader; private final OpenOfficePreferences openOfficePreferences; - private final PreferencesService preferencesService; + private final FilePreferences filePreferences; private final ListProperty styles = new SimpleListProperty<>(FXCollections.observableArrayList()); private final ObjectProperty selectedItem = new SimpleObjectProperty<>(); public StyleSelectDialogViewModel(DialogService dialogService, StyleLoader styleLoader, PreferencesService preferencesService) { this.dialogService = dialogService; - this.preferencesService = preferencesService; + this.filePreferences = preferencesService.getFilePreferences(); this.openOfficePreferences = preferencesService.getOpenOfficePreferences(); this.styleLoader = styleLoader; @@ -62,7 +63,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.getFilePreferences().getWorkingDirectory()) + .withInitialDirectory(filePreferences.getWorkingDirectory()) .build(); Optional path = dialogService.showFileOpenDialog(fileDialogConfiguration); path.map(Path::toAbsolutePath).map(Path::toString).ifPresent(stylePath -> { @@ -93,9 +94,9 @@ public void deleteStyle() { public void editStyle() { OOBibStyle style = selectedItem.getValue().getStyle(); - Optional type = ExternalFileTypes.getExternalFileTypeByExt("jstyle", preferencesService.getFilePreferences()); + Optional type = ExternalFileTypes.getExternalFileTypeByExt("jstyle", filePreferences); try { - JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), preferencesService, style.getPath(), type); + JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), filePreferences, style.getPath(), type); } catch (IOException e) { dialogService.showErrorDialogAndWait(e); } diff --git a/src/main/java/org/jabref/gui/preferences/citationkeypattern/CitationKeyPatternTab.java b/src/main/java/org/jabref/gui/preferences/citationkeypattern/CitationKeyPatternTab.java index 92ded437ac6..5f14bd5247e 100644 --- a/src/main/java/org/jabref/gui/preferences/citationkeypattern/CitationKeyPatternTab.java +++ b/src/main/java/org/jabref/gui/preferences/citationkeypattern/CitationKeyPatternTab.java @@ -60,7 +60,7 @@ public void initialize() { bibtexKeyPatternTable.defaultKeyPatternProperty().bindBidirectional(viewModel.defaultKeyPatternProperty()); ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); - actionFactory.configureIconButton(StandardActions.HELP_KEY_PATTERNS, new HelpAction(HelpFile.CITATION_KEY_PATTERN, dialogService), keyPatternHelp); + actionFactory.configureIconButton(StandardActions.HELP_KEY_PATTERNS, new HelpAction(HelpFile.CITATION_KEY_PATTERN, dialogService, preferencesService.getFilePreferences()), keyPatternHelp); } @Override diff --git a/src/main/java/org/jabref/gui/preferences/entry/EntryTab.java b/src/main/java/org/jabref/gui/preferences/entry/EntryTab.java index d3b81871b0f..f92088ad6ea 100644 --- a/src/main/java/org/jabref/gui/preferences/entry/EntryTab.java +++ b/src/main/java/org/jabref/gui/preferences/entry/EntryTab.java @@ -62,7 +62,7 @@ public void initialize() { addModificationDate.selectedProperty().bindBidirectional(viewModel.addModificationDateProperty()); ActionFactory actionFactory = new ActionFactory(keyBindingRepository); - actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.OWNER, dialogService), markOwnerHelp); + actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.OWNER, dialogService, preferencesService.getFilePreferences()), markOwnerHelp); } @Override diff --git a/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTab.java b/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTab.java index 46b3d642362..121d44da00c 100644 --- a/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTab.java +++ b/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTab.java @@ -61,7 +61,7 @@ public void initialize() { fieldsTextArea.textProperty().bindBidirectional(viewModel.fieldsProperty()); ActionFactory actionFactory = new ActionFactory(keyBindingRepository); - actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.GENERAL_FIELDS, dialogService), generalFieldsHelp); + actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.GENERAL_FIELDS, dialogService, preferencesService.getFilePreferences()), generalFieldsHelp); } @FXML diff --git a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java index ecd749be4ca..8cf5db7140d 100644 --- a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java +++ b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java @@ -121,7 +121,7 @@ public void initialize() { alwaysReformatBib.selectedProperty().bindBidirectional(viewModel.alwaysReformatBibProperty()); autosaveLocalLibraries.selectedProperty().bindBidirectional(viewModel.autosaveLocalLibrariesProperty()); ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); - actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.AUTOSAVE, dialogService), autosaveLocalLibrariesHelp); + actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.AUTOSAVE, dialogService, preferencesService.getFilePreferences()), autosaveLocalLibrariesHelp); createBackup.selectedProperty().bindBidirectional(viewModel.createBackupProperty()); backupDirectory.textProperty().bindBidirectional(viewModel.backupDirectoryProperty()); diff --git a/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTab.java b/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTab.java index 558ac2db289..83325c8e3f2 100644 --- a/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTab.java +++ b/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTab.java @@ -71,7 +71,7 @@ public void initialize() { fileDirectoryPattern.textProperty().bindBidirectional(viewModel.fileDirectoryPatternProperty()); ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); - actionFactory.configureIconButton(StandardActions.HELP_REGEX_SEARCH, new HelpAction(HelpFile.REGEX_SEARCH, dialogService), autolinkRegexHelp); + actionFactory.configureIconButton(StandardActions.HELP_REGEX_SEARCH, new HelpAction(HelpFile.REGEX_SEARCH, dialogService, preferencesService.getFilePreferences()), autolinkRegexHelp); validationVisualizer.setDecoration(new IconValidationDecorator()); Platform.runLater(() -> validationVisualizer.initVisualization(viewModel.mainFileDirValidationStatus(), mainFileDirectory)); 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 84ccc80d80d..932678f7cfa 100644 --- a/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTab.java +++ b/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTab.java @@ -103,7 +103,7 @@ public void initialize() { }); ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); - actionFactory.configureIconButton(StandardActions.HELP_NAME_FORMATTER, new HelpAction(HelpFile.CUSTOM_EXPORTS_NAME_FORMATTER, dialogService), formatterHelp); + actionFactory.configureIconButton(StandardActions.HELP_NAME_FORMATTER, new HelpAction(HelpFile.CUSTOM_EXPORTS_NAME_FORMATTER, dialogService, preferencesService.getFilePreferences()), formatterHelp); } public void addFormatter() { diff --git a/src/main/java/org/jabref/gui/preferences/network/NetworkTab.java b/src/main/java/org/jabref/gui/preferences/network/NetworkTab.java index d57ec457e5a..71e70e5b1f0 100644 --- a/src/main/java/org/jabref/gui/preferences/network/NetworkTab.java +++ b/src/main/java/org/jabref/gui/preferences/network/NetworkTab.java @@ -28,6 +28,7 @@ import org.jabref.gui.util.ValueTableCellFactory; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.util.FileUpdateMonitor; import com.airhacks.afterburner.views.ViewLoader; @@ -67,6 +68,7 @@ public class NetworkTab extends AbstractPreferenceTabView i @FXML private TableColumn actionsColumn; @Inject private FileUpdateMonitor fileUpdateMonitor; + @Inject private BibEntryTypesManager entryTypesManager; private String proxyPasswordText = ""; private int proxyPasswordCaretPosition = 0; @@ -85,7 +87,7 @@ public String getTabName() { } public void initialize() { - this.viewModel = new NetworkTabViewModel(dialogService, preferencesService, fileUpdateMonitor); + this.viewModel = new NetworkTabViewModel(dialogService, preferencesService, fileUpdateMonitor, entryTypesManager); versionCheck.selectedProperty().bindBidirectional(viewModel.versionCheckProperty()); @@ -128,7 +130,7 @@ public void initialize() { proxyPassword.getRight().addEventFilter(MouseEvent.MOUSE_EXITED, this::proxyPasswordMask); ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); - actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.REMOTE, dialogService), remoteHelp); + actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.REMOTE, dialogService, preferencesService.getFilePreferences()), remoteHelp); validationVisualizer.setDecoration(new IconValidationDecorator()); Platform.runLater(() -> { diff --git a/src/main/java/org/jabref/gui/preferences/network/NetworkTabViewModel.java b/src/main/java/org/jabref/gui/preferences/network/NetworkTabViewModel.java index eaaf293fe5b..7991e86493e 100644 --- a/src/main/java/org/jabref/gui/preferences/network/NetworkTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/network/NetworkTabViewModel.java @@ -33,6 +33,7 @@ import org.jabref.logic.remote.RemoteUtil; import org.jabref.logic.util.OS; import org.jabref.logic.util.StandardFileType; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.strings.StringUtil; import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.InternalPreferences; @@ -68,6 +69,7 @@ public class NetworkTabViewModel implements PreferenceTabViewModel { private final DialogService dialogService; private final PreferencesService preferences; private final FileUpdateMonitor fileUpdateMonitor; + private final BibEntryTypesManager entryTypesManager; private final RemotePreferences remotePreferences; private final ProxyPreferences proxyPreferences; @@ -78,10 +80,14 @@ public class NetworkTabViewModel implements PreferenceTabViewModel { private final AtomicBoolean sslCertificatesChanged = new AtomicBoolean(false); - public NetworkTabViewModel(DialogService dialogService, PreferencesService preferences, FileUpdateMonitor fileUpdateMonitor) { + public NetworkTabViewModel(DialogService dialogService, + PreferencesService preferences, + FileUpdateMonitor fileUpdateMonitor, + BibEntryTypesManager entryTypesManager) { this.dialogService = dialogService; this.preferences = preferences; this.fileUpdateMonitor = fileUpdateMonitor; + this.entryTypesManager = entryTypesManager; this.remotePreferences = preferences.getRemotePreferences(); this.proxyPreferences = preferences.getProxyPreferences(); this.internalPreferences = preferences.getInternalPreferences(); @@ -196,7 +202,7 @@ public void storeSettings() { if (remoteServerProperty.getValue()) { remotePreferences.setUseRemoteServer(true); - Globals.REMOTE_LISTENER.openAndStart(new CLIMessageHandler(preferences, fileUpdateMonitor), remotePreferences.getPort()); + Globals.REMOTE_LISTENER.openAndStart(new CLIMessageHandler(preferences, fileUpdateMonitor, entryTypesManager), remotePreferences.getPort()); } else { remotePreferences.setUseRemoteServer(false); Globals.REMOTE_LISTENER.stop(); diff --git a/src/main/java/org/jabref/gui/preferences/preview/PreviewTab.java b/src/main/java/org/jabref/gui/preferences/preview/PreviewTab.java index 10ff3bcf9aa..cd50d49cfdb 100644 --- a/src/main/java/org/jabref/gui/preferences/preview/PreviewTab.java +++ b/src/main/java/org/jabref/gui/preferences/preview/PreviewTab.java @@ -156,7 +156,7 @@ public void initialize() { sortUpButton.disableProperty().bind(viewModel.chosenSelectionModelProperty().getValue().selectedItemProperty().isNull()); sortDownButton.disableProperty().bind(viewModel.chosenSelectionModelProperty().getValue().selectedItemProperty().isNull()); - PreviewViewer previewViewer = new PreviewViewer(new BibDatabaseContext(), dialogService, stateManager, themeManager); + PreviewViewer previewViewer = new PreviewViewer(new BibDatabaseContext(), dialogService, preferencesService, stateManager, themeManager); previewViewer.setEntry(TestEntry.getTestEntry()); EasyBind.subscribe(viewModel.selectedLayoutProperty(), previewViewer::setLayout); previewViewer.visibleProperty().bind(viewModel.chosenSelectionModelProperty().getValue().selectedItemProperty().isNotNull() 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 ac17b25d736..93ffa2b05fb 100644 --- a/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java @@ -27,6 +27,7 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.util.OptionalUtil; +import org.jabref.preferences.FilePreferences; import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; @@ -37,17 +38,17 @@ public class ProtectedTermsTabViewModel implements PreferenceTabViewModel { private final ProtectedTermsLoader termsLoader; private final ListProperty termsFilesProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); - private final PreferencesService preferences; + private final FilePreferences filePreferences; private final DialogService dialogService; private final ProtectedTermsPreferences protectedTermsPreferences; public ProtectedTermsTabViewModel(ProtectedTermsLoader termsLoader, DialogService dialogService, - PreferencesService preferences) { + PreferencesService preferencesService) { this.termsLoader = termsLoader; this.dialogService = dialogService; - this.preferences = preferences; - this.protectedTermsPreferences = preferences.getProtectedTermsPreferences(); + this.filePreferences = preferencesService.getFilePreferences(); + this.protectedTermsPreferences = preferencesService.getProtectedTermsPreferences(); } @Override @@ -92,7 +93,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.getFilePreferences().getWorkingDirectory()) + .withInitialDirectory(filePreferences.getWorkingDirectory()) .build(); dialogService.showFileOpenDialog(fileDialogConfiguration) @@ -116,18 +117,18 @@ public void removeList(ProtectedTermsListItemModel itemModel) { } public void createNewFile() { - dialogService.showCustomDialogAndWait(new NewProtectedTermsFileDialog(termsFilesProperty, dialogService, preferences.getFilePreferences())); + dialogService.showCustomDialogAndWait(new NewProtectedTermsFileDialog(termsFilesProperty, dialogService, filePreferences)); } public void edit(ProtectedTermsListItemModel file) { Optional termsFileType = OptionalUtil.orElse( - ExternalFileTypes.getExternalFileTypeByExt("terms", preferences.getFilePreferences()), - ExternalFileTypes.getExternalFileTypeByExt("txt", preferences.getFilePreferences()) + ExternalFileTypes.getExternalFileTypeByExt("terms", filePreferences), + ExternalFileTypes.getExternalFileTypeByExt("txt", filePreferences) ); String fileName = file.getTermsList().getLocation(); try { - JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), preferences, fileName, termsFileType); + JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), filePreferences, fileName, termsFileType); } catch (IOException e) { LOGGER.warn("Problem open protected terms file editor", e); } diff --git a/src/main/java/org/jabref/gui/preferences/table/TableTab.java b/src/main/java/org/jabref/gui/preferences/table/TableTab.java index e3ab7004598..4d802c8b611 100644 --- a/src/main/java/org/jabref/gui/preferences/table/TableTab.java +++ b/src/main/java/org/jabref/gui/preferences/table/TableTab.java @@ -66,7 +66,7 @@ public void initialize() { setupBindings(); ActionFactory actionFactory = new ActionFactory(preferencesService.getKeyBindingRepository()); - actionFactory.configureIconButton(StandardActions.HELP_SPECIAL_FIELDS, new HelpAction(HelpFile.SPECIAL_FIELDS, dialogService), specialFieldsHelp); + actionFactory.configureIconButton(StandardActions.HELP_SPECIAL_FIELDS, new HelpAction(HelpFile.SPECIAL_FIELDS, dialogService, preferencesService.getFilePreferences()), specialFieldsHelp); } private void setupTable() { diff --git a/src/main/java/org/jabref/gui/preview/PreviewPanel.java b/src/main/java/org/jabref/gui/preview/PreviewPanel.java index eb57ad53136..eea343507d3 100644 --- a/src/main/java/org/jabref/gui/preview/PreviewPanel.java +++ b/src/main/java/org/jabref/gui/preview/PreviewPanel.java @@ -50,19 +50,19 @@ public class PreviewPanel extends VBox { public PreviewPanel(BibDatabaseContext database, DialogService dialogService, KeyBindingRepository keyBindingRepository, - PreferencesService preferences, + PreferencesService preferencesService, StateManager stateManager, ThemeManager themeManager, IndexingTaskManager indexingTaskManager) { this.keyBindingRepository = keyBindingRepository; this.dialogService = dialogService; this.stateManager = stateManager; - this.previewPreferences = preferences.getPreviewPreferences(); + this.previewPreferences = preferencesService.getPreviewPreferences(); this.indexingTaskManager = indexingTaskManager; - this.fileLinker = new ExternalFilesEntryLinker(preferences.getFilePreferences(), database, dialogService); + this.fileLinker = new ExternalFilesEntryLinker(preferencesService.getFilePreferences(), database, dialogService); - PreviewPreferences previewPreferences = preferences.getPreviewPreferences(); - previewView = new PreviewViewer(database, dialogService, stateManager, themeManager); + PreviewPreferences previewPreferences = preferencesService.getPreviewPreferences(); + previewView = new PreviewViewer(database, dialogService, preferencesService, stateManager, themeManager); previewView.setLayout(previewPreferences.getSelectedPreviewLayout()); previewView.setContextMenu(createPopupMenu()); previewView.setOnDragDetected(event -> { diff --git a/src/main/java/org/jabref/gui/preview/PreviewViewer.java b/src/main/java/org/jabref/gui/preview/PreviewViewer.java index abec8fcab61..979c30a5049 100644 --- a/src/main/java/org/jabref/gui/preview/PreviewViewer.java +++ b/src/main/java/org/jabref/gui/preview/PreviewViewer.java @@ -30,6 +30,7 @@ import org.jabref.logic.util.WebViewStore; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -119,6 +120,7 @@ function getSelectionHtml() { private final ClipBoardManager clipBoardManager; private final DialogService dialogService; + private final PreferencesService preferencesService; private final TaskExecutor taskExecutor = Globals.TASK_EXECUTOR; private final WebView previewView; @@ -143,10 +145,12 @@ function getSelectionHtml() { */ public PreviewViewer(BibDatabaseContext database, DialogService dialogService, + PreferencesService preferencesService, StateManager stateManager, ThemeManager themeManager) { this.database = Objects.requireNonNull(database); this.dialogService = dialogService; + this.preferencesService = preferencesService; this.clipBoardManager = Globals.getClipboardManager(); setFitToHeight(true); @@ -177,7 +181,7 @@ public PreviewViewer(BibDatabaseContext database, String href = anchorElement.getHref(); if (href != null) { try { - JabRefDesktop.openBrowser(href); + JabRefDesktop.openBrowser(href, preferencesService.getFilePreferences()); } catch (MalformedURLException exception) { LOGGER.error("Invalid URL", exception); } catch (IOException exception) { diff --git a/src/main/java/org/jabref/gui/remote/CLIMessageHandler.java b/src/main/java/org/jabref/gui/remote/CLIMessageHandler.java index 5b5330b7282..7ac1ebe879e 100644 --- a/src/main/java/org/jabref/gui/remote/CLIMessageHandler.java +++ b/src/main/java/org/jabref/gui/remote/CLIMessageHandler.java @@ -8,6 +8,7 @@ import org.jabref.gui.JabRefGUI; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.remote.server.RemoteMessageHandler; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.PreferencesService; @@ -20,10 +21,12 @@ public class CLIMessageHandler implements RemoteMessageHandler { private final PreferencesService preferencesService; private final FileUpdateMonitor fileUpdateMonitor; + private final BibEntryTypesManager entryTypesManager; - public CLIMessageHandler(PreferencesService preferencesService, FileUpdateMonitor fileUpdateMonitor) { + public CLIMessageHandler(PreferencesService preferencesService, FileUpdateMonitor fileUpdateMonitor, BibEntryTypesManager entryTypesManager) { this.preferencesService = preferencesService; this.fileUpdateMonitor = fileUpdateMonitor; + this.entryTypesManager = entryTypesManager; } @Override @@ -33,7 +36,8 @@ public void handleCommandLineArguments(String[] message) { message, ArgumentProcessor.Mode.REMOTE_START, preferencesService, - fileUpdateMonitor); + fileUpdateMonitor, + entryTypesManager); List loaded = argumentProcessor.getParserResults(); for (int i = 0; i < loaded.size(); i++) { diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchResultDialog.java b/src/main/java/org/jabref/gui/search/GlobalSearchResultDialog.java index 812125df5f3..14de1499f95 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchResultDialog.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchResultDialog.java @@ -51,7 +51,7 @@ public GlobalSearchResultDialog(UndoManager undoManager) { private void initialize() { viewModel = new GlobalSearchResultDialogViewModel(preferencesService); - PreviewViewer previewViewer = new PreviewViewer(viewModel.getSearchDatabaseContext(), dialogService, stateManager, themeManager); + PreviewViewer previewViewer = new PreviewViewer(viewModel.getSearchDatabaseContext(), dialogService, preferencesService, stateManager, themeManager); previewViewer.setLayout(preferencesService.getPreviewPreferences().getSelectedPreviewLayout()); SearchResultsTableDataModel model = new SearchResultsTableDataModel(viewModel.getSearchDatabaseContext(), preferencesService, stateManager); diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java index 32f844b1515..2430a8bbdae 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java @@ -190,7 +190,7 @@ private boolean openSharedDatabase(DBMSConnectionProperties connectionProperties Localization.lang("However, a new database was created alongside the pre-3.6 one."), ButtonType.OK, openHelp); - result.filter(btn -> btn.equals(openHelp)).ifPresent(btn -> new HelpAction(HelpFile.SQL_DATABASE_MIGRATION, dialogService).execute()); + result.filter(btn -> btn.equals(openHelp)).ifPresent(btn -> new HelpAction(HelpFile.SQL_DATABASE_MIGRATION, dialogService, preferencesService.getFilePreferences()).execute()); result.filter(btn -> btn.equals(ButtonType.OK)).ifPresent(btn -> openSharedDatabase(connectionProperties)); } loading.set(false); diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java index 1a31ac13a18..914c6899b19 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java @@ -98,7 +98,7 @@ public void listen(UpdateRefusedEvent updateRefusedEvent) { Optional response = dialogService.showCustomButtonDialogAndWait(AlertType.CONFIRMATION, Localization.lang("Update refused"), message, ButtonType.CANCEL, merge); if (response.isPresent() && response.get().equals(merge)) { - MergeEntriesDialog dialog = new MergeEntriesDialog(localBibEntry, sharedBibEntry, preferencesService.getBibEntryPreferences()); + MergeEntriesDialog dialog = new MergeEntriesDialog(localBibEntry, sharedBibEntry, preferencesService); dialog.setTitle(Localization.lang("Update refused")); Optional mergedEntry = dialogService.showCustomDialogAndWait(dialog).map(EntriesMergeResult::mergedEntry); diff --git a/src/main/java/org/jabref/gui/util/OpenHyperlinksInExternalBrowser.java b/src/main/java/org/jabref/gui/util/OpenHyperlinksInExternalBrowser.java deleted file mode 100644 index a16c0aa29ee..00000000000 --- a/src/main/java/org/jabref/gui/util/OpenHyperlinksInExternalBrowser.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.jabref.gui.util; - -import java.io.IOException; - -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.concurrent.Worker; -import javafx.concurrent.Worker.State; -import javafx.scene.web.WebView; - -import org.jabref.gui.desktop.JabRefDesktop; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.events.Event; -import org.w3c.dom.events.EventListener; -import org.w3c.dom.events.EventTarget; -import org.w3c.dom.html.HTMLAnchorElement; - -/** - * A Hyperlink Click Listener for javafx.WebView to open links on click in the browser - * Code adapted from: https://stackoverflow.com/a/33445383/ - */ -public class OpenHyperlinksInExternalBrowser implements ChangeListener, EventListener { - - private static final Logger LOGGER = LoggerFactory.getLogger(OpenHyperlinksInExternalBrowser.class); - private static final String CLICK_EVENT = "click"; - private static final String ANCHOR_TAG = "a"; - - private final WebView webView; - - public OpenHyperlinksInExternalBrowser(WebView webView) { - this.webView = webView; - } - - @Override - public void changed(ObservableValue observable, State oldValue, State newValue) { - if (State.SUCCEEDED.equals(newValue)) { - Document document = webView.getEngine().getDocument(); - NodeList anchors = document.getElementsByTagName(ANCHOR_TAG); - for (int i = 0; i < anchors.getLength(); i++) { - Node node = anchors.item(i); - EventTarget eventTarget = (EventTarget) node; - eventTarget.addEventListener(CLICK_EVENT, this, false); - } - } - } - - @Override - public void handleEvent(Event event) { - HTMLAnchorElement anchorElement = (HTMLAnchorElement) event.getCurrentTarget(); - String href = anchorElement.getHref(); - - try { - JabRefDesktop.openBrowser(href); - } catch (IOException e) { - LOGGER.error("Problem opening browser", e); - } - event.preventDefault(); - } -} diff --git a/src/main/java/org/jabref/logic/exporter/Exporter.java b/src/main/java/org/jabref/logic/exporter/Exporter.java index 9bcbb9aa931..61e1c5751ae 100644 --- a/src/main/java/org/jabref/logic/exporter/Exporter.java +++ b/src/main/java/org/jabref/logic/exporter/Exporter.java @@ -8,7 +8,6 @@ import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.util.FileType; -import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.LinkedFile; @@ -103,7 +102,6 @@ public boolean exportToAllFilesOfEntry(BibDatabaseContext databaseContext, * If it extends existing information, all found bib-entries will be exported. * * @param databaseContext the database-context to export from - * @param dataBase the database to export from * @param filePreferences the filePreferences to use for resolving paths * @param filePath the path to the file we want to write on * @param abbreviationRepository the opened repository of journal abbreviations @@ -111,7 +109,6 @@ public boolean exportToAllFilesOfEntry(BibDatabaseContext databaseContext, * @throws Exception if the writing fails */ public boolean exportToFileByPath(BibDatabaseContext databaseContext, - BibDatabase dataBase, FilePreferences filePreferences, Path filePath, JournalAbbreviationRepository abbreviationRepository) throws Exception { @@ -119,7 +116,7 @@ public boolean exportToFileByPath(BibDatabaseContext databaseContext, return false; } boolean writtenABibEntry = false; - for (BibEntry entry : dataBase.getEntries()) { + for (BibEntry entry : databaseContext.getEntries()) { for (LinkedFile linkedFile : entry.getFiles()) { if (linkedFile.getFileType().equals(fileType.getName())) { Optional linkedFilePath = linkedFile.findIn(databaseContext.getFileDirectories(filePreferences)); diff --git a/src/main/java/org/jabref/migrations/CustomEntryTypePreferenceMigration.java b/src/main/java/org/jabref/migrations/CustomEntryTypePreferenceMigration.java index 7159ba1714c..e2973ea207a 100644 --- a/src/main/java/org/jabref/migrations/CustomEntryTypePreferenceMigration.java +++ b/src/main/java/org/jabref/migrations/CustomEntryTypePreferenceMigration.java @@ -5,10 +5,10 @@ import java.util.Optional; import java.util.stream.Collectors; -import org.jabref.gui.Globals; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.BibEntryTypeBuilder; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.FieldFactory; import org.jabref.model.entry.types.EntryTypeFactory; import org.jabref.preferences.JabRefPreferences; @@ -21,23 +21,23 @@ class CustomEntryTypePreferenceMigration { private static final String CUSTOM_TYPE_OPT = "customTypeOpt_"; private static final String CUSTOM_TYPE_PRIOPT = "customTypePriOpt_"; - private static JabRefPreferences prefs = Globals.prefs; - private CustomEntryTypePreferenceMigration() { } - static void upgradeStoredBibEntryTypes(BibDatabaseMode defaultBibDatabaseMode) { + static void upgradeStoredBibEntryTypes(BibDatabaseMode defaultBibDatabaseMode, + JabRefPreferences preferences, + BibEntryTypesManager entryTypesManager) { List storedOldTypes = new ArrayList<>(); int number = 0; Optional type; - while ((type = getBibEntryType(number)).isPresent()) { - Globals.entryTypesManager.addCustomOrModifiedType(type.get(), defaultBibDatabaseMode); + while ((type = getBibEntryType(number, preferences)).isPresent()) { + entryTypesManager.addCustomOrModifiedType(type.get(), defaultBibDatabaseMode); storedOldTypes.add(type.get()); number++; } - prefs.storeCustomEntryTypesRepository(Globals.entryTypesManager); + preferences.storeCustomEntryTypesRepository(entryTypesManager); } /** @@ -45,15 +45,15 @@ static void upgradeStoredBibEntryTypes(BibDatabaseMode defaultBibDatabaseMode) { *

* (old implementation which has been copied) */ - private static Optional getBibEntryType(int number) { + private static Optional getBibEntryType(int number, JabRefPreferences preferences) { String nr = String.valueOf(number); - String name = prefs.get(CUSTOM_TYPE_NAME + nr); + String name = preferences.get(CUSTOM_TYPE_NAME + nr); if (name == null) { return Optional.empty(); } - List req = prefs.getStringList(CUSTOM_TYPE_REQ + nr); - List opt = prefs.getStringList(CUSTOM_TYPE_OPT + nr); - List priOpt = prefs.getStringList(CUSTOM_TYPE_PRIOPT + nr); + List req = preferences.getStringList(CUSTOM_TYPE_REQ + nr); + List opt = preferences.getStringList(CUSTOM_TYPE_OPT + nr); + List priOpt = preferences.getStringList(CUSTOM_TYPE_PRIOPT + nr); BibEntryTypeBuilder entryTypeBuilder = new BibEntryTypeBuilder() .withType(EntryTypeFactory.parse(name)) diff --git a/src/main/java/org/jabref/migrations/PreferencesMigrations.java b/src/main/java/org/jabref/migrations/PreferencesMigrations.java index 0b50da1850d..09738861b2a 100644 --- a/src/main/java/org/jabref/migrations/PreferencesMigrations.java +++ b/src/main/java/org/jabref/migrations/PreferencesMigrations.java @@ -22,6 +22,7 @@ import org.jabref.logic.cleanup.FieldFormatterCleanups; import org.jabref.logic.shared.security.Password; import org.jabref.logic.util.OS; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.SpecialField; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.EntryTypeFactory; @@ -43,7 +44,7 @@ private PreferencesMigrations() { /** * Perform checks and changes for users with a preference set from an older JabRef version. */ - public static void runMigrations(JabRefPreferences preferences) { + public static void runMigrations(JabRefPreferences preferences, BibEntryTypesManager entryTypesManager) { Preferences mainPrefsNode = Preferences.userRoot().node("/org/jabref"); upgradePrefsToOrgJabRef(mainPrefsNode); @@ -51,7 +52,7 @@ public static void runMigrations(JabRefPreferences preferences) { upgradeFaultyEncodingStrings(preferences); upgradeLabelPatternToCitationKeyPattern(preferences, mainPrefsNode); upgradeImportFileAndDirePatterns(preferences, mainPrefsNode); - upgradeStoredBibEntryTypes(preferences, mainPrefsNode); + upgradeStoredBibEntryTypes(preferences, mainPrefsNode, entryTypesManager); upgradeKeyBindingsToJavaFX(preferences); addCrossRefRelatedFieldsForAutoComplete(preferences); upgradePreviewStyle(preferences); @@ -169,14 +170,17 @@ private static void upgradeSortOrder(JabRefPreferences prefs) { /** * Migrate all customized entry types from versions <=3.7 */ - private static void upgradeStoredBibEntryTypes(JabRefPreferences prefs, Preferences mainPrefsNode) { + private static void upgradeStoredBibEntryTypes(JabRefPreferences prefs, Preferences mainPrefsNode, BibEntryTypesManager entryTypesManager) { try { if (mainPrefsNode.nodeExists(JabRefPreferences.CUSTOMIZED_BIBTEX_TYPES) || mainPrefsNode.nodeExists(JabRefPreferences.CUSTOMIZED_BIBLATEX_TYPES)) { // skip further processing as prefs already have been migrated } else { LOGGER.info("Migrating old custom entry types."); - CustomEntryTypePreferenceMigration.upgradeStoredBibEntryTypes(prefs.getLibraryPreferences().getDefaultBibDatabaseMode()); + CustomEntryTypePreferenceMigration.upgradeStoredBibEntryTypes( + prefs.getLibraryPreferences().getDefaultBibDatabaseMode(), + prefs, + entryTypesManager); } } catch (BackingStoreException ex) { LOGGER.error("Migrating old custom entry types failed.", ex); diff --git a/src/test/java/org/jabref/cli/ArgumentProcessorTest.java b/src/test/java/org/jabref/cli/ArgumentProcessorTest.java index 5538a3dba81..78dcb77f755 100644 --- a/src/test/java/org/jabref/cli/ArgumentProcessorTest.java +++ b/src/test/java/org/jabref/cli/ArgumentProcessorTest.java @@ -14,6 +14,7 @@ import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.fileformat.BibtexImporter; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.search.rules.SearchRules; import org.jabref.model.util.DummyFileUpdateMonitor; import org.jabref.model.util.FileUpdateMonitor; @@ -34,6 +35,7 @@ class ArgumentProcessorTest { private ArgumentProcessor processor; private BibtexImporter bibtexImporter; private final PreferencesService preferencesService = mock(PreferencesService.class, Answers.RETURNS_DEEP_STUBS); + private final BibEntryTypesManager entryTypesManager = mock(BibEntryTypesManager.class); private final ImporterPreferences importerPreferences = mock(ImporterPreferences.class, Answers.RETURNS_DEEP_STUBS); private final ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); @@ -62,7 +64,8 @@ void testAuxImport(@TempDir Path tempDir) throws Exception { args.toArray(String[]::new), Mode.INITIAL_START, preferencesService, - mock(FileUpdateMonitor.class)); + mock(FileUpdateMonitor.class), + entryTypesManager); assertTrue(Files.exists(outputBib)); } @@ -87,7 +90,8 @@ void testExportMatches(@TempDir Path tempDir) throws Exception { args.toArray(String[]::new), Mode.INITIAL_START, preferencesService, - mock(FileUpdateMonitor.class)); + mock(FileUpdateMonitor.class), + entryTypesManager); assertTrue(Files.exists(outputBib)); BibEntryAssert.assertEquals(expectedEntries, outputBib, bibtexImporter); diff --git a/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java b/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java index a2ae4666810..f9f41a73ab4 100644 --- a/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java +++ b/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java @@ -18,6 +18,7 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.UnknownField; import org.jabref.model.util.DummyFileUpdateMonitor; import org.jabref.testutils.category.GUITest; @@ -63,6 +64,7 @@ public void onStart(Stage stage) { new DummyFileUpdateMonitor(), mock(DialogService.class), stateManager, + mock(BibEntryTypesManager.class), keyBindingRepository); pane = new TabPane( new Tab("main area", area), diff --git a/src/test/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModelTest.java b/src/test/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModelTest.java index cc057020e4f..7280c3e33e1 100644 --- a/src/test/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModelTest.java +++ b/src/test/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModelTest.java @@ -8,7 +8,9 @@ import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibtexString; +import org.jabref.preferences.FilePreferences; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -17,6 +19,15 @@ class ConstantsPropertiesViewModelTest { + private DialogService service; + private FilePreferences filePreferences; + + @BeforeEach + void setUp() { + service = mock(DialogService.class); + filePreferences = mock(FilePreferences.class); + } + @DisplayName("Check that the list of strings is sorted according to their keys") @Test void testStringsListPropertySorting() { @@ -25,10 +36,9 @@ void testStringsListPropertySorting() { BibDatabase db = new BibDatabase(); db.setStrings(List.of(string1, string2)); BibDatabaseContext context = new BibDatabaseContext(db); - DialogService service = mock(DialogService.class); List expected = List.of(string2.getName(), string1.getName()); // ICSE before TSE - ConstantsPropertiesViewModel model = new ConstantsPropertiesViewModel(context, service); + ConstantsPropertiesViewModel model = new ConstantsPropertiesViewModel(context, service, filePreferences); model.setValues(); List actual = model.stringsListProperty().stream() @@ -44,10 +54,9 @@ void testStringsListPropertySorting() { void testStringsListPropertyResorting() { BibDatabase db = new BibDatabase(); BibDatabaseContext context = new BibDatabaseContext(db); - DialogService service = mock(DialogService.class); List expected = List.of("ICSE", "TSE"); - ConstantsPropertiesViewModel model = new ConstantsPropertiesViewModel(context, service); + ConstantsPropertiesViewModel model = new ConstantsPropertiesViewModel(context, service, filePreferences); var stringsList = model.stringsListProperty(); stringsList.add(new ConstantsItemModel("TSE", "Transactions on Software Engineering")); stringsList.add(new ConstantsItemModel("ICSE", "International Conference on Software Engineering")); diff --git a/src/test/java/org/jabref/logic/exporter/EmbeddedBibFilePdfExporterTest.java b/src/test/java/org/jabref/logic/exporter/EmbeddedBibFilePdfExporterTest.java index 0bf78d73c2b..dc669e07dac 100644 --- a/src/test/java/org/jabref/logic/exporter/EmbeddedBibFilePdfExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/EmbeddedBibFilePdfExporterTest.java @@ -43,7 +43,6 @@ class EmbeddedBibFilePdfExporterTest { private EmbeddedBibFilePdfExporter exporter; private BibDatabaseContext databaseContext; - private BibDatabase dataBase; private JournalAbbreviationRepository abbreviationRepository; private FilePreferences filePreferences; @@ -111,7 +110,7 @@ void setUp() throws IOException { exporter = new EmbeddedBibFilePdfExporter(bibDatabaseMode, bibEntryTypesManager, fieldPreferences); databaseContext = new BibDatabaseContext(); - dataBase = databaseContext.getDatabase(); + BibDatabase dataBase = databaseContext.getDatabase(); initBibEntries(); dataBase.insertEntry(olly2018); @@ -142,13 +141,13 @@ public static Stream provideBibEntriesWithInvalidPdfFileLinks() { @ParameterizedTest @MethodSource("providePathsToValidPDFs") void successfulExportToFileByPath(Path path) throws Exception { - assertTrue(exporter.exportToFileByPath(databaseContext, dataBase, filePreferences, path, abbreviationRepository)); + assertTrue(exporter.exportToFileByPath(databaseContext, filePreferences, path, abbreviationRepository)); } @ParameterizedTest @MethodSource("providePathsToInvalidPDFs") void unsuccessfulExportToFileByPath(Path path) throws Exception { - assertFalse(exporter.exportToFileByPath(databaseContext, dataBase, filePreferences, path, abbreviationRepository)); + assertFalse(exporter.exportToFileByPath(databaseContext, filePreferences, path, abbreviationRepository)); } public static Stream providePathsToValidPDFs() { diff --git a/src/test/java/org/jabref/logic/exporter/XmpPdfExporterTest.java b/src/test/java/org/jabref/logic/exporter/XmpPdfExporterTest.java index 2e630f3ae27..3e07fd1f085 100644 --- a/src/test/java/org/jabref/logic/exporter/XmpPdfExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/XmpPdfExporterTest.java @@ -1,7 +1,6 @@ package org.jabref.logic.exporter; import java.io.IOException; -import java.nio.charset.Charset; import java.nio.file.Path; import java.util.Collections; import java.util.List; @@ -9,7 +8,6 @@ import javafx.beans.property.SimpleObjectProperty; -import org.jabref.logic.importer.fileformat.PdfXmpImporter; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabase; @@ -42,13 +40,9 @@ class XmpPdfExporterTest { private static BibEntry toral2006 = new BibEntry(StandardEntryType.Article); private static BibEntry vapnik2000 = new BibEntry(StandardEntryType.Article); - private PdfXmpImporter importer; private XmpPdfExporter exporter; - private XmpPreferences xmpPreferences; - private Charset encoding; private BibDatabaseContext databaseContext; - private BibDatabase dataBase; private JournalAbbreviationRepository abbreviationRepository; private FilePreferences filePreferences; @@ -101,20 +95,15 @@ private static void initBibEntries() throws IOException { @BeforeEach void setUp() throws IOException { abbreviationRepository = mock(JournalAbbreviationRepository.class); - - xmpPreferences = new XmpPreferences(false, Collections.emptySet(), new SimpleObjectProperty<>(',')); - - encoding = Charset.defaultCharset(); - filePreferences = mock(FilePreferences.class); when(filePreferences.getUserAndHost()).thenReturn(tempDir.toAbsolutePath().toString()); when(filePreferences.shouldStoreFilesRelativeToBibFile()).thenReturn(false); - importer = new PdfXmpImporter(xmpPreferences); + XmpPreferences xmpPreferences = new XmpPreferences(false, Collections.emptySet(), new SimpleObjectProperty<>(',')); exporter = new XmpPdfExporter(xmpPreferences); databaseContext = new BibDatabaseContext(); - dataBase = databaseContext.getDatabase(); + BibDatabase dataBase = databaseContext.getDatabase(); initBibEntries(); dataBase.insertEntry(olly2018); @@ -145,13 +134,13 @@ public static Stream provideBibEntriesWithInvalidPdfFileLinks() { @ParameterizedTest @MethodSource("providePathsToValidPDFs") void successfulExportToFileByPath(Path path) throws Exception { - assertTrue(exporter.exportToFileByPath(databaseContext, dataBase, filePreferences, path, abbreviationRepository)); + assertTrue(exporter.exportToFileByPath(databaseContext, filePreferences, path, abbreviationRepository)); } @ParameterizedTest @MethodSource("providePathsToInvalidPDFs") void unsuccessfulExportToFileByPath(Path path) throws Exception { - assertFalse(exporter.exportToFileByPath(databaseContext, dataBase, filePreferences, path, abbreviationRepository)); + assertFalse(exporter.exportToFileByPath(databaseContext, filePreferences, path, abbreviationRepository)); } public static Stream providePathsToValidPDFs() {