diff options
| author | jmoenig <jens@moenig.org> | 2013-11-12 11:44:39 +0100 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2013-11-12 11:44:39 +0100 |
| commit | 651f44ebdfe3c6ff33f9135b23b971293a211dbc (patch) | |
| tree | fc809de66ca1b78aa8d3bee9566f4760b9b5ceb8 /blocks.js | |
| parent | cc7a1558f1aeb3fa0e75378f8688cdfa40c8fb8e (diff) | |
| download | snap-byow-651f44ebdfe3c6ff33f9135b23b971293a211dbc.tar.gz snap-byow-651f44ebdfe3c6ff33f9135b23b971293a211dbc.zip | |
customizable drop-down menus for input slots
Diffstat (limited to 'blocks.js')
| -rw-r--r-- | blocks.js | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2013-October-25'; +modules.blocks = '2013-November-12'; var SyntaxElementMorph; var BlockMorph; @@ -517,6 +517,12 @@ SyntaxElementMorph.prototype.revertToDefaultInput = function (arg, noValues) { if (idx !== -1) { 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.fixLayout(); + } } else if (this instanceof MultiArgMorph) { deflt = this.labelPart(this.slotSpec); } else if (this instanceof ReporterSlotMorph) { @@ -1889,7 +1895,8 @@ BlockMorph.prototype.parseSpec = function (spec) { BlockMorph.prototype.setSpec = function (spec) { var myself = this, - part; + part, + inputIdx = -1; if (!spec) {return; } this.parts().forEach(function (part) { @@ -1899,6 +1906,9 @@ BlockMorph.prototype.setSpec = function (spec) { this.add(this.placeHolder()); } this.parseSpec(spec).forEach(function (word) { + if (word[0] === '%') { + inputIdx += 1; + } part = myself.labelPart(word); myself.add(part); if (!(part instanceof CommandSlotMorph)) { @@ -1917,6 +1927,10 @@ BlockMorph.prototype.setSpec = function (spec) { if (myself.isPrototype) { myself.add(myself.placeHolder()); } + if (part instanceof InputSlotMorph && myself.definition) { + part.choices = myself.definition.dropDownMenuOfInputIdx(inputIdx); + part.fixLayout(); // needed when de-serializing + } }); this.blockSpec = spec; this.fixLayout(); @@ -2325,7 +2339,7 @@ BlockMorph.prototype.mapToHeader = function () { } else { help = 'Enter code that corresponds to the block\'s definition. ' + 'Choose your own\nformal parameter names (ignoring the ones ' + - 'shown .'; + 'shown).'; } new DialogBoxMorph( this, |
