Skip to content

Commit

Permalink
Saving changes and exiting application (#4729)
Browse files Browse the repository at this point in the history
* [WIP] Saving changes and exiting application

Fixes #4728

When the user clicks _Save changes_ option, the status of
saving is not shown unlike before. I am not sure what might be
the cause of that.

* Refactored confirmClose() method

* Display dialog in case of save exception, and remove runInJavaFXThread
  • Loading branch information
CaptainDaVinci authored and tobiasdiez committed Mar 11, 2019
1 parent 7c8441d commit 3d3eecc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
18 changes: 10 additions & 8 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -1313,18 +1313,20 @@ private boolean confirmClose(BasePanel panel) {
// The user wants to save.
try {
SaveDatabaseAction saveAction = new SaveDatabaseAction(panel, Globals.prefs);
if (!saveAction.save()) {
// The action was either canceled or unsuccessful.
output(Localization.lang("Unable to save library"));
return false;
if (saveAction.save()) {
// Saved, now exit.
return true;
}
// The action was either canceled or unsuccessful.
output(Localization.lang("Unable to save library"));
} catch (Throwable ex) {
return false;
LOGGER.error("A problem occurred when trying to save the file", ex);
dialogService.showErrorDialogAndWait(Localization.lang("Save library"), Localization.lang("Could not save file."), ex);
}
} else {
return !response.isPresent() || !response.get().equals(cancel);
// Save was cancelled or an error occurred.
return false;
}
return false;
return !response.isPresent() || !response.get().equals(cancel);
}

private void closeTab(BasePanel panel) {
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.dialogs.AutosaveUIManager;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.autosaveandbackup.AutosaveManager;
import org.jabref.logic.autosaveandbackup.BackupManager;
Expand Down Expand Up @@ -138,15 +137,13 @@ private boolean doSave() {
panel.setBaseChanged(false);
panel.markExternalChangesAsResolved();

DefaultTaskExecutor.runInJavaFXThread(() -> {
// Reset title of tab
frame.setTabTitle(panel, panel.getTabTitle(),
panel.getBibDatabaseContext().getDatabaseFile().get().getAbsolutePath());
frame.output(Localization.lang("Saved library") + " '"
+ panel.getBibDatabaseContext().getDatabaseFile().get().getPath() + "'.");
frame.setWindowTitle();
frame.updateAllTabTitles();
});
// Reset title of tab
frame.setTabTitle(panel, panel.getTabTitle(),
panel.getBibDatabaseContext().getDatabaseFile().get().getAbsolutePath());
frame.output(Localization.lang("Saved library") + " '"
+ panel.getBibDatabaseContext().getDatabaseFile().get().getPath() + "'.");
frame.setWindowTitle();
frame.updateAllTabTitles();
}
return success;
} catch (SaveException ex) {
Expand Down

0 comments on commit 3d3eecc

Please sign in to comment.