Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when path is no valid directory #2527

Merged
merged 1 commit into from
Feb 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/java/net/sf/jabref/gui/FileDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.awt.Component;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
Expand Down Expand Up @@ -59,7 +60,10 @@ public FileDialog(Component parent, String dir) {

public FileDialog(Component parent, Path dir) {
Objects.requireNonNull(dir, "Directory must not be null");

//Dir must be a folder, not a file
if (!Files.isDirectory(dir)) {
dir = dir.getParent();
}
fileChooser = new FileChooser();
configurationBuilder = new FileDialogConfiguration.Builder();
configurationBuilder = configurationBuilder.withInitialDirectory(dir);
Expand Down Expand Up @@ -137,6 +141,7 @@ public Optional<Path> showDialogAndGetSelectedDirectory() {

return runInJavaFXThread(() -> Optional.ofNullable(directoryChooser.showDialog(null)).map(File::toPath));
}

/**
* Shows an {@link JFileChooser#OPEN_DIALOG} and allows to select multiple files
* @return List containing the paths of all files or an empty list if dialog is canceled
Expand Down