Skip to content

Commit

Permalink
Fix linux file opening by using Process Builder (#8853)
Browse files Browse the repository at this point in the history
* Fix linux file opening by using Process Builder

Fixes #8831


Co-authored-by: ThiloteE <[email protected]>

* checkstyle

* add comment on nemo


Co-authored-by: ThiloteE <[email protected]>

* Refactor terminal opening as well

Co-authored-by: ThiloteE <[email protected]>

* Split ProcessBuilder arguments into Array

Co-authored-by: Siedlerchr [email protected]

* Refactor passing of dialog servie
Set directory for terminal

* fix checkstyle

* checkstyle

* remove blank line

* add missing  l10n

* add changelog

Co-authored-by: ThiloteE <[email protected]>
Co-authored-by: Benedikt Tutzer <[email protected]>
  • Loading branch information
3 people authored Jun 5, 2022
1 parent 7cb1b23 commit 35cd5d0
Show file tree
Hide file tree
Showing 38 changed files with 157 additions and 107 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand All @@ -867,28 +868,28 @@ 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(),

factory.createMenuItem(StandardActions.ERROR_CONSOLE, new ErrorConsoleAction()),

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())
);
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -1341,7 +1342,7 @@ public OpenDatabaseFolder(Supplier<BibDatabaseContext> 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);
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/jabref/gui/OpenConsoleAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,35 @@ public class OpenConsoleAction extends SimpleCommand {
private final Supplier<BibDatabaseContext> 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,
* or defaults to the active database. Use
* {@link #OpenConsoleAction(StateManager, PreferencesService)} if not supplying
* another database.
*/
public OpenConsoleAction(Supplier<BibDatabaseContext> databaseContext, StateManager stateManager, PreferencesService preferencesService) {
public OpenConsoleAction(Supplier<BibDatabaseContext> 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));
}

/**
* 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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/SendAsEMailAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -184,7 +183,7 @@ private static void openExternalFilePlatformIndependent(Optional<ExternalFileTyp
* @param fileLink the location of the file
* @throws IOException if the default file browser cannot be opened
*/
public static void openFolderAndSelectFile(Path fileLink, PreferencesService preferencesService) throws IOException {
public static void openFolderAndSelectFile(Path fileLink, PreferencesService preferencesService, DialogService dialogService) throws IOException {
if (fileLink == null) {
return;
}
Expand All @@ -208,7 +207,7 @@ public static void openFolderAndSelectFile(Path fileLink, PreferencesService pre
new ProcessBuilder(subcommands).start();
} catch (IOException exception) {
LOGGER.error("Open File Browser", exception);
JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("Error occured while executing the command \"%0\".", command));
dialogService.notify(Localization.lang("Error occured while executing the command \"%0\".", command));
}
}
}
Expand All @@ -233,7 +232,7 @@ public static void openBrowser(URI url) throws IOException {
*
* @param url the URL to open
*/
public static void openBrowserShowPopup(String url) {
public static void openBrowserShowPopup(String url, DialogService dialogService) {
try {
openBrowser(url);
} catch (IOException exception) {
Expand All @@ -242,8 +241,8 @@ public static void openBrowserShowPopup(String url) {
String couldNotOpenBrowser = Localization.lang("Could not open browser.");
String openManually = Localization.lang("Please open %0 manually.", url);
String copiedToClipboard = Localization.lang("The link has been copied to the clipboard.");
JabRefGUI.getMainFrame().getDialogService().notify(couldNotOpenBrowser);
JabRefGUI.getMainFrame().getDialogService().showErrorDialogAndWait(couldNotOpenBrowser, couldNotOpenBrowser + "\n" + openManually + "\n" + copiedToClipboard);
dialogService.notify(couldNotOpenBrowser);
dialogService.showErrorDialogAndWait(couldNotOpenBrowser, couldNotOpenBrowser + "\n" + openManually + "\n" + copiedToClipboard);
}
}

Expand All @@ -253,8 +252,9 @@ public static void openBrowserShowPopup(String url) {
* If no command is specified in {@link Globals}, the default system console will be executed.
*
* @param file Location the console should be opened at.
* @param dialogService
*/
public static void openConsole(File file, PreferencesService preferencesService) throws IOException {
public static void openConsole(File file, PreferencesService preferencesService, DialogService dialogService) throws IOException {
if (file == null) {
return;
}
Expand All @@ -263,7 +263,7 @@ public static void openConsole(File file, PreferencesService preferencesService)

boolean useCustomTerminal = preferencesService.getExternalApplicationsPreferences().useCustomTerminal();
if (!useCustomTerminal) {
NATIVE_DESKTOP.openConsole(absolutePath);
NATIVE_DESKTOP.openConsole(absolutePath, dialogService);
} else {
String command = preferencesService.getExternalApplicationsPreferences().getCustomTerminalCommand();
command = command.trim();
Expand All @@ -275,14 +275,14 @@ public static void openConsole(File file, PreferencesService preferencesService)
String[] subcommands = command.split(" ");

LOGGER.info("Executing command \"" + command + "\"...");
JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("Executing command \"%0\"...", command));
dialogService.notify(Localization.lang("Executing command \"%0\"...", command));

try {
new ProcessBuilder(subcommands).start();
} catch (IOException exception) {
LOGGER.error("Open console", exception);

JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("Error occured while executing the command \"%0\".", command));
dialogService.notify(Localization.lang("Error occured while executing the command \"%0\".", command));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/desktop/os/DefaultDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.nio.file.Path;

import org.jabref.architecture.AllowedToUseAwt;
import org.jabref.gui.DialogService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -31,7 +32,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 {
LOGGER.error("This feature is not supported by your Operating System.");
}

Expand Down
Loading

0 comments on commit 35cd5d0

Please sign in to comment.