Skip to content

Commit

Permalink
Added error dialog when setting invalid main file directory (JabRef#1921
Browse files Browse the repository at this point in the history
)
  • Loading branch information
boceckts authored and zesaro committed Oct 27, 2016
1 parent 4e13aa6 commit 37b3257
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Fixed [#1882](https://github.com/JabRef/jabref/issues/1882): Crash after saving illegal bibtexkey in entry editor
- Fixed field `location` containing only city is not exported correctly to MS-Office 2007 xml format
- Fixed field `key` field is not exported to MS-Office 2008 xml format
- Fixed download files failed silently when an invalid directory is selected

### Removed
- The non-supported feature of being able to define file directories for any extension is removed. Still, it should work for older databases using the legacy `ps` and `pdf` fields, although we strongly encourage using the `file` field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ public void download(URL url, final DownloadCallback callback) throws IOExceptio

callback.downloadComplete(fileListEntry);
} catch (IOException ex) {
LOGGER.warn("Problem downloading file", ex);
String content = String.format("%s %n %s", Localization.lang("Error message:"),
ex.getLocalizedMessage());
JOptionPane.showMessageDialog(this.frame, content,
Localization.lang("Error while writing"), JOptionPane.ERROR_MESSAGE);
}

if (!tmp.delete()) {
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/net/sf/jabref/gui/preftabs/FileTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ItemListener;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSpinner;
Expand Down Expand Up @@ -281,7 +285,14 @@ else if (origAutoSaveSetting && !autoSave.isSelected()) {

@Override
public boolean validateSettings() {
return true;
Path path = Paths.get(fileDir.getText());
boolean valid = Files.exists(path) && Files.isDirectory(path);
if (!valid) {
String content = String.format("%s -> %s %n %n %s: %n %s", Localization.lang("File"),
Localization.lang("Main file directory"), Localization.lang("Directory not found"), path);
JOptionPane.showMessageDialog(this.frame, content, Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
}
return valid;
}

@Override
Expand Down

0 comments on commit 37b3257

Please sign in to comment.