fix #65: save at exit for desktop app

This commit is contained in:
Antelle 2016-01-13 21:18:45 +03:00
parent 37183ed978
commit aaa314f88a
3 changed files with 32 additions and 9 deletions

View File

@ -138,10 +138,10 @@ var Locale = {
appSecWarnBody2: 'Yes, your database is encrypted but no one can guarantee that the app has not been modified on the way to you.', appSecWarnBody2: 'Yes, your database is encrypted but no one can guarantee that the app has not been modified on the way to you.',
appSecWarnBtn: 'I understand the risks, continue', appSecWarnBtn: 'I understand the risks, continue',
appUnsavedWarn: 'Unsaved changes!', appUnsavedWarn: 'Unsaved changes!',
appUnsavedWarnBody: 'You have unsaved files, all changes will be lost.', appUnsavedWarnBody: 'You have unsaved files, if you close the app, changes will be lost.',
appExitBtn: 'Exit and discard unsaved changes', appExitBtn: 'Discard changes',
appExitSaveBtn: 'Save changes',
appDontExitBtn: 'Don\'t exit', appDontExitBtn: 'Don\'t exit',
appUnsavedCloseMsg: 'You have unsaved files, all changes will be lost.',
appCannotLockAutoInit: 'The app cannot be locked because auto save is disabled.', appCannotLockAutoInit: 'The app cannot be locked because auto save is disabled.',
appCannotLock: 'You have unsaved changes that will be lost. Continue?', appCannotLock: 'You have unsaved changes that will be lost. Continue?',
appSaveChangesBtn: 'Save changes', appSaveChangesBtn: 'Save changes',

View File

@ -223,13 +223,25 @@ var AppView = Backbone.View.extend({
if (Launcher && !Launcher.exitRequested) { if (Launcher && !Launcher.exitRequested) {
if (!this.exitAlertShown) { if (!this.exitAlertShown) {
var that = this; var that = this;
if (this.model.settings.get('autoSave')) {
that.saveAndExit();
return;
}
that.exitAlertShown = true; that.exitAlertShown = true;
Alerts.yesno({ Alerts.yesno({
header: Locale.appUnsavedWarn, header: Locale.appUnsavedWarn,
body: Locale.appUnsavedWarnBody, body: Locale.appUnsavedWarnBody,
buttons: [{result: 'yes', title: Locale.appExitBtn}, {result: '', title: Locale.appDontExitBtn}], buttons: [
success: function () { {result: 'save', title: Locale.appExitSaveBtn},
Launcher.exit(); {result: 'exit', title: Locale.appExitBtn, error: true},
{result: '', title: Locale.appDontExitBtn}
],
success: function (result) {
if (result === 'save') {
that.saveAndExit();
} else {
Launcher.exit();
}
}, },
cancel: function() { cancel: function() {
Launcher.cancelRestart(false); Launcher.cancelRestart(false);
@ -241,7 +253,7 @@ var AppView = Backbone.View.extend({
} }
return Launcher.preventExit(e); return Launcher.preventExit(e);
} }
return Locale.appUnsavedCloseMsg; return Locale.appUnsavedWarnBody;
} else if (Launcher && !Launcher.exitRequested && !Launcher.restartPending && } else if (Launcher && !Launcher.exitRequested && !Launcher.restartPending &&
Launcher.canMinimize() && this.model.settings.get('minimizeOnClose')) { Launcher.canMinimize() && this.model.settings.get('minimizeOnClose')) {
Launcher.minimizeApp(); Launcher.minimizeApp();
@ -293,7 +305,7 @@ var AppView = Backbone.View.extend({
} }
if (this.model.files.hasUnsavedFiles()) { if (this.model.files.hasUnsavedFiles()) {
if (this.model.settings.get('autoSave')) { if (this.model.settings.get('autoSave')) {
this.saveAndLock(autoInit); this.saveAndLock();
} else { } else {
var message = autoInit ? Locale.appCannotLockAutoInit : Locale.appCannotLock; var message = autoInit ? Locale.appCannotLockAutoInit : Locale.appCannotLock;
Alerts.alert({ Alerts.alert({
@ -323,7 +335,7 @@ var AppView = Backbone.View.extend({
} }
}, },
saveAndLock: function(/*autoInit*/) { saveAndLock: function(complete) {
var pendingCallbacks = 0, var pendingCallbacks = 0,
errorFiles = [], errorFiles = [],
that = this; that = this;
@ -350,13 +362,23 @@ var AppView = Backbone.View.extend({
body: alertBody + ' ' + errorFiles.join(', ') body: alertBody + ' ' + errorFiles.join(', ')
}); });
} }
if (complete) { complete(true); }
} else { } else {
that.closeAllFilesAndShowFirst(); that.closeAllFilesAndShowFirst();
if (complete) { complete(true); }
} }
} }
} }
}, },
saveAndExit: function() {
this.saveAndLock(function(result) {
if (result) {
Launcher.exit();
}
});
},
closeAllFilesAndShowFirst: function() { closeAllFilesAndShowFirst: function() {
var firstFile = this.model.files.find(function(file) { return !file.get('demo') && !file.get('created'); }); var firstFile = this.model.files.find(function(file) { return !file.get('demo') && !file.get('created'); });
this.model.closeAllFiles(); this.model.closeAllFiles();

View File

@ -2,6 +2,7 @@ Release notes
------------- -------------
##### v0.6.0 (not released yet) ##### v0.6.0 (not released yet)
Improvements Improvements
`+` save at exit for desktop app
`+` more reliable binaries management `+` more reliable binaries management
`+` string resources globalization `+` string resources globalization
`+` help/tips `+` help/tips