From 81654e72997c1577181d6729660c110ed1b9e20f Mon Sep 17 00:00:00 2001 From: jmoenig Date: Fri, 15 Nov 2013 11:18:45 +0100 Subject: „read-only“ option for editable custom block input slots MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit also custom block input slots reverting to default now show their default value (useful in combination with the new "read-only" option --- blocks.js | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'blocks.js') diff --git a/blocks.js b/blocks.js index b2b38c4..8f675c4 100644 --- a/blocks.js +++ b/blocks.js @@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2013-November-12'; +modules.blocks = '2013-November-15'; var SyntaxElementMorph; var BlockMorph; @@ -518,10 +518,13 @@ SyntaxElementMorph.prototype.revertToDefaultInput = function (arg, noValues) { if (this instanceof BlockMorph) { deflt = this.labelPart(this.parseSpec(this.blockSpec)[idx]); if (deflt instanceof InputSlotMorph && this.definition) { - deflt.choices = this.definition.dropDownMenuOfInputIdx( - this.inputs().indexOf(arg) + deflt.setChoices.apply( + deflt, + this.definition.inputOptionsOfIdx(inp) + ); + deflt.setContents( + this.definition.defaultValueOfInputIdx(inp) ); - deflt.fixLayout(); } } else if (this instanceof MultiArgMorph) { deflt = this.labelPart(this.slotSpec); @@ -1912,8 +1915,10 @@ BlockMorph.prototype.setSpec = function (spec) { myself.add(myself.placeHolder()); } if (part instanceof InputSlotMorph && myself.definition) { - part.choices = myself.definition.dropDownMenuOfInputIdx(inputIdx); - part.fixLayout(); // needed when de-serializing + part.setChoices.apply( + part, + myself.definition.inputOptionsOfIdx(inputIdx) + ); } }); this.blockSpec = spec; @@ -6593,6 +6598,23 @@ InputSlotMorph.prototype.getVarNamesDict = function () { return {}; }; +InputSlotMorph.prototype.setChoices = function (dict, readonly) { + // externally specify choices and read-only status, + // used for custom blocks + var cnts = this.contents(); + this.choices = dict; + this.isReadOnly = readonly || false; + if (this.parent instanceof BlockMorph) { + this.parent.fixLabelColor(); + if (!readonly) { + cnts.shadowOffset = new Point(); + cnts.shadowColor = null; + cnts.setColor(new Color(0, 0, 0)); + } + } + this.fixLayout(); +}; + // InputSlotMorph layout: InputSlotMorph.prototype.fixLayout = function () { -- cgit v1.3.1