From eea73bae079ef68ca59d0bac0e655dedeafdc260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Fri, 15 Sep 2017 13:48:53 +0200 Subject: [PATCH] =?UTF-8?q?added=20=E2=80=9Cinherited=E2=80=9D=20toggle=20?= =?UTF-8?q?option=20to=20inheritable=20variable=20templates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (context menu) in the palette --- blocks.js | 31 +++++++++++++++++++++++++++---- history.txt | 6 +++++- objects.js | 10 +++++++++- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/blocks.js b/blocks.js index 5441326c..4d6e8a17 100644 --- a/blocks.js +++ b/blocks.js @@ -148,7 +148,7 @@ CustomCommandBlockMorph, SymbolMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2017-September-06'; +modules.blocks = '2017-September-15'; var SyntaxElementMorph; var BlockMorph; @@ -2399,7 +2399,30 @@ BlockMorph.prototype.userMenu = function () { } } else { // in palette if (this.selector === 'reportGetVar') { - if (!this.isInheritedVariable()) { + rcvr = this.scriptTarget(); + if (this.isInheritedVariable(false)) { // fully inherited + addOption( + 'inherited', + function () { + rcvr.toggleInheritedVariable(myself.blockSpec); + }, + true, + 'uncheck to\ndisinherit', + null + ); + } else { // not inherited + if (this.isInheritedVariable(true)) { // shadowed + addOption( + 'inherited', + function () { + rcvr.toggleInheritedVariable(myself.blockSpec); + }, + false, + null, + localize('check to inherit\nfrom') + + ' ' + rcvr.exemplar.name + ); + } addOption( 'transient', 'toggleTransientVariable', @@ -2653,13 +2676,13 @@ BlockMorph.prototype.hidePrimitive = function () { ide.refreshPalette(); }; -BlockMorph.prototype.isInheritedVariable = function () { +BlockMorph.prototype.isInheritedVariable = function (shadowedOnly) { // private - only for variable getter template inside the palette if (this.isTemplate && (this.selector === 'reportGetVar') && (this.parent instanceof FrameMorph)) { return contains( - this.scriptTarget().inheritedVariableNames(), + this.scriptTarget().inheritedVariableNames(shadowedOnly), this.blockSpec ); } diff --git a/history.txt b/history.txt index 25f62d1a..0ff8ad82 100755 --- a/history.txt +++ b/history.txt @@ -3623,13 +3623,17 @@ Fixes: ------ * GUI: disable camera (but make it accessible as hidden setting) because of retina issues +170914 +------ +* Blocks, Objects: added “inherited” option to inheritable variable templates’ context menu in the palette + v4.1 Features: * polymorphic sprite-local custom blocks * inheritance of sprite-local custom blocks * inheritance of sprite attributes (x, y, direction, size, costumes, costume #, sounds, scripts) * first-class costumes and sounds -* camera snapshots for costumes and new sprites +* [experimental, hidden] camera snapshots for costumes and new sprites * localization support when typing expressions * support for user-forced line-breaks in custom block labels * ternary Boolean slot setting: support to limit Boolean input slots to “true/false” outside of rings and in palette diff --git a/objects.js b/objects.js index b7444997..b574d5ed 100644 --- a/objects.js +++ b/objects.js @@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph, BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize, TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph*/ -modules.objects = '2017-September-08'; +modules.objects = '2017-September-15'; var SpriteMorph; var StageMorph; @@ -5606,6 +5606,14 @@ SpriteMorph.prototype.shadowVar = function (name, value) { } }; +SpriteMorph.prototype.toggleInheritedVariable = function (vName) { + if (contains(this.inheritedVariableNames(true), vName)) { // is shadowed + this.deleteVariable(vName); + } else if (contains(this.inheritedVariableNames(), vName)) { // inherited + this.shadowVar(vName, this.variables.getVar(vName)); + } +}; + SpriteMorph.prototype.inheritedVariableNames = function (shadowedOnly) { var names = [], own = this.variables.names(),