kopia lustrzana https://github.com/backface/turtlestitch
warn about unsaved changes
and only backup those projects with unsaved changespull/95/head
rodzic
5a3be048f5
commit
c43aee639e
87
src/gui.js
87
src/gui.js
|
@ -2259,9 +2259,7 @@ IDE_Morph.prototype.droppedText = function (aString, name, fileType) {
|
||||||
() => {
|
() => {
|
||||||
location.hash = '';
|
location.hash = '';
|
||||||
this.openProjectString(aString);
|
this.openProjectString(aString);
|
||||||
},
|
}
|
||||||
'Replace the current project with a new one?',
|
|
||||||
'New Project'
|
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2646,12 +2644,25 @@ IDE_Morph.prototype.hasLocalStorage = function () {
|
||||||
|
|
||||||
// IDE_Morph project backup
|
// IDE_Morph project backup
|
||||||
|
|
||||||
IDE_Morph.prototype.backup = function (callback, question, title) {
|
IDE_Morph.prototype.backup = function (callback) {
|
||||||
// save the current project for the currently logged in user
|
// in case of unsaved changes let the user confirm whether to
|
||||||
|
// abort the operation or go ahead with it.
|
||||||
|
// Save the current project for the currently logged in user
|
||||||
// to localstorage, then perform the given callback, e.g.
|
// to localstorage, then perform the given callback, e.g.
|
||||||
// load a new project. If the backup fails, e.g. because localstorage
|
// load a new project.
|
||||||
// isn't available or the storage quota exceeded, let the user
|
if (this.hasUnsavedEdits) {
|
||||||
// abort the action or choose to go ahead with it
|
this.confirm(
|
||||||
|
'Replace the current project with a new one?',
|
||||||
|
'Unsaved Changes!',
|
||||||
|
() => this.backupAndDo(callback)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
IDE_Morph.prototype.backupAndDo = function (callback) {
|
||||||
|
// private
|
||||||
var username = this.cloud.username;
|
var username = this.cloud.username;
|
||||||
try {
|
try {
|
||||||
if (username) {
|
if (username) {
|
||||||
|
@ -2660,17 +2671,15 @@ IDE_Morph.prototype.backup = function (callback, question, title) {
|
||||||
delete localStorage['-snap-bakuser-'];
|
delete localStorage['-snap-bakuser-'];
|
||||||
}
|
}
|
||||||
localStorage['-snap-backup-'] = this.serializer.serialize(this.stage);
|
localStorage['-snap-backup-'] = this.serializer.serialize(this.stage);
|
||||||
if (callback) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
nop(err);
|
nop(err);
|
||||||
if (question) {
|
|
||||||
this.confirm(question, title, callback);
|
|
||||||
} else if (callback) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
|
||||||
|
IDE_Morph.prototype.clearBackup = function () {
|
||||||
|
delete localStorage['-snap-bakuser-'];
|
||||||
|
delete localStorage['-snap-backup-'];
|
||||||
};
|
};
|
||||||
|
|
||||||
IDE_Morph.prototype.availableBackup = function () {
|
IDE_Morph.prototype.availableBackup = function () {
|
||||||
|
@ -2701,8 +2710,9 @@ IDE_Morph.prototype.restore = function () {
|
||||||
if (this.hasLocalStorage()) {
|
if (this.hasLocalStorage()) {
|
||||||
if (localStorage['-snap-bakuser-'] == username) { // null == undefined
|
if (localStorage['-snap-bakuser-'] == username) { // null == undefined
|
||||||
bak = localStorage['-snap-backup-'];
|
bak = localStorage['-snap-backup-'];
|
||||||
this.backup();
|
if (bak) {
|
||||||
this.openProjectString(bak);
|
this.backup(() => this.openProjectString(bak));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -3768,7 +3778,24 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
menu.addPair('Save', "save", '^S');
|
menu.addPair('Save', "save", '^S');
|
||||||
menu.addItem('Save As...', 'saveProjectsBrowser');
|
menu.addItem('Save As...', 'saveProjectsBrowser');
|
||||||
if (backup) {
|
if (backup) {
|
||||||
menu.addItem('Restore backup', 'restore', backup);
|
if (!this.hasUnsavedEdits) {
|
||||||
|
menu.addItem('Restore unsaved changes', 'restore', backup);
|
||||||
|
} else if (shiftClicked) {
|
||||||
|
menu.addItem(
|
||||||
|
'Restore unsaved changes',
|
||||||
|
'restore',
|
||||||
|
backup,
|
||||||
|
new Color(100, 0, 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (shiftClicked) {
|
||||||
|
menu.addItem(
|
||||||
|
'Clear backup',
|
||||||
|
'clearBackup',
|
||||||
|
backup,
|
||||||
|
new Color(100, 0, 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
menu.addLine();
|
menu.addLine();
|
||||||
menu.addItem(
|
menu.addItem(
|
||||||
|
@ -5630,11 +5657,7 @@ IDE_Morph.prototype.setPaletteWidth = function (newWidth) {
|
||||||
};
|
};
|
||||||
|
|
||||||
IDE_Morph.prototype.createNewProject = function () {
|
IDE_Morph.prototype.createNewProject = function () {
|
||||||
this.backup(
|
this.backup(() => this.newProject());
|
||||||
() => this.newProject(),
|
|
||||||
'Replace the current project with a new one?',
|
|
||||||
'New Project'
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
IDE_Morph.prototype.openProjectsBrowser = function () {
|
IDE_Morph.prototype.openProjectsBrowser = function () {
|
||||||
|
@ -7320,20 +7343,12 @@ ProjectDialogMorph.prototype.openProject = function () {
|
||||||
} else if (this.source === 'examples') {
|
} else if (this.source === 'examples') {
|
||||||
// Note "file" is a property of the parseResourceFile function.
|
// Note "file" is a property of the parseResourceFile function.
|
||||||
src = this.ide.getURL(this.ide.resourceURL('Examples', proj.fileName));
|
src = this.ide.getURL(this.ide.resourceURL('Examples', proj.fileName));
|
||||||
this.ide.backup(
|
this.ide.backup(() => this.ide.openProjectString(src));
|
||||||
() => this.ide.openProjectString(src),
|
|
||||||
'Replace the current project with a new one?',
|
|
||||||
'New Project'
|
|
||||||
);
|
|
||||||
this.destroy();
|
this.destroy();
|
||||||
|
|
||||||
} else { // 'local'
|
} else { // 'local'
|
||||||
this.ide.source = null;
|
this.ide.source = null;
|
||||||
this.ide.backup(
|
this.ide.backup(() => this.ide.openProject(proj.name));
|
||||||
() => this.ide.openProject(proj.name),
|
|
||||||
'Replace the current project with a new one?',
|
|
||||||
'New Project'
|
|
||||||
);
|
|
||||||
this.destroy();
|
this.destroy();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -7345,9 +7360,7 @@ ProjectDialogMorph.prototype.openCloudProject = function (project, delta) {
|
||||||
() => this.ide.showMessage('Fetching project\nfrom the cloud...'),
|
() => this.ide.showMessage('Fetching project\nfrom the cloud...'),
|
||||||
() => this.rawOpenCloudProject(project, delta)
|
() => this.rawOpenCloudProject(project, delta)
|
||||||
]);
|
]);
|
||||||
},
|
}
|
||||||
'Replace the current project with a new one?',
|
|
||||||
'New Project'
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue