Skip to content

Commit

Permalink
Fix #3774 Remember correct path of last export
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Feb 27, 2018
1 parent d19b6d7 commit a51fff8
Showing 1 changed file with 59 additions and 59 deletions.
118 changes: 59 additions & 59 deletions src/main/java/org/jabref/gui/exporter/ExportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,73 +78,73 @@ private void export(Path file, FileChooser.ExtensionFilter selectedExtensionFilt
String selectedExtension = selectedExtensionFilter.getExtensions().get(0).replace("*", "");
if (!file.endsWith(selectedExtension)) {
FileUtil.addExtension(file, selectedExtension);
}
}

final Exporter format = FileFilterConverter.getExporter(selectedExtensionFilter, exporters).orElseThrow(() -> new IllegalStateException("User didn't selected a file type for the extension"));
List<BibEntry> entries;
if (selectedOnly) {
// Selected entries
entries = frame.getCurrentBasePanel().getSelectedEntries();
} else {
// All entries
entries = frame.getCurrentBasePanel().getDatabase().getEntries();
}

// Set the global variable for this database's file directory before exporting,
// so formatters can resolve linked files correctly.
// (This is an ugly hack!)
Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext()
.getFileDirectories(Globals.prefs.getFileDirectoryPreferences());

// Make sure we remember which filter was used, to set
// the default for next time:
List<BibEntry> entries;
if (selectedOnly) {
// Selected entries
entries = frame.getCurrentBasePanel().getSelectedEntries();
} else {
// All entries
entries = frame.getCurrentBasePanel().getDatabase().getEntries();
}

// Set the global variable for this database's file directory before exporting,
// so formatters can resolve linked files correctly.
// (This is an ugly hack!)
Globals.prefs.fileDirForDatabase = frame.getCurrentBasePanel().getBibDatabaseContext()
.getFileDirectories(Globals.prefs.getFileDirectoryPreferences());

// Make sure we remember which filter was used, to set
// the default for next time:
Globals.prefs.put(JabRefPreferences.LAST_USED_EXPORT, format.getDescription());
Globals.prefs.put(JabRefPreferences.EXPORT_WORKING_DIRECTORY, file.getParent().getFileName().toString());

final List<BibEntry> finEntries = entries;
AbstractWorker exportWorker = new AbstractWorker() {

String errorMessage;

@Override
public void run() {
try {
format.export(frame.getCurrentBasePanel().getBibDatabaseContext(),
file,
frame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getEncoding()
.orElse(Globals.prefs.getDefaultEncoding()),
finEntries);
} catch (Exception ex) {
LOGGER.warn("Problem exporting", ex);
if (ex.getMessage() == null) {
errorMessage = ex.toString();
} else {
errorMessage = ex.getMessage();
}
Globals.prefs.put(JabRefPreferences.EXPORT_WORKING_DIRECTORY, file.getParent().toString());

final List<BibEntry> finEntries = entries;
AbstractWorker exportWorker = new AbstractWorker() {

String errorMessage;

@Override
public void run() {
try {
format.export(frame.getCurrentBasePanel().getBibDatabaseContext(),
file,
frame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getEncoding()
.orElse(Globals.prefs.getDefaultEncoding()),
finEntries);
} catch (Exception ex) {
LOGGER.warn("Problem exporting", ex);
if (ex.getMessage() == null) {
errorMessage = ex.toString();
} else {
errorMessage = ex.getMessage();
}
}
}

@Override
public void update() {
// No error message. Report success:
if (errorMessage == null) {
frame.output(Localization.lang("%0 export successful", format.getDisplayName()));
}
// ... or show an error dialog:
else {
frame.output(Localization.lang("Could not save file.") + " - " + errorMessage);
// Need to warn the user that saving failed!
JOptionPane.showMessageDialog(frame,
Localization.lang("Could not save file.") + "\n" + errorMessage,
Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE);
}
@Override
public void update() {
// No error message. Report success:
if (errorMessage == null) {
frame.output(Localization.lang("%0 export successful", format.getDisplayName()));
}
};
// ... or show an error dialog:
else {
frame.output(Localization.lang("Could not save file.") + " - " + errorMessage);
// Need to warn the user that saving failed!
JOptionPane.showMessageDialog(frame,
Localization.lang("Could not save file.") + "\n" + errorMessage,
Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE);
}
}
};

// Run the export action in a background thread:
exportWorker.getWorker().run();
// Run the update method:
exportWorker.update();
// Run the export action in a background thread:
exportWorker.getWorker().run();
// Run the update method:
exportWorker.update();
}
}

Expand Down

0 comments on commit a51fff8

Please sign in to comment.