From 35cd5d03e106c102b9d2aad3dbd54038ddc2728a Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 5 Jun 2022 18:09:38 +0200 Subject: [PATCH] Fix linux file opening by using Process Builder (#8853) * Fix linux file opening by using Process Builder Fixes #8831 Co-authored-by: ThiloteE * checkstyle * add comment on nemo Co-authored-by: ThiloteE * Refactor terminal opening as well Co-authored-by: ThiloteE * Split ProcessBuilder arguments into Array Co-authored-by: Siedlerchr siedlerkiller@gmail.com * Refactor passing of dialog servie Set directory for terminal * fix checkstyle * checkstyle * remove blank line * add missing l10n * add changelog Co-authored-by: ThiloteE Co-authored-by: Benedikt Tutzer --- CHANGELOG.md | 1 + src/main/java/org/jabref/gui/JabRefFrame.java | 31 ++++---- .../org/jabref/gui/OpenConsoleAction.java | 10 ++- .../org/jabref/gui/SendAsEMailAction.java | 2 +- .../org/jabref/gui/desktop/JabRefDesktop.java | 20 ++--- .../jabref/gui/desktop/os/DefaultDesktop.java | 3 +- .../java/org/jabref/gui/desktop/os/Linux.java | 77 +++++++++++++------ .../jabref/gui/desktop/os/NativeDesktop.java | 5 +- .../java/org/jabref/gui/desktop/os/OSX.java | 8 +- .../org/jabref/gui/desktop/os/Windows.java | 3 +- .../DuplicateResolverDialog.java | 7 +- .../duplicationFinder/DuplicateSearch.java | 2 +- .../jabref/gui/edit/OpenBrowserAction.java | 7 +- .../jabref/gui/entryeditor/EntryEditor.java | 2 +- .../jabref/gui/exporter/ExportCommand.java | 2 +- .../gui/externalfiles/ImportHandler.java | 2 +- .../gui/fieldeditors/LinkedFileViewModel.java | 2 +- .../gui/groups/GroupDialogViewModel.java | 2 +- .../java/org/jabref/gui/help/HelpAction.java | 20 ++--- .../org/jabref/gui/help/NewVersionDialog.java | 7 +- .../org/jabref/gui/help/VersionWorker.java | 2 +- .../gui/importer/ImportEntriesViewModel.java | 4 +- .../importer/fetcher/WebSearchPaneView.java | 4 +- .../constants/ConstantsPropertiesView.java | 4 +- .../ConstantsPropertiesViewModel.java | 8 +- .../keypattern/KeyPatternPropertiesView.java | 2 +- .../gui/openoffice/OpenOfficePanel.java | 2 +- .../CitationKeyPatternTab.java | 2 +- .../CustomEditorFieldsTab.java | 2 +- .../jabref/gui/preferences/file/FileTab.java | 2 +- .../gui/preferences/general/GeneralTab.java | 2 +- .../linkedfiles/LinkedFilesTab.java | 2 +- .../nameformatter/NameFormatterTab.java | 2 +- .../gui/preferences/network/NetworkTab.java | 2 +- .../gui/preferences/table/TableTab.java | 2 +- .../SharedDatabaseLoginDialogViewModel.java | 2 +- src/main/resources/l10n/JabRef_en.properties | 1 + .../gui/util/OpenConsoleActionTest.java | 6 +- 38 files changed, 157 insertions(+), 107 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de3230689b5..e3d23b986ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ### Fixed +- We fixed an issue where "open folder" for linked files did not open the folder and did not select the file unter certain Linux desktop environments [#8679](https://github.com/JabRef/jabref/issues/8679), [#8849](https://github.com/JabRef/jabref/issues/8849) - We fixed an issue where the content of a big shared database library is not shown [#8788](https://github.com/JabRef/jabref/issues/8788) - We fixed the unnecessary horizontal scroll bar in group panel [#8467](https://github.com/JabRef/jabref/issues/8467) - We fixed an issue where the notification bar message, icon and actions appeared to be invisible. [#8761](https://github.com/JabRef/jabref/issues/8761) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index c140bb85c0d..efd992dd688 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -124,6 +124,7 @@ import org.jabref.logic.autosaveandbackup.AutosaveManager; import org.jabref.logic.autosaveandbackup.BackupManager; import org.jabref.logic.citationstyle.CitationStyleOutputFormat; +import org.jabref.logic.help.HelpFile; import org.jabref.logic.importer.IdFetcher; import org.jabref.logic.importer.ImportCleanup; import org.jabref.logic.importer.ParserResult; @@ -337,7 +338,7 @@ public void openAction(String filePath) { * The MacAdapter calls this method when "About" is selected from the application menu. */ public void about() { - HelpAction.getMainHelpPageCommand().execute(); + new HelpAction(HelpFile.CONTENTS, dialogService).execute(); } /** @@ -534,7 +535,7 @@ private Node createToolbar() { new Separator(Orientation.VERTICAL), new HBox( - factory.createIconButton(StandardActions.OPEN_GITHUB, new OpenBrowserAction("https://github.com/JabRef/jabref")))); + factory.createIconButton(StandardActions.OPEN_GITHUB, new OpenBrowserAction("https://github.com/JabRef/jabref", dialogService)))); leftSpacer.setPrefWidth(50); leftSpacer.setMinWidth(Region.USE_PREF_SIZE); @@ -854,7 +855,7 @@ private MenuBar createMenu() { factory.createMenuItem(StandardActions.SHOW_PDF_VIEWER, new ShowDocumentViewerAction(stateManager, prefs)), factory.createMenuItem(StandardActions.EDIT_ENTRY, new OpenEntryEditorAction(this, stateManager)), - factory.createMenuItem(StandardActions.OPEN_CONSOLE, new OpenConsoleAction(stateManager, prefs)) + factory.createMenuItem(StandardActions.OPEN_CONSOLE, new OpenConsoleAction(stateManager, prefs, dialogService)) ); options.getItems().addAll( @@ -867,8 +868,8 @@ private MenuBar createMenu() { ); help.getItems().addAll( - factory.createMenuItem(StandardActions.HELP, HelpAction.getMainHelpPageCommand()), - factory.createMenuItem(StandardActions.OPEN_FORUM, new OpenBrowserAction("http://discourse.jabref.org/")), + factory.createMenuItem(StandardActions.HELP, new HelpAction(HelpFile.CONTENTS, dialogService)), + factory.createMenuItem(StandardActions.OPEN_FORUM, new OpenBrowserAction("http://discourse.jabref.org/", dialogService)), new SeparatorMenuItem(), @@ -876,19 +877,19 @@ private MenuBar createMenu() { new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.DONATE, new OpenBrowserAction("https://donations.jabref.org")), + 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.createSubMenu(StandardActions.WEB_MENU, - factory.createMenuItem(StandardActions.OPEN_WEBPAGE, new OpenBrowserAction("https://jabref.org/")), - factory.createMenuItem(StandardActions.OPEN_BLOG, new OpenBrowserAction("https://blog.jabref.org/")), - factory.createMenuItem(StandardActions.OPEN_FACEBOOK, new OpenBrowserAction("https://www.facebook.com/JabRef/")), - factory.createMenuItem(StandardActions.OPEN_TWITTER, new OpenBrowserAction("https://twitter.com/jabref_org")), - factory.createMenuItem(StandardActions.OPEN_GITHUB, new OpenBrowserAction("https://github.com/JabRef/jabref")), + 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)), new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.OPEN_DEV_VERSION_LINK, new OpenBrowserAction("https://builds.jabref.org/master/")), - factory.createMenuItem(StandardActions.OPEN_CHANGELOG, new OpenBrowserAction("https://github.com/JabRef/jabref/blob/main/CHANGELOG.md")) + 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.ABOUT, new AboutAction()) ); @@ -1043,7 +1044,7 @@ private ContextMenu createTabContextMenuFor(LibraryTab tab, KeyBindingRepository contextMenu.getItems().addAll( factory.createMenuItem(StandardActions.LIBRARY_PROPERTIES, new LibraryPropertiesAction(tab::getBibDatabaseContext, stateManager)), factory.createMenuItem(StandardActions.OPEN_DATABASE_FOLDER, new OpenDatabaseFolder(tab::getBibDatabaseContext)), - factory.createMenuItem(StandardActions.OPEN_CONSOLE, new OpenConsoleAction(tab::getBibDatabaseContext, stateManager, prefs)), + factory.createMenuItem(StandardActions.OPEN_CONSOLE, new OpenConsoleAction(tab::getBibDatabaseContext, stateManager, prefs, dialogService)), new SeparatorMenuItem(), factory.createMenuItem(StandardActions.CLOSE_LIBRARY, new CloseDatabaseAction(tab)), factory.createMenuItem(StandardActions.CLOSE_OTHER_LIBRARIES, new CloseOthersDatabaseAction(tab)), @@ -1341,7 +1342,7 @@ public OpenDatabaseFolder(Supplier databaseContext) { public void execute() { Optional.of(databaseContext.get()).flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> { try { - JabRefDesktop.openFolderAndSelectFile(path, prefs); + JabRefDesktop.openFolderAndSelectFile(path, prefs, dialogService); } catch (IOException e) { LOGGER.info("Could not open folder", e); } diff --git a/src/main/java/org/jabref/gui/OpenConsoleAction.java b/src/main/java/org/jabref/gui/OpenConsoleAction.java index 52ddf7fb4a0..b470e1e3ef0 100644 --- a/src/main/java/org/jabref/gui/OpenConsoleAction.java +++ b/src/main/java/org/jabref/gui/OpenConsoleAction.java @@ -19,6 +19,7 @@ public class OpenConsoleAction extends SimpleCommand { private final Supplier databaseContext; private final StateManager stateManager; private final PreferencesService preferencesService; + private final DialogService dialogService; /** * Creates a command that opens the console at the path of the supplied database, @@ -26,10 +27,11 @@ public class OpenConsoleAction extends SimpleCommand { * {@link #OpenConsoleAction(StateManager, PreferencesService)} if not supplying * another database. */ - public OpenConsoleAction(Supplier databaseContext, StateManager stateManager, PreferencesService preferencesService) { + public OpenConsoleAction(Supplier databaseContext, StateManager stateManager, PreferencesService preferencesService, DialogService dialogService) { this.databaseContext = databaseContext; this.stateManager = stateManager; this.preferencesService = preferencesService; + this.dialogService = dialogService; this.executable.bind(ActionHelper.needsDatabase(stateManager)); } @@ -37,15 +39,15 @@ public OpenConsoleAction(Supplier databaseContext, StateMana /** * Using this constructor will result in executing the command on the active database. */ - public OpenConsoleAction(StateManager stateManager, PreferencesService preferencesService) { - this(() -> null, stateManager, preferencesService); + public OpenConsoleAction(StateManager stateManager, PreferencesService preferencesService, DialogService dialogService) { + this(() -> null, stateManager, preferencesService, dialogService); } @Override public void execute() { Optional.ofNullable(databaseContext.get()).or(stateManager::getActiveDatabase).flatMap(BibDatabaseContext::getDatabasePath).ifPresent(path -> { try { - JabRefDesktop.openConsole(path.toFile(), preferencesService); + JabRefDesktop.openConsole(path.toFile(), preferencesService, dialogService); } catch (IOException e) { LOGGER.info("Could not open console", e); } diff --git a/src/main/java/org/jabref/gui/SendAsEMailAction.java b/src/main/java/org/jabref/gui/SendAsEMailAction.java index 6ef1150cbe6..016b4a039ba 100644 --- a/src/main/java/org/jabref/gui/SendAsEMailAction.java +++ b/src/main/java/org/jabref/gui/SendAsEMailAction.java @@ -100,7 +100,7 @@ private String sendEmail() throws Exception { attachments.add(path.toAbsolutePath().toString()); if (openFolders) { try { - JabRefDesktop.openFolderAndSelectFile(path.toAbsolutePath(), preferencesService); + JabRefDesktop.openFolderAndSelectFile(path.toAbsolutePath(), preferencesService, dialogService); } catch (IOException e) { LOGGER.debug("Cannot open file", e); } diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index 75d22919cb8..96bc258e134 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -12,7 +12,6 @@ import org.jabref.gui.DialogService; import org.jabref.gui.Globals; -import org.jabref.gui.JabRefGUI; import org.jabref.gui.desktop.os.DefaultDesktop; import org.jabref.gui.desktop.os.Linux; import org.jabref.gui.desktop.os.NativeDesktop; @@ -184,7 +183,7 @@ private static void openExternalFilePlatformIndependent(Optional" if the app is specified, and just "open " otherwise: String[] cmd = (application != null) && !application.isEmpty() ? new String[] {"/usr/bin/open", "-a", application, filePath} : new String[] {"/usr/bin/open", filePath}; - Runtime.getRuntime().exec(cmd); + new ProcessBuilder(cmd).start(); } @Override @@ -38,8 +38,8 @@ public void openFolderAndSelectFile(Path file) throws IOException { } @Override - public void openConsole(String absolutePath) throws IOException { - Runtime.getRuntime().exec("open -a Terminal " + absolutePath, null, new File(absolutePath)); + public void openConsole(String absolutePath, DialogService dialogService) throws IOException { + new ProcessBuilder("open", "-a", "Terminal", absolutePath).start(); } @Override 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 560a404653c..a5a6acfe79a 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Windows.java +++ b/src/main/java/org/jabref/gui/desktop/os/Windows.java @@ -6,6 +6,7 @@ import java.nio.file.Path; import java.util.Optional; +import org.jabref.gui.DialogService; import org.jabref.gui.externalfiletype.ExternalFileType; import org.jabref.gui.externalfiletype.ExternalFileTypes; @@ -79,7 +80,7 @@ public void openFolderAndSelectFile(Path filePath) throws IOException { } @Override - public void openConsole(String absolutePath) throws IOException { + public void openConsole(String absolutePath, DialogService dialogService) throws IOException { ProcessBuilder process = new ProcessBuilder("cmd.exe", "/c", "start"); process.directory(new File(absolutePath)); process.start(); diff --git a/src/main/java/org/jabref/gui/duplicationFinder/DuplicateResolverDialog.java b/src/main/java/org/jabref/gui/duplicationFinder/DuplicateResolverDialog.java index a890007c220..1dad9cae973 100644 --- a/src/main/java/org/jabref/gui/duplicationFinder/DuplicateResolverDialog.java +++ b/src/main/java/org/jabref/gui/duplicationFinder/DuplicateResolverDialog.java @@ -6,6 +6,7 @@ import javafx.scene.control.ButtonType; import javafx.scene.layout.BorderPane; +import org.jabref.gui.DialogService; import org.jabref.gui.StateManager; import org.jabref.gui.duplicationFinder.DuplicateResolverDialog.DuplicateResolverResult; import org.jabref.gui.help.HelpAction; @@ -39,16 +40,18 @@ public enum DuplicateResolverResult { } private MergeEntries mergeEntries; + private final DialogService dialogService; - public DuplicateResolverDialog(BibEntry one, BibEntry two, DuplicateResolverType type, BibDatabaseContext database, StateManager stateManager) { + public DuplicateResolverDialog(BibEntry one, BibEntry two, DuplicateResolverType type, BibDatabaseContext database, StateManager stateManager, DialogService dialogService) { this.setTitle(Localization.lang("Possible duplicate entries")); this.database = database; this.stateManager = stateManager; + this.dialogService = dialogService; init(one, two, type); } private void init(BibEntry one, BibEntry two, DuplicateResolverType type) { - HelpAction helpCommand = new HelpAction(HelpFile.FIND_DUPLICATES); + HelpAction helpCommand = new HelpAction(HelpFile.FIND_DUPLICATES, dialogService); ButtonType help = new ButtonType(Localization.lang("Help"), ButtonData.HELP); ButtonType cancel = ButtonType.CANCEL; diff --git a/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java b/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java index 64af1bc9143..7ccc1b19402 100644 --- a/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java +++ b/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java @@ -142,7 +142,7 @@ private DuplicateSearchResult verifyDuplicates() { } private void askResolveStrategy(DuplicateSearchResult result, BibEntry first, BibEntry second, DuplicateResolverType resolverType) { - DuplicateResolverDialog dialog = new DuplicateResolverDialog(first, second, resolverType, frame.getCurrentLibraryTab().getBibDatabaseContext(), stateManager); + DuplicateResolverDialog dialog = new DuplicateResolverDialog(first, second, resolverType, frame.getCurrentLibraryTab().getBibDatabaseContext(), stateManager, dialogService); dialog.titleProperty().bind(Bindings.concat(dialog.getTitle()).concat(" (").concat(duplicateProgress.getValue()).concat("/").concat(duplicateTotal).concat(")")); diff --git a/src/main/java/org/jabref/gui/edit/OpenBrowserAction.java b/src/main/java/org/jabref/gui/edit/OpenBrowserAction.java index 503f0711b3c..c6eb7653ae8 100644 --- a/src/main/java/org/jabref/gui/edit/OpenBrowserAction.java +++ b/src/main/java/org/jabref/gui/edit/OpenBrowserAction.java @@ -1,18 +1,21 @@ package org.jabref.gui.edit; +import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.desktop.JabRefDesktop; public class OpenBrowserAction extends SimpleCommand { private final String urlToOpen; + private final DialogService dialogService; - public OpenBrowserAction(String urlToOpen) { + public OpenBrowserAction(String urlToOpen, DialogService dialogService) { this.urlToOpen = urlToOpen; + this.dialogService = dialogService; } @Override public void execute() { - JabRefDesktop.openBrowserShowPopup(urlToOpen); + JabRefDesktop.openBrowserShowPopup(urlToOpen, dialogService); } } diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 995461c638b..a5b513203a2 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -195,7 +195,7 @@ private void setupKeyBindings() { event.consume(); break; case HELP: - HelpAction.openHelpPage(HelpFile.ENTRY_EDITOR); + new HelpAction(HelpFile.ENTRY_EDITOR, dialogService).execute(); event.consume(); break; case CLOSE: diff --git a/src/main/java/org/jabref/gui/exporter/ExportCommand.java b/src/main/java/org/jabref/gui/exporter/ExportCommand.java index 78198252c98..f3c6812a764 100644 --- a/src/main/java/org/jabref/gui/exporter/ExportCommand.java +++ b/src/main/java/org/jabref/gui/exporter/ExportCommand.java @@ -139,7 +139,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); + JabRefDesktop.openFolderAndSelectFile(file, preferences, dialogService); } catch (IOException e) { LOGGER.error("Could not open export folder.", e); } diff --git a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java index 668d2579d2b..7de10cf7b35 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java @@ -184,7 +184,7 @@ public void importEntryWithDuplicateCheck(BibDatabaseContext bibDatabaseContext, Optional existingDuplicateInLibrary = new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(bibDatabaseContext.getDatabase(), entryToInsert, bibDatabaseContext.getMode()); if (existingDuplicateInLibrary.isPresent()) { - DuplicateResolverDialog dialog = new DuplicateResolverDialog(existingDuplicateInLibrary.get(), entryToInsert, DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, bibDatabaseContext, stateManager); + DuplicateResolverDialog dialog = new DuplicateResolverDialog(existingDuplicateInLibrary.get(), entryToInsert, DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, bibDatabaseContext, stateManager, dialogService); switch (dialogService.showCustomDialogAndWait(dialog).orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK)) { case KEEP_LEFT: bibDatabaseContext.getDatabase().removeEntry(existingDuplicateInLibrary.get()); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index db615c074aa..89a943d9e1f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -218,7 +218,7 @@ public void openFolder() { preferences.getFilePreferences()); if (resolvedPath.isPresent()) { - JabRefDesktop.openFolderAndSelectFile(resolvedPath.get(), preferences); + JabRefDesktop.openFolderAndSelectFile(resolvedPath.get(), preferences, dialogService); } else { dialogService.showErrorDialogAndWait(Localization.lang("File not found")); } diff --git a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java index 1d4d7d97804..0a1de76104c 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java @@ -446,7 +446,7 @@ public void texGroupBrowse() { } public void openHelpPage() { - HelpAction.openHelpPage(HelpFile.GROUPS); + new HelpAction(HelpFile.GROUPS, dialogService).execute(); } private List getFileDirectoriesAsPaths() { diff --git a/src/main/java/org/jabref/gui/help/HelpAction.java b/src/main/java/org/jabref/gui/help/HelpAction.java index 1cfe14937ff..0447f7331ed 100644 --- a/src/main/java/org/jabref/gui/help/HelpAction.java +++ b/src/main/java/org/jabref/gui/help/HelpAction.java @@ -1,5 +1,6 @@ package org.jabref.gui.help; +import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.logic.help.HelpFile; @@ -10,25 +11,18 @@ */ public class HelpAction extends SimpleCommand { - private HelpFile helpPage; + private final HelpFile helpPage; + private final DialogService dialogService; - public HelpAction(HelpFile helpPage) { + public HelpAction(HelpFile helpPage, DialogService dialogService) { this.helpPage = helpPage; + this.dialogService = dialogService; } - public static void openHelpPage(HelpFile helpPage) { + void openHelpPage(HelpFile helpPage) { StringBuilder sb = new StringBuilder("https://docs.jabref.org/"); sb.append(helpPage.getPageName()); - JabRefDesktop.openBrowserShowPopup(sb.toString()); - } - - public static SimpleCommand getMainHelpPageCommand() { - return new SimpleCommand() { - @Override - public void execute() { - openHelpPage(HelpFile.CONTENTS); - } - }; + JabRefDesktop.openBrowserShowPopup(sb.toString(), dialogService); } @Override diff --git a/src/main/java/org/jabref/gui/help/NewVersionDialog.java b/src/main/java/org/jabref/gui/help/NewVersionDialog.java index 2ab73b250a5..f026d0d7295 100644 --- a/src/main/java/org/jabref/gui/help/NewVersionDialog.java +++ b/src/main/java/org/jabref/gui/help/NewVersionDialog.java @@ -7,6 +7,7 @@ import javafx.scene.control.Label; import javafx.scene.layout.VBox; +import org.jabref.gui.DialogService; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.util.BaseDialog; import org.jabref.logic.l10n.Localization; @@ -14,7 +15,7 @@ public class NewVersionDialog extends BaseDialog { - public NewVersionDialog(Version currentVersion, Version latestVersion) { + public NewVersionDialog(Version currentVersion, Version latestVersion, DialogService dialogService) { this.setTitle(Localization.lang("New version available")); ButtonType btnIgnoreUpdate = new ButtonType(Localization.lang("Ignore this update"), ButtonBar.ButtonData.CANCEL_CLOSE); @@ -25,7 +26,7 @@ public NewVersionDialog(Version currentVersion, Version latestVersion) { if (button == btnIgnoreUpdate) { return false; } else if (button == btnDownloadUpdate) { - JabRefDesktop.openBrowserShowPopup(Version.JABREF_DOWNLOAD_URL); + JabRefDesktop.openBrowserShowPopup(Version.JABREF_DOWNLOAD_URL, dialogService); } return true; }); @@ -34,7 +35,7 @@ public NewVersionDialog(Version currentVersion, Version latestVersion) { Hyperlink lblMoreInformation = new Hyperlink(Localization.lang("To see what is new view the changelog.")); lblMoreInformation.setOnAction(event -> - JabRefDesktop.openBrowserShowPopup(latestVersion.getChangelogUrl()) + JabRefDesktop.openBrowserShowPopup(latestVersion.getChangelogUrl(), dialogService) ); VBox container = new VBox( diff --git a/src/main/java/org/jabref/gui/help/VersionWorker.java b/src/main/java/org/jabref/gui/help/VersionWorker.java index 66579e67a40..b4760f58c9b 100644 --- a/src/main/java/org/jabref/gui/help/VersionWorker.java +++ b/src/main/java/org/jabref/gui/help/VersionWorker.java @@ -95,7 +95,7 @@ private void showUpdateInfo(Optional newerVersion, boolean manualExecut } } else { // notify the user about a newer version - if (dialogService.showCustomDialogAndWait(new NewVersionDialog(installedVersion, newerVersion.get())).orElse(true)) { + if (dialogService.showCustomDialogAndWait(new NewVersionDialog(installedVersion, newerVersion.get(), dialogService)).orElse(true)) { internalPreferences.setIgnoredVersion(newerVersion.get()); } } diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index 1eed96197a6..b139a4573c4 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -198,7 +198,7 @@ public void resolveDuplicate(BibEntry entry) { Optional other = new DuplicateCheck(entryTypesManager).containsDuplicate(databaseContext.getDatabase(), entry, databaseContext.getMode()); if (other.isPresent()) { DuplicateResolverDialog dialog = new DuplicateResolverDialog(other.get(), - entry, DuplicateResolverDialog.DuplicateResolverType.INSPECTION, databaseContext, stateManager); + entry, DuplicateResolverDialog.DuplicateResolverType.INSPECTION, databaseContext, stateManager, dialogService); DuplicateResolverDialog.DuplicateResolverResult result = dialogService.showCustomDialogAndWait(dialog) .orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK); @@ -229,7 +229,7 @@ public void resolveDuplicate(BibEntry entry) { other = findInternalDuplicate(entry); if (other.isPresent()) { DuplicateResolverDialog diag = new DuplicateResolverDialog(entry, - other.get(), DuplicateResolverDialog.DuplicateResolverType.DUPLICATE_SEARCH, databaseContext, stateManager); + other.get(), DuplicateResolverDialog.DuplicateResolverType.DUPLICATE_SEARCH, databaseContext, stateManager, dialogService); DuplicateResolverDialog.DuplicateResolverResult answer = dialogService.showCustomDialogAndWait(diag) .orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK); 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 a37a4b1f670..df252ccc8df 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneView.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneView.java @@ -30,9 +30,11 @@ public class WebSearchPaneView extends VBox { private final WebSearchPaneViewModel viewModel; private final PreferencesService preferences; + private final DialogService dialogService; public WebSearchPaneView(PreferencesService preferences, DialogService dialogService, StateManager stateManager) { this.preferences = preferences; + this.dialogService = dialogService; this.viewModel = new WebSearchPaneViewModel(preferences, dialogService, stateManager); initialize(); } @@ -51,7 +53,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())); + Button helpButton = factory.createIconButton(StandardActions.HELP, new HelpAction(fetcher.getHelpPage().get(), dialogService)); helpButtonContainer.getChildren().setAll(helpButton); } else { helpButtonContainer.getChildren().clear(); 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 16f43d77a70..0e83f999963 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesView.java +++ b/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesView.java @@ -12,6 +12,7 @@ import javafx.scene.control.Tooltip; import javafx.util.converter.DefaultStringConverter; +import org.jabref.gui.DialogService; import org.jabref.gui.icon.IconTheme; import org.jabref.gui.libraryproperties.AbstractPropertiesTabView; import org.jabref.gui.libraryproperties.PropertiesTab; @@ -33,6 +34,7 @@ public class ConstantsPropertiesView extends AbstractPropertiesTabView> allValidProperty = EasyBind.map(stringsListProperty, ConstantsItemModel::combinedValidationValidProperty); @@ -90,7 +94,7 @@ public Optional labelAlreadyExists(String label) { } public void openHelpPage() { - HelpAction.openHelpPage(HelpFile.STRING_EDITOR); + new HelpAction(HelpFile.STRING_EDITOR, dialogService).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 a47eabc2db3..74035d4cd03 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/keypattern/KeyPatternPropertiesView.java +++ b/src/main/java/org/jabref/gui/libraryproperties/keypattern/KeyPatternPropertiesView.java @@ -48,7 +48,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), keyPatternHelp); + actionFactory.configureIconButton(StandardActions.HELP_KEY_PATTERNS, new HelpAction(HelpFile.CITATION_KEY_PATTERN, dialogService), keyPatternHelp); } @Override diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index 2f203cc4381..68f274e1a2d 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -119,7 +119,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)); + help = factory.createIconButton(StandardActions.HELP, new HelpAction(HelpFile.OPENOFFICE_LIBREOFFICE, dialogService)); help.setMaxWidth(Double.MAX_VALUE); selectDocument = new Button(); 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 325493c520f..1b1f2838949 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), keyPatternHelp); + actionFactory.configureIconButton(StandardActions.HELP_KEY_PATTERNS, new HelpAction(HelpFile.CITATION_KEY_PATTERN, dialogService), keyPatternHelp); } @Override diff --git a/src/main/java/org/jabref/gui/preferences/entryeditortabs/CustomEditorFieldsTab.java b/src/main/java/org/jabref/gui/preferences/entryeditortabs/CustomEditorFieldsTab.java index f00fbe24ee8..319f4e83f02 100644 --- a/src/main/java/org/jabref/gui/preferences/entryeditortabs/CustomEditorFieldsTab.java +++ b/src/main/java/org/jabref/gui/preferences/entryeditortabs/CustomEditorFieldsTab.java @@ -37,7 +37,7 @@ public void initialize() { fieldsTextArea.textProperty().bindBidirectional(viewModel.fieldsProperty()); ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); - actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.GENERAL_FIELDS), generalFieldsHelp); + actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.GENERAL_FIELDS, dialogService), generalFieldsHelp); } @FXML diff --git a/src/main/java/org/jabref/gui/preferences/file/FileTab.java b/src/main/java/org/jabref/gui/preferences/file/FileTab.java index 0fd6bc201e7..f91f08650a1 100644 --- a/src/main/java/org/jabref/gui/preferences/file/FileTab.java +++ b/src/main/java/org/jabref/gui/preferences/file/FileTab.java @@ -52,7 +52,7 @@ public void initialize() { autosaveLocalLibraries.selectedProperty().bindBidirectional(viewModel.autosaveLocalLibrariesProperty()); ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); - actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.AUTOSAVE), autosaveLocalLibrariesHelp); + actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.AUTOSAVE, dialogService), autosaveLocalLibrariesHelp); } @Override 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 2b421129d8b..4f561b8f2a1 100644 --- a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java +++ b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java @@ -81,7 +81,7 @@ public void initialize() { addModificationDate.selectedProperty().bindBidirectional(viewModel.addModificationDateProperty()); ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs()); - actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.OWNER), markOwnerHelp); + actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.OWNER, dialogService), markOwnerHelp); validationVisualizer.setDecoration(new IconValidationDecorator()); } 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 6c4adbbdfa9..558ac2db289 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), autolinkRegexHelp); + actionFactory.configureIconButton(StandardActions.HELP_REGEX_SEARCH, new HelpAction(HelpFile.REGEX_SEARCH, dialogService), 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 03038872af2..84ccc80d80d 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), formatterHelp); + actionFactory.configureIconButton(StandardActions.HELP_NAME_FORMATTER, new HelpAction(HelpFile.CUSTOM_EXPORTS_NAME_FORMATTER, dialogService), 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 0e7e700f074..1002f80b22e 100644 --- a/src/main/java/org/jabref/gui/preferences/network/NetworkTab.java +++ b/src/main/java/org/jabref/gui/preferences/network/NetworkTab.java @@ -110,7 +110,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), remoteHelp); + actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.REMOTE, dialogService), remoteHelp); validationVisualizer.setDecoration(new IconValidationDecorator()); Platform.runLater(() -> { 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 6014d21ae90..e3ab7004598 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), specialFieldsHelp); + actionFactory.configureIconButton(StandardActions.HELP_SPECIAL_FIELDS, new HelpAction(HelpFile.SPECIAL_FIELDS, dialogService), specialFieldsHelp); } private void setupTable() { diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java index 857a410692d..43bf6f86dac 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseLoginDialogViewModel.java @@ -184,7 +184,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 -> HelpAction.openHelpPage(HelpFile.SQL_DATABASE_MIGRATION)); + result.filter(btn -> btn.equals(openHelp)).ifPresent(btn -> new HelpAction(HelpFile.SQL_DATABASE_MIGRATION, dialogService).execute()); result.filter(btn -> btn.equals(ButtonType.OK)).ifPresent(btn -> openSharedDatabase(connectionProperties)); } loading.set(false); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 568136a3534..1cc2c330268 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1303,6 +1303,7 @@ Please\ open\ %0\ manually.=Please open %0 manually. The\ link\ has\ been\ copied\ to\ the\ clipboard.=The link has been copied to the clipboard. Open\ %0\ file=Open %0 file +Could\ not\ detect\ terminal\ automatically.\ Please\ define\ a\ custom\ terminal\ in\ the\ preferences.=Could not detect terminal automatically. Please define a custom terminal in the preferences. Cannot\ delete\ file=Cannot delete file File\ permission\ error=File permission error diff --git a/src/test/java/org/jabref/gui/util/OpenConsoleActionTest.java b/src/test/java/org/jabref/gui/util/OpenConsoleActionTest.java index e96d8b80591..5ec37c2ee0e 100644 --- a/src/test/java/org/jabref/gui/util/OpenConsoleActionTest.java +++ b/src/test/java/org/jabref/gui/util/OpenConsoleActionTest.java @@ -31,7 +31,7 @@ public void setup() { @Test public void newActionGetsCurrentDatabase() { - OpenConsoleAction action = new OpenConsoleAction(stateManager, preferences); + OpenConsoleAction action = new OpenConsoleAction(stateManager, preferences, null); action.execute(); verify(stateManager, times(1)).getActiveDatabase(); verify(current, times(1)).getDatabasePath(); @@ -39,7 +39,7 @@ public void newActionGetsCurrentDatabase() { @Test public void newActionGetsSuppliedDatabase() { - OpenConsoleAction action = new OpenConsoleAction(() -> other, stateManager, preferences); + OpenConsoleAction action = new OpenConsoleAction(() -> other, stateManager, preferences, null); action.execute(); verify(stateManager, never()).getActiveDatabase(); verify(other, times(1)).getDatabasePath(); @@ -47,7 +47,7 @@ public void newActionGetsSuppliedDatabase() { @Test public void actionDefaultsToCurrentDatabase() { - OpenConsoleAction action = new OpenConsoleAction(() -> null, stateManager, preferences); + OpenConsoleAction action = new OpenConsoleAction(() -> null, stateManager, preferences, null); action.execute(); verify(stateManager, times(1)).getActiveDatabase(); verify(current, times(1)).getDatabasePath();