Skip to content

Commit

Permalink
Fix right clicking on any entry and selecting "Open folder" results i…
Browse files Browse the repository at this point in the history
…n the NullPointer exception (#4797)

* Add an option in preference settings to set what action to be taken by JabRef when user clicks 'open folder' on a entry.

* Fix #4763 and add added required changes in CHANGELOG.md and JabRef_en.properties

* Refactor and Reformat code.

* Fix issue #4802, where option 'open terminal here' with custom command was passing wrong argument

* Fix failure of LocalizationConsistencyTest after code changes.
  • Loading branch information
deepakkumar96 authored and Siedlerchr committed Apr 13, 2019
1 parent b798907 commit 3d770b8
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,5 @@ Johannes Manner <[email protected]>
Dominik Traczyk <[email protected]>
Cerrianne Santos <[email protected]>
Stefan Scheffel <[email protected]>
Stefan Gerzmann <[email protected]>
Stefan Gerzmann <[email protected]>
Deepak Kumar <[email protected]>
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We changed the title of Group Dialog to "Add subgroup" from "Edit group" when we select Add subgroup option.
- We enable import button only if entries are selected. [#4755](https://github.com/JabRef/jabref/issues/4755)
- We made modifications to improve contrast of UI elements. [#4583](https://github.com/JabRef/jabref/issues/4583)
- We added an option in the settings to set the default action in JabRef when right clicking on any entry in any database and selecting "Open folder". [#4763](https://github.com/JabRef/jabref/issues/4763)
- The Medline fetcher now normalizes the author names according to the BibTeX-Standard [#4345](https://github.com/JabRef/jabref/issues/4345)


Expand Down Expand Up @@ -105,13 +106,14 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where only one PDF file could be imported [#4422](https://github.com/JabRef/jabref/issues/4422)
- We fixed an issue where "Move to group" would always move the first entry in the library and not the selected [#4414](https://github.com/JabRef/jabref/issues/4414)
- We fixed an issue where an older dialog appears when downloading full texts from the quality menu. [#4489](https://github.com/JabRef/jabref/issues/4489)
- We fixed an issue where right clicking on any entry in any database and selecting "Open folder" results in the NullPointer exception. [#4763](https://github.com/JabRef/jabref/issues/4763)
- We fixed an issue where option 'open terminal here' with custom command was passing wrong argument. [#4802](https://github.com/JabRef/jabref/issues/4802)
- We fixed an issue where ranking an entry would generate an IllegalArgumentException. [#4754](https://github.com/JabRef/jabref/issues/4754)
- We fixed an issue where special characters where removed from non label key generation pattern parts [#4767](https://github.com/JabRef/jabref/issues/4767)
- We fixed an issue where the RIS import would overwite the article date with the value of the acessed date [#4816](https://github.com/JabRef/jabref/issues/4816)




### Removed
- The feature to "mark entries" was removed and merged with the groups functionality. For migration, a group is created for every value of the `__markedentry` field and the entry is added to this group.
- The number column was removed.
Expand Down
39 changes: 31 additions & 8 deletions src/main/java/org/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,33 @@ private static void openExternalFilePlatformIndependent(Optional<ExternalFileTyp
* @throws IOException
*/
public static void openFolderAndSelectFile(Path fileLink) throws IOException {
NATIVE_DESKTOP.openFolderAndSelectFile(fileLink);
if (fileLink == null) {
return;
}
boolean usingDefault = Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_FILE_BROWSER_APPLICATION);

if (usingDefault) {
NATIVE_DESKTOP.openFolderAndSelectFile(fileLink);
} else {
String absolutePath = fileLink.toAbsolutePath().getParent().toString();
String command = Globals.prefs.get(JabRefPreferences.FILE_BROWSER_COMMAND);
if (!command.isEmpty()) {
command = command.replaceAll("\\s+", " "); // normalize white spaces

// replace the placeholder if used
command = command.replace("%DIR", absolutePath);
String[] subcommands = command.split(" ");

LOGGER.info("Executing command \"" + command + "\"...");

try {
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));
}
}
}
}

/**
Expand Down Expand Up @@ -228,22 +254,19 @@ public static void openConsole(File file) throws IOException {

if (!command.isEmpty()) {
command = command.replaceAll("\\s+", " "); // normalize white spaces
String[] subcommands = command.split(" ");
command = command.replace("%DIR", absolutePath); // replace the placeholder if used

// replace the placeholder if used
String commandLoggingText = command.replace("%DIR", absolutePath);
String[] subcommands = command.split(" ");

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

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

JabRefGUI.getMainFrame().getDialogService().showErrorDialogAndWait(
Localization.lang("Open console") + " - " + Localization.lang("Error",
Localization.lang("Error occured while executing the command \"%0\".", commandLoggingText)));
JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("Error occured while executing the command \"%0\".", command));
}
}
}
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/org/jabref/gui/desktop/os/Linux.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ public void openFileWithApplication(String filePath, String application) throws

@Override
public void openFolderAndSelectFile(Path filePath) throws IOException {
String desktopSession = System.getenv("DESKTOP_SESSION").toLowerCase(Locale.ROOT);
String desktopSession = System.getenv("DESKTOP_SESSION");

String cmd;
String cmd = "xdg-open " + filePath.toAbsolutePath().getParent().toString(); //default command

if (desktopSession.contains("gnome")) {
cmd = "nautilus" + filePath.toString().replace(" ", "\\ ");
} else if (desktopSession.contains("kde")) {
cmd = "dolphin --select " + filePath.toString().replace(" ", "\\ ");
} else {
cmd = "xdg-open " + filePath.toAbsolutePath().getParent().toString();
if (desktopSession != null) {
desktopSession = desktopSession.toLowerCase(Locale.ROOT);
if (desktopSession.contains("gnome")) {
cmd = "nautilus" + filePath.toString().replace(" ", "\\ ");
} else if (desktopSession.contains("kde")) {
cmd = "dolphin --select " + filePath.toString().replace(" ", "\\ ");
}
}

Runtime.getRuntime().exec(cmd);
}

Expand All @@ -73,7 +73,6 @@ public void openConsole(String absolutePath) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

String emulatorName = reader.readLine();

if (emulatorName != null) {
emulatorName = emulatorName.substring(emulatorName.lastIndexOf(File.separator) + 1);

Expand Down
48 changes: 48 additions & 0 deletions src/main/java/org/jabref/gui/preferences/ExternalTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.model.strings.StringUtil;
import org.jabref.preferences.JabRefPreferences;

class ExternalTab implements PrefsTab {
Expand All @@ -38,6 +39,12 @@ class ExternalTab implements PrefsTab {
private final RadioButton sumatraReader;
private final TextField adobeAcrobatReaderPath;
private final TextField sumatraReaderPath;

private final RadioButton defaultFileBrowser;
private final RadioButton executeFileBrowser;
private final TextField fileBrowserCommand;
private final Button fileBrowserButton;

private final GridPane builder = new GridPane();
private final DialogService dialogService;
private final FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().build();
Expand All @@ -59,11 +66,20 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere
sumatraReaderPath = new TextField();
Button browseSumatraReader = new Button(Localization.lang("Browse"));

defaultFileBrowser = new RadioButton(Localization.lang("Use default file browser"));
executeFileBrowser = new RadioButton(Localization.lang("Execute Command"));
fileBrowserCommand = new TextField();
fileBrowserButton = new Button(Localization.lang("Browser"));

Label commandDescription = new Label(Localization.lang("Note: Use the placeholder %0 for the location of the opened library file.", "%DIR"));
defaultConsole.setOnAction(e -> updateExecuteConsoleButtonAndFieldEnabledState());
executeConsole.setOnAction(e -> updateExecuteConsoleButtonAndFieldEnabledState());
browseButton.setOnAction(e -> showConsoleChooser());

fileBrowserButton.disableProperty().bind(executeFileBrowser.selectedProperty().not());
fileBrowserCommand.disableProperty().bind(executeFileBrowser.selectedProperty().not());
fileBrowserButton.setOnAction(e -> showFileBrowserCommandChooser());

browseAdobeAcrobatReader.setOnAction(e -> showAdobeChooser());

GridPane consoleOptionPanel = new GridPane();
Expand All @@ -83,6 +99,17 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere
adobeAcrobatReader.setToggleGroup(pdfReaderGroup);
pdfOptionPanel.add(browseAdobeAcrobatReader, 3, 1);

Label fileBrowserCommandDescription = new Label(Localization.lang("Note: Use the placeholder %0 for the location of the opened library file.", "%DIR"));
GridPane fileBrowserOptionPanel = new GridPane();
final ToggleGroup fileBrowserGroup = new ToggleGroup();
defaultFileBrowser.setToggleGroup(fileBrowserGroup);
executeFileBrowser.setToggleGroup(fileBrowserGroup);
fileBrowserOptionPanel.add(defaultFileBrowser, 1, 1);
fileBrowserOptionPanel.add(executeFileBrowser, 1, 2);
fileBrowserOptionPanel.add(fileBrowserCommand, 2, 2);
fileBrowserOptionPanel.add(fileBrowserButton, 3, 2);
fileBrowserOptionPanel.add(fileBrowserCommandDescription, 2, 3);

if (OS.WINDOWS) {
browseSumatraReader.setOnAction(e -> showSumatraChooser());
pdfOptionPanel.add(sumatraReader, 1, 2);
Expand Down Expand Up @@ -133,6 +160,12 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere

builder.add(pdfOptionPanel, 1, 13);

Label openFileBrowser = new Label(Localization.lang("Open File Browser"));
openFileBrowser.getStyleClass().add("sectionHeader");
builder.add(openFileBrowser, 1, 14);

builder.add(fileBrowserOptionPanel, 1, 15);

}

@Override
Expand Down Expand Up @@ -165,6 +198,10 @@ public void setValues() {

consoleCommand.setText(Globals.prefs.get(JabRefPreferences.CONSOLE_COMMAND));

defaultFileBrowser.setSelected(Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_FILE_BROWSER_APPLICATION));
executeFileBrowser.setSelected(!Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_FILE_BROWSER_APPLICATION));
fileBrowserCommand.setText(Globals.prefs.get(JabRefPreferences.FILE_BROWSER_COMMAND));

adobeAcrobatReaderPath.setText(Globals.prefs.get(JabRefPreferences.ADOBE_ACROBAT_COMMAND));
if (OS.WINDOWS) {
sumatraReaderPath.setText(Globals.prefs.get(JabRefPreferences.SUMATRA_PDF_COMMAND));
Expand All @@ -187,6 +224,13 @@ public void storeSettings() {
prefs.putBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION, defaultConsole.isSelected());
prefs.put(JabRefPreferences.CONSOLE_COMMAND, consoleCommand.getText());
prefs.put(JabRefPreferences.ADOBE_ACROBAT_COMMAND, adobeAcrobatReaderPath.getText());

prefs.putBoolean(JabRefPreferences.USE_DEFAULT_FILE_BROWSER_APPLICATION, defaultFileBrowser.isSelected());
if (StringUtil.isNotBlank(fileBrowserCommand.getText())) {
prefs.put(JabRefPreferences.FILE_BROWSER_COMMAND, fileBrowserCommand.getText());
} else {
prefs.putBoolean(JabRefPreferences.USE_DEFAULT_FILE_BROWSER_APPLICATION, true); //default if no command specified
}
if (OS.WINDOWS) {
prefs.put(JabRefPreferences.SUMATRA_PDF_COMMAND, sumatraReaderPath.getText());
}
Expand Down Expand Up @@ -220,6 +264,10 @@ private void showSumatraChooser() {
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> sumatraReaderPath.setText(file.toAbsolutePath().toString()));
}

private void showFileBrowserCommandChooser() {
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> fileBrowserCommand.setText(file.toAbsolutePath().toString()));
}

private void readerSelected() {
if (adobeAcrobatReader.isSelected()) {
prefs.put(JabRefPreferences.USE_PDF_READER, adobeAcrobatReaderPath.getText());
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ public class JabRefPreferences implements PreferencesService {
public static final String ADOBE_ACROBAT_COMMAND = "adobeAcrobatCommand";
public static final String SUMATRA_PDF_COMMAND = "sumatraCommand";
public static final String USE_PDF_READER = "usePDFReader";
public static final String USE_DEFAULT_FILE_BROWSER_APPLICATION = "userDefaultFileBrowserApplication";
public static final String FILE_BROWSER_COMMAND = "fileBrowserCommand";

// Currently, it is not possible to specify defaults for specific entry types
// When this should be made possible, the code to inspect is org.jabref.gui.preferences.BibtexKeyPatternPrefTab.storeSettings() -> LabelPattern keypatterns = getCiteKeyPattern(); etc
public static final String DEFAULT_BIBTEX_KEY_PATTERN = "defaultBibtexKeyPattern";
Expand Down Expand Up @@ -729,16 +732,19 @@ private JabRefPreferences() {
defaults.put(USE_UNIT_FORMATTER_ON_SEARCH, Boolean.TRUE);

defaults.put(USE_DEFAULT_CONSOLE_APPLICATION, Boolean.TRUE);
defaults.put(USE_DEFAULT_FILE_BROWSER_APPLICATION, Boolean.TRUE);
if (OS.WINDOWS) {
defaults.put(CONSOLE_COMMAND, "C:\\Program Files\\ConEmu\\ConEmu64.exe /single /dir \"%DIR\"");
defaults.put(ADOBE_ACROBAT_COMMAND, "C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader");
defaults.put(SUMATRA_PDF_COMMAND, "C:\\Program Files\\SumatraPDF");
defaults.put(USE_PDF_READER, ADOBE_ACROBAT_COMMAND);
defaults.put(FILE_BROWSER_COMMAND, "explorer.exe /select, \"%DIR\"");
} else {
defaults.put(CONSOLE_COMMAND, "");
defaults.put(ADOBE_ACROBAT_COMMAND, "");
defaults.put(SUMATRA_PDF_COMMAND, "");
defaults.put(USE_PDF_READER, "");
defaults.put(FILE_BROWSER_COMMAND, "");
}

//versioncheck defaults
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,6 @@ Open\ console=Open console
Use\ default\ terminal\ emulator=Use default terminal emulator
Execute\ command=Execute command
Note\:\ Use\ the\ placeholder\ %0\ for\ the\ location\ of\ the\ opened\ library\ file.=Note: Use the placeholder %0 for the location of the opened library file.
Executing\ command\ \"%0\"...=Executing command \"%0\"...
Error\ occured\ while\ executing\ the\ command\ \"%0\".=Error occured while executing the command \"%0\".
Reformat\ ISSN=Reformat ISSN

Expand Down Expand Up @@ -2081,6 +2080,12 @@ Use\ selected\ document=Use selected document
Accept\ changes=Accept changes
Dismiss\ changes=Dismiss changes
The\ library\ has\ been\ modified\ by\ another\ program.=The library has been modified by another program.
Browser=Browser
Execute\ Command=Execute Command
Open\ File\ Browser=Open File Browser
Use\ default\ file\ browser=Use default file browser
Set\ rank\ to\ one=Set rank to one
Set\ rank\ to\ two=Set rank to two
Set\ rank\ to\ three=Set rank to three
Expand Down

0 comments on commit 3d770b8

Please sign in to comment.