diff options
| author | jmoenig <jens@moenig.org> | 2013-11-15 11:18:45 +0100 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2013-11-15 11:18:45 +0100 |
| commit | 81654e72997c1577181d6729660c110ed1b9e20f (patch) | |
| tree | 7a03fd5c340f72ca557cd3b6c93a87c0d19435cb /blocks.js | |
| parent | cc0bf15c1a9172c494fd527ad4c15a31014fee75 (diff) | |
| download | snap-yow-81654e72997c1577181d6729660c110ed1b9e20f.tar.gz snap-yow-81654e72997c1577181d6729660c110ed1b9e20f.zip | |
„read-only“ option for editable custom block input slots
also custom block input slots reverting to default now show their
default value (useful in combination with the new "read-only" option
Diffstat (limited to 'blocks.js')
| -rw-r--r-- | blocks.js | 34 |
1 files changed, 28 insertions, 6 deletions
@@ -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 () { |
