diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index f4337d33545..267526d0ad7 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -34,6 +34,7 @@ import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.StandardActions; +import org.jabref.gui.frame.ExternalApplicationsPreferences; import org.jabref.gui.help.HelpAction; import org.jabref.gui.icon.IconTheme; import org.jabref.gui.preferences.GuiPreferences; @@ -47,6 +48,7 @@ import org.jabref.logic.help.HelpFile; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.layout.LayoutFormatterPreferences; import org.jabref.logic.openoffice.OpenOfficeFileSearch; import org.jabref.logic.openoffice.OpenOfficePreferences; import org.jabref.logic.openoffice.action.Update; @@ -95,6 +97,8 @@ public class OpenOfficePanel { private final VBox vbox = new VBox(); private final GuiPreferences preferences; + private final OpenOfficePreferences openOfficePreferences; + private final CitationKeyPatternPreferences citationKeyPatternPreferences; private final StateManager stateManager; private final ClipBoardManager clipBoardManager; private final UndoManager undoManager; @@ -103,7 +107,6 @@ public class OpenOfficePanel { private final LibraryTabContainer tabContainer; private final FileUpdateMonitor fileUpdateMonitor; private final BibEntryTypesManager entryTypesManager; - private final OpenOfficePreferences openOfficePreferences; private OOBibBase ooBase; private OOStyle currentStyle; @@ -111,6 +114,10 @@ public class OpenOfficePanel { public OpenOfficePanel(LibraryTabContainer tabContainer, GuiPreferences preferences, + OpenOfficePreferences openOfficePreferences, + ExternalApplicationsPreferences externalApplicationsPreferences, + LayoutFormatterPreferences layoutFormatterPreferences, + CitationKeyPatternPreferences citationKeyPatternPreferences, JournalAbbreviationRepository abbreviationRepository, UiTaskExecutor taskExecutor, DialogService dialogService, @@ -123,13 +130,14 @@ public OpenOfficePanel(LibraryTabContainer tabContainer, this.fileUpdateMonitor = fileUpdateMonitor; this.entryTypesManager = entryTypesManager; this.preferences = preferences; + this.openOfficePreferences = openOfficePreferences; + this.citationKeyPatternPreferences = citationKeyPatternPreferences; this.taskExecutor = taskExecutor; this.dialogService = dialogService; this.stateManager = stateManager; this.clipBoardManager = clipBoardManager; this.undoManager = undoManager; - this.currentStyle = preferences.getOpenOfficePreferences().getCurrentStyle(); - this.openOfficePreferences = preferences.getOpenOfficePreferences(); + this.currentStyle = openOfficePreferences.getCurrentStyle(); ActionFactory factory = new ActionFactory(); @@ -143,7 +151,7 @@ public OpenOfficePanel(LibraryTabContainer tabContainer, manualConnect.setTooltip(new Tooltip(Localization.lang("Manual connect"))); manualConnect.setMaxWidth(Double.MAX_VALUE); - help = factory.createIconButton(StandardActions.HELP, new HelpAction(HelpFile.OPENOFFICE_LIBREOFFICE, dialogService, preferences.getExternalApplicationsPreferences())); + help = factory.createIconButton(StandardActions.HELP, new HelpAction(HelpFile.OPENOFFICE_LIBREOFFICE, dialogService, externalApplicationsPreferences)); help.setMaxWidth(Double.MAX_VALUE); selectDocument = new Button(); @@ -157,8 +165,8 @@ public OpenOfficePanel(LibraryTabContainer tabContainer, update.setMaxWidth(Double.MAX_VALUE); loader = new StyleLoader( - preferences.getOpenOfficePreferences(), - preferences.getLayoutFormatterPreferences(), + openOfficePreferences, + layoutFormatterPreferences, abbreviationRepository); currentStyleProperty = new SimpleObjectProperty<>(currentStyle); @@ -327,7 +335,7 @@ private void exportEntries() { private List getBaseList() { List databases = new ArrayList<>(); - if (preferences.getOpenOfficePreferences().getUseAllDatabases()) { + if (openOfficePreferences.getUseAllDatabases()) { for (BibDatabaseContext database : stateManager.getOpenDatabases()) { databases.add(database.getDatabase()); } @@ -341,7 +349,7 @@ private List getBaseList() { } private void connectAutomatically() { - DetectOpenOfficeInstallation officeInstallation = new DetectOpenOfficeInstallation(preferences.getOpenOfficePreferences(), dialogService); + DetectOpenOfficeInstallation officeInstallation = new DetectOpenOfficeInstallation(openOfficePreferences, dialogService); if (officeInstallation.isExecutablePathDefined()) { connect(); @@ -375,7 +383,7 @@ private void connectManually() { var fileDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(System.getProperty("user.home")).build(); Optional selectedPath = dialogService.showDirectorySelectionDialog(fileDialogConfiguration); - DetectOpenOfficeInstallation officeInstallation = new DetectOpenOfficeInstallation(preferences.getOpenOfficePreferences(), dialogService); + DetectOpenOfficeInstallation officeInstallation = new DetectOpenOfficeInstallation(openOfficePreferences, dialogService); if (selectedPath.isPresent()) { BackgroundTask.wrap(() -> officeInstallation.setOpenOfficePreferences(selectedPath.get())) @@ -394,30 +402,24 @@ private void connectManually() { } private void updateButtonAvailability() { - boolean isConnected = ooBase != null; - boolean isConnectedToDocument = isConnected && !ooBase.isDocumentConnectionMissing(); - - // For these, we need to watch something - boolean hasStyle = true; // (style != null); - boolean hasDatabase = true; // !getBaseList().isEmpty(); - boolean hasSelectedBibEntry = true; + boolean isConnectedToDocument = (ooBase != null && !ooBase.isDocumentConnectionMissing()); + boolean hasStyle = (currentStyle != null); + boolean hasDatabase = !getBaseList().isEmpty(); + boolean canCite = isConnectedToDocument && hasStyle && hasDatabase; + boolean canRefreshDocument = isConnectedToDocument && hasStyle; + boolean cslStyleSelected = currentStyle instanceof CitationStyle; - selectDocument.setDisable(!isConnected); - pushEntries.setDisable(!(isConnectedToDocument && hasStyle && hasDatabase)); + selectDocument.setDisable(!isConnectedToDocument); - boolean canCite = isConnectedToDocument && hasStyle && hasSelectedBibEntry; - boolean cslStyleSelected = preferences.getOpenOfficePreferences().getCurrentStyle() instanceof CitationStyle; + pushEntries.setDisable(!canCite); pushEntriesInt.setDisable(!canCite); pushEntriesEmpty.setDisable(!canCite); pushEntriesAdvanced.setDisable(!canCite || cslStyleSelected); - boolean canRefreshDocument = isConnectedToDocument && hasStyle; - update.setDisable(!canRefreshDocument); merge.setDisable(!canRefreshDocument || cslStyleSelected); unmerge.setDisable(!canRefreshDocument || cslStyleSelected); manageCitations.setDisable(!canRefreshDocument || cslStyleSelected); - exportCitations.setDisable(!(isConnectedToDocument && hasDatabase) || cslStyleSelected); } @@ -427,7 +429,7 @@ private void connect() { protected OOBibBase call() throws BootstrapException, CreationException { updateProgress(ProgressBar.INDETERMINATE_PROGRESS, ProgressBar.INDETERMINATE_PROGRESS); - Path path = Path.of(preferences.getOpenOfficePreferences().getExecutablePath()); + Path path = Path.of(openOfficePreferences.getExecutablePath()); return createBibBase(path); } }; @@ -451,13 +453,13 @@ protected OOBibBase call() throws BootstrapException, CreationException { LOGGER.error("autodetect failed", ex); switch (ex) { case UnsatisfiedLinkError unsatisfiedLinkError -> { - LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", ex); + LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", unsatisfiedLinkError); dialogService.showErrorDialogAndWait(Localization.lang("Unable to connect. One possible reason is that JabRef " + "and OpenOffice/LibreOffice are not both running in either 32 bit mode or 64 bit mode.")); } case IOException ioException -> { - LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", ex); + LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", ioException); dialogService.showErrorDialogAndWait(Localization.lang("Could not connect to running OpenOffice/LibreOffice."), Localization.lang("Could not connect to running OpenOffice/LibreOffice.") @@ -502,23 +504,19 @@ private static CitationType citationTypeFromOptions(boolean withText, boolean in private void pushEntries(CitationType citationType, boolean addPageInfo) { final String errorDialogTitle = Localization.lang("Error pushing entries"); - if (stateManager.getActiveDatabase().isEmpty() - || (stateManager.getActiveDatabase().get().getDatabase() == null)) { - OOError.noDataBaseIsOpenForCiting() - .setTitle(errorDialogTitle) - .showErrorDialog(dialogService); - return; - } + final Optional activeDatabase = stateManager.getActiveDatabase(); - final BibDatabaseContext bibDatabaseContext = stateManager.getActiveDatabase().get(); - if (bibDatabaseContext == null) { + if (activeDatabase.isEmpty() || (activeDatabase.get().getDatabase() == null)) { OOError.noDataBaseIsOpenForCiting() .setTitle(errorDialogTitle) .showErrorDialog(dialogService); return; } + final BibDatabaseContext bibDatabaseContext = activeDatabase.get(); + List entries = stateManager.getSelectedEntries(); + if (entries.isEmpty()) { OOError.noEntriesSelectedForCitation() .setTitle(errorDialogTitle) @@ -553,12 +551,12 @@ private void pushEntries(CitationType citationType, boolean addPageInfo) { } Optional syncOptions = - preferences.getOpenOfficePreferences().getSyncWhenCiting() + openOfficePreferences.getSyncWhenCiting() ? Optional.of(new Update.SyncOptions(getBaseList())) : Optional.empty(); // Sync options are non-null only when "Automatically sync bibliography when inserting citations" is enabled - if (syncOptions.isPresent() && preferences.getOpenOfficePreferences().getSyncWhenCiting()) { + if (syncOptions.isPresent() && openOfficePreferences.getSyncWhenCiting()) { syncOptions.get().setUpdateBibliography(true); } ooBase.guiActionInsertEntry(entries, @@ -601,12 +599,11 @@ private boolean checkThatEntriesHaveKeys(List entries) { Optional databaseContext = stateManager.getActiveDatabase(); if (citePressed && databaseContext.isPresent()) { // Generate keys - CitationKeyPatternPreferences prefs = preferences.getCitationKeyPatternPreferences(); NamedCompound undoCompound = new NamedCompound(Localization.lang("Cite")); for (BibEntry entry : entries) { if (entry.getCitationKey().isEmpty()) { // Generate key - new CitationKeyGenerator(databaseContext.get(), prefs) + new CitationKeyGenerator(databaseContext.get(), citationKeyPatternPreferences) .generateAndSetKey(entry) .ifPresent(change -> undoCompound.addEdit(new UndoableKeyChange(change))); } diff --git a/src/main/java/org/jabref/gui/sidepane/SidePaneContentFactory.java b/src/main/java/org/jabref/gui/sidepane/SidePaneContentFactory.java index 6d364aab9a1..171fc8b8777 100644 --- a/src/main/java/org/jabref/gui/sidepane/SidePaneContentFactory.java +++ b/src/main/java/org/jabref/gui/sidepane/SidePaneContentFactory.java @@ -67,6 +67,10 @@ public Node create(SidePaneType sidePaneType) { case OPEN_OFFICE -> new OpenOfficePanel( tabContainer, preferences, + preferences.getOpenOfficePreferences(), + preferences.getExternalApplicationsPreferences(), + preferences.getLayoutFormatterPreferences(), + preferences.getCitationKeyPatternPreferences(), abbreviationRepository, (UiTaskExecutor) taskExecutor, dialogService,