tweaked backup / restore some more

pull/95/head
jmoenig 2020-12-21 17:28:39 +01:00
rodzic 523202cbd5
commit c7cc58cab8
1 zmienionych plików z 18 dodań i 14 usunięć

Wyświetl plik

@ -2665,12 +2665,13 @@ IDE_Morph.prototype.backupAndDo = function (callback) {
// private // private
var username = this.cloud.username; var username = this.cloud.username;
try { try {
localStorage['-snap-backup-'] = this.serializer.serialize(this.stage);
delete localStorage['-snap-bakflag-'];
if (username) { if (username) {
localStorage['-snap-bakuser-'] = username; localStorage['-snap-bakuser-'] = username;
} else { } else {
delete localStorage['-snap-bakuser-']; delete localStorage['-snap-bakuser-'];
} }
localStorage['-snap-backup-'] = this.serializer.serialize(this.stage);
callback(); callback();
} catch (err) { } catch (err) {
nop(err); nop(err);
@ -2683,11 +2684,12 @@ IDE_Morph.prototype.backupAndDo = function (callback) {
}; };
IDE_Morph.prototype.clearBackup = function () { IDE_Morph.prototype.clearBackup = function () {
delete localStorage['-snap-bakflag-'];
delete localStorage['-snap-bakuser-']; delete localStorage['-snap-bakuser-'];
delete localStorage['-snap-backup-']; delete localStorage['-snap-backup-'];
}; };
IDE_Morph.prototype.availableBackup = function () { IDE_Morph.prototype.availableBackup = function (anyway) {
// return the name of the project that can be restored in double // return the name of the project that can be restored in double
// quotes for the currently logged in user. // quotes for the currently logged in user.
// Otherwise return null // Otherwise return null
@ -2695,6 +2697,12 @@ IDE_Morph.prototype.availableBackup = function () {
bak, ix; bak, ix;
if (this.hasLocalStorage()) { if (this.hasLocalStorage()) {
if (localStorage['-snap-bakuser-'] == username) { // null == undefined if (localStorage['-snap-bakuser-'] == username) { // null == undefined
if (this.hasUnsavedEdits || localStorage['-snap-bakflag-']) {
localStorage['-snap-bakflag-'] = 'expired';
if (!anyway) {
return null;
}
}
bak = localStorage['-snap-backup-']; bak = localStorage['-snap-backup-'];
if (bak) { if (bak) {
ix = bak.indexOf('"', 15); ix = bak.indexOf('"', 15);
@ -3777,8 +3785,8 @@ IDE_Morph.prototype.projectMenu = function () {
pos = this.controlBar.projectButton.bottomLeft(), pos = this.controlBar.projectButton.bottomLeft(),
graphicsName = this.currentSprite instanceof SpriteMorph ? graphicsName = this.currentSprite instanceof SpriteMorph ?
'Costumes' : 'Backgrounds', 'Costumes' : 'Backgrounds',
backup = this.availableBackup(), shiftClicked = (world.currentKey === 16),
shiftClicked = (world.currentKey === 16); backup = this.availableBackup(shiftClicked);
menu = new MenuMorph(this); menu = new MenuMorph(this);
menu.addItem('Project notes...', 'editProjectNotes'); menu.addItem('Project notes...', 'editProjectNotes');
@ -3788,16 +3796,12 @@ 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) {
if (!this.hasUnsavedEdits) { menu.addItem(
menu.addItem('Restore unsaved project', 'restore', backup); 'Restore unsaved project',
} else if (shiftClicked) { 'restore',
menu.addItem( backup,
'Restore unsaved project', shiftClicked ? new Color(100, 0, 0) : null
'restore', );
backup,
new Color(100, 0, 0)
);
}
if (shiftClicked) { if (shiftClicked) {
menu.addItem( menu.addItem(
'Clear backup', 'Clear backup',