From 66e5dc21127def62d54427f3914a14de24cd66d2 Mon Sep 17 00:00:00 2001 From: Michael Aschauer Date: Sun, 21 May 2017 18:03:12 +0200 Subject: [PATCH] move cloud menu and add reset password link --- stitchcode/gui.js | 153 +++++++++++++++++++++++++++++++------- stitchcode/turtlecloud.js | 12 +++ 2 files changed, 138 insertions(+), 27 deletions(-) diff --git a/stitchcode/gui.js b/stitchcode/gui.js index 2d77b47f..7195a43e 100644 --- a/stitchcode/gui.js +++ b/stitchcode/gui.js @@ -370,29 +370,6 @@ IDE_Morph.prototype.createControlBar = function () { this.controlBar.add(settingsButton); this.controlBar.settingsButton = settingsButton; // for menu positioning - // cloudButton - button = new PushButtonMorph( - this, - 'cloudMenu', - new SymbolMorph('cloud', 11) - ); - button.corner = 12; - button.color = colors[0]; - button.highlightColor = colors[1]; - button.pressColor = colors[2]; - button.labelMinExtent = new Point(36, 18); - button.padding = 0; - button.labelShadowOffset = new Point(-1, -1); - button.labelShadowColor = colors[1]; - button.labelColor = this.buttonLabelColor; - button.contrast = this.buttonContrast; - button.drawNew(); - // button.hint = 'cloud operations'; - button.fixLayout(); - cloudButton = button; - this.controlBar.add(cloudButton); - this.controlBar.cloudButton = cloudButton; // for menu positioning - this.controlBar.fixLayout = function () { x = this.right() - padding; [stopButton, pauseButton, startButton].forEach( @@ -424,11 +401,8 @@ IDE_Morph.prototype.createControlBar = function () { settingsButton.setCenter(myself.controlBar.center()); settingsButton.setLeft(this.left()); - cloudButton.setCenter(myself.controlBar.center()); - cloudButton.setRight(settingsButton.left() - padding); - projectButton.setCenter(myself.controlBar.center()); - projectButton.setRight(cloudButton.left() - padding); + projectButton.setRight(settingsButton.left() - padding); this.refreshSlider(); this.updateLabel(); @@ -1589,6 +1563,131 @@ IDE_Morph.prototype.projectMenu = function () { }, 'Select categories of additional blocks to add to this project.' ); + + menu.addLine(); + + if (shiftClicked) { + menu.addItem( + 'Cloud url...', + 'setCloudURL', + null, + new Color(100, 0, 0) + ); + menu.addLine(); + } + if (!SnapCloud.username) { + menu.addItem( + 'Login', + function () { window.open('/login'); } + ); + menu.addItem( + 'Create an account', + function () { window.open('/signup'); } + ); + menu.addItem( + 'Reset Password...', + function () { window.open('/forgot_password'); } + ); + } else { + menu.addItem( + localize('Logout') + ' / ' + SnapCloud.username, + 'logout' + ); + } + if (shiftClicked) { + menu.addLine(); + menu.addItem( + 'export project media only...', + function () { + if (myself.projectName) { + myself.exportProjectMedia(myself.projectName); + } else { + myself.prompt('Export Project As...', function (name) { + myself.exportProjectMedia(name); + }, null, 'exportProject'); + } + }, + null, + this.hasChangedMedia ? new Color(100, 0, 0) : new Color(0, 100, 0) + ); + menu.addItem( + 'export project without media...', + function () { + if (myself.projectName) { + myself.exportProjectNoMedia(myself.projectName); + } else { + myself.prompt('Export Project As...', function (name) { + myself.exportProjectNoMedia(name); + }, null, 'exportProject'); + } + }, + null, + new Color(100, 0, 0) + ); + menu.addItem( + 'export project as cloud data...', + function () { + if (myself.projectName) { + myself.exportProjectAsCloudData(myself.projectName); + } else { + myself.prompt('Export Project As...', function (name) { + myself.exportProjectAsCloudData(name); + }, null, 'exportProject'); + } + }, + null, + new Color(100, 0, 0) + ); + menu.addLine(); + menu.addItem( + 'open shared project from cloud...', + function () { + myself.prompt('Author name…', function (usr) { + myself.prompt('Project name...', function (prj) { + var id = 'Username=' + + encodeURIComponent(usr.toLowerCase()) + + '&ProjectName=' + + encodeURIComponent(prj); + myself.showMessage( + 'Fetching project\nfrom the cloud...' + ); + SnapCloud.getPublicProject( + id, + function (projectData) { + var msg; + if (!Process.prototype.isCatchingErrors) { + window.open( + 'data:text/xml,' + projectData + ); + } + myself.nextSteps([ + function () { + msg = myself.showMessage( + 'Opening project...' + ); + }, + function () {nop(); }, // yield (Chrome) + function () { + myself.rawOpenCloudDataString( + projectData + ); + }, + function () { + msg.destroy(); + } + ]); + }, + myself.cloudError() + ); + + }, null, 'project'); + }, null, 'project'); + }, + null, + new Color(100, 0, 0) + ); + } + menu.popup(world, pos); }; diff --git a/stitchcode/turtlecloud.js b/stitchcode/turtlecloud.js index 2c287793..e2ca03bb 100644 --- a/stitchcode/turtlecloud.js +++ b/stitchcode/turtlecloud.js @@ -1024,7 +1024,19 @@ ProjectDialogMorph.prototype.rawOpenCloudProject = function (proj) { }; +// gui.js +IDE_Morph.prototype.cloudMenu = function () { + var menu, + myself = this, + world = this.world(), + pos = this.controlBar.cloudButton.bottomLeft(), + shiftClicked = (world.currentKey === 16); + + menu = new MenuMorph(this); + menu.popup(world, pos); + +}; // store.js