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.',
appSecWarnBtn: 'I understand the risks, continue',
appUnsavedWarn: 'Unsaved changes!',
appUnsavedWarnBody: 'You have unsaved files, all changes will be lost.',
appExitBtn: 'Exit and discard unsaved changes',
appUnsavedWarnBody: 'You have unsaved files, if you close the app, changes will be lost.',
appExitBtn: 'Discard changes',
appExitSaveBtn: 'Save changes',
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.',
appCannotLock: 'You have unsaved changes that will be lost. Continue?',
appSaveChangesBtn: 'Save changes',

View File

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

View File

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