From 63d8530e88d7afea8f90356b14a4300e01a82e98 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Sat, 19 Dec 2020 18:40:05 +0100 Subject: [PATCH] new auto-backup to localstore feature --- HISTORY.md | 5 +++- snap.html | 2 +- src/gui.js | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 83 insertions(+), 8 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 22fb65bb..7a217ad4 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,8 @@ ## in development: +* **New Features:** + * automatic backup to localstore, option to restore last backed up project in the file menu * **Notable Changes:** * 25 % speed-up for reporters, WARP and TURBO * re-enabled reporter drops in "key _ pressed?" input slot @@ -10,7 +12,8 @@ * fixed keyboard formula entry for subtraction ### 2020-12-19 -* added code-documentation for the WARP/timestamp optimization +* threads: added code-documentation for the WARP/timestamp optimization +* gui: new auto-backup to localstore feature ### 2020-12-18 * threads: optimized scheduler, reduced system calls to Date.now(), 25 % speed-up for reporters, WARP and TURBO diff --git a/snap.html b/snap.html index 46d9997a..fa77f08a 100755 --- a/snap.html +++ b/snap.html @@ -11,7 +11,7 @@ - + diff --git a/src/gui.js b/src/gui.js index 163bf3ee..eededb29 100644 --- a/src/gui.js +++ b/src/gui.js @@ -78,7 +78,7 @@ Animation, BoxMorph, BlockEditorMorph, BlockDialogMorph, Note, ZERO, BLACK*/ // Global stuff //////////////////////////////////////////////////////// -modules.gui = '2020-December-15'; +modules.gui = '2020-December-19'; // Declarations @@ -2248,8 +2248,15 @@ IDE_Morph.prototype.droppedText = function (aString, name, fileType) { // check for Snap specific files, projects, libraries, sprites, scripts if (aString.indexOf(' { + location.hash = ''; + this.openProjectString(aString); + }, + 'Replace the current project with a new one?', + 'New Project' + ); + return; } if (aString.indexOf(' 15) { + return bak.slice(15, ix); + } + } + } + return null; +}; + +IDE_Morph.prototype.restore = function () { + // load the backed up project for the currently logged im user + // and backup the current one, in case they want to switch back to it + var username = this.cloud.username, + bak; + if (this.hasLocalStorage()) { + if (localStorage['-snap-bakuser-'] == username) { // null == undefined + bak = localStorage['-snap-backup-']; + this.backup(); + this.openProjectString(bak); + } + } +}; + // IDE_Morph sprite list access IDE_Morph.prototype.addNewSprite = function () { @@ -3672,6 +3740,7 @@ IDE_Morph.prototype.projectMenu = function () { pos = this.controlBar.projectButton.bottomLeft(), graphicsName = this.currentSprite instanceof SpriteMorph ? 'Costumes' : 'Backgrounds', + backup = this.availableBackup(), shiftClicked = (world.currentKey === 16); menu = new MenuMorph(this); @@ -3681,6 +3750,9 @@ IDE_Morph.prototype.projectMenu = function () { menu.addPair('Open...', 'openProjectsBrowser', '^O'); menu.addPair('Save', "save", '^S'); menu.addItem('Save As...', 'saveProjectsBrowser'); + if (backup) { + menu.addItem('Restore backup', 'restore', backup); + } menu.addLine(); menu.addItem( 'Import...', @@ -5537,10 +5609,10 @@ IDE_Morph.prototype.setPaletteWidth = function (newWidth) { }; IDE_Morph.prototype.createNewProject = function () { - this.confirm( + this.backup( + () => this.newProject(), 'Replace the current project with a new one?', - 'New Project', - () => this.newProject() + 'New Project' ); };