From a0fe652116a43ba756c338dc18ccd0fa0df6238a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20M=C3=B6nig?= Date: Thu, 27 Jul 2017 08:33:08 +0200 Subject: [PATCH] remodelled context menu for inheritance to use check-boxes --- blocks.js | 59 ++++++++++++++++++++++++++--------------------------- history.txt | 1 + objects.js | 8 ++++++++ 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/blocks.js b/blocks.js index 01ac7f54..3cb1c6a7 100644 --- a/blocks.js +++ b/blocks.js @@ -150,7 +150,7 @@ CustomCommandBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2017-July-25'; +modules.blocks = '2017-July-27'; var SyntaxElementMorph; var BlockMorph; @@ -2498,21 +2498,16 @@ BlockMorph.prototype.userMenu = function () { }[this.selector]; if (field && rcvr && rcvr.exemplar) { menu.addLine(); - if (rcvr.inheritsAttribute(field)) { - menu.addItem( - 'disinherit', - function () { - rcvr.shadowAttribute(field); - } - ); - } else { - menu.addItem( - localize('inherit from') + ' ' + rcvr.exemplar.name, - function () { - rcvr.inheritAttribute(field); - } - ); - } + addOption( + 'inherited', + function () { + rcvr.toggleInheritanceForAttribute(field); + }, + rcvr.inheritsAttribute(field), + 'uncheck to\ndisinherit', + localize('check to inherit\nfrom') + + ' ' + rcvr.exemplar.name + ); } } @@ -6118,6 +6113,16 @@ ScriptsMorph.prototype.userMenu = function () { hasUndropQueue, stage = obj.parentThatIsA(StageMorph); + function addOption(label, toggle, test, onHint, offHint) { + var on = '\u2611 ', + off = '\u2610 '; + menu.addItem( + (test ? on : off) + localize(label), + toggle, + test ? onHint : offHint + ); + } + if (!ide) { blockEditor = this.parentThatIsA(BlockEditorMorph); if (blockEditor) { @@ -6182,22 +6187,16 @@ ScriptsMorph.prototype.userMenu = function () { if (ide) { menu.addLine(); if (obj.exemplar) { - if (obj.inheritsAttribute('scripts')) { - menu.addItem( - 'disinherit scripts', + addOption( + 'inherited', function () { - obj.shadowAttribute('scripts'); - } + obj.toggleInheritanceForAttribute('scripts'); + }, + obj.inheritsAttribute('scripts'), + 'uncheck to\ndisinherit', + localize('check to inherit\nfrom') + + ' ' + obj.exemplar.name ); - } else { - menu.addItem( - 'inherit scripts\nfrom' + ' ' + obj.exemplar.name, - function () { - obj.inheritAttribute('scripts'); - } - ); - menu.addLine(); - } } menu.addItem( 'make a block...', diff --git a/history.txt b/history.txt index 9849cf04..f316f36d 100755 --- a/history.txt +++ b/history.txt @@ -3555,6 +3555,7 @@ Fixes: 170727 ------ * Objects: don't shadow costume # when editing a costume +* Blocks, Objects: remodelled context menu for inheritance to use check-boxes Features: diff --git a/objects.js b/objects.js index ca082e9a..73edcfa1 100644 --- a/objects.js +++ b/objects.js @@ -5537,6 +5537,14 @@ SpriteMorph.prototype.refreshInheritedAttribute = function (aName) { } }; +SpriteMorph.prototype.toggleInheritanceForAttribute = function (aName) { + if (this.inheritsAttribute(aName)) { + this.shadowAttribute(aName); + } else { + this.inheritAttribute(aName); + } +}; + // SpriteMorph inheritance - variables SpriteMorph.prototype.isVariableNameInUse = function (vName, isGlobal) {