diff options
Diffstat (limited to 'blocks.js')
| -rw-r--r-- | blocks.js | 102 |
1 files changed, 74 insertions, 28 deletions
@@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2014-July-29'; +modules.blocks = '2014-September-22'; var SyntaxElementMorph; @@ -396,10 +396,11 @@ SyntaxElementMorph.prototype.allInputs = function () { SyntaxElementMorph.prototype.allEmptySlots = function () { /* answer empty input slots of all children excluding myself, - but omit those in nested rings (lambdas) + but omit those in nested rings (lambdas) and JS-Function primitives */ var empty = []; - if (!(this instanceof RingMorph)) { + if (!(this instanceof RingMorph) && + (this.selector !== 'reportJSFunction')) { this.children.forEach(function (morph) { if (morph.isEmptySlot && morph.isEmptySlot()) { empty.push(morph); @@ -1621,7 +1622,7 @@ SyntaxElementMorph.prototype.isEmptySlot = function () { // SyntaxElementMorph speech bubble feedback: -SyntaxElementMorph.prototype.showBubble = function (value) { +SyntaxElementMorph.prototype.showBubble = function (value, exportPic) { var bubble, txt, img, @@ -1695,11 +1696,28 @@ SyntaxElementMorph.prototype.showBubble = function (value) { this.rightCenter().add(new Point(2, 0)), isClickable ); + if (exportPic) { + this.exportPictureWithResult(bubble); + } if (sf) { bubble.keepWithin(sf); } }; +SyntaxElementMorph.prototype.exportPictureWithResult = function (aBubble) { + var scr = this.fullImage(), + bub = aBubble.fullImageClassic(), + taller = Math.max(0, bub.height - scr.height), + pic = newCanvas(new Point( + scr.width + bub.width + 2, + scr.height + taller + )), + ctx = pic.getContext('2d'); + ctx.drawImage(scr, 0, pic.height - scr.height); + ctx.drawImage(bub, scr.width + 2, 0); + window.open(pic.toDataURL()); +}; + // SyntaxElementMorph code mapping /* @@ -2026,13 +2044,29 @@ BlockMorph.prototype.userMenu = function () { var menu = new MenuMorph(this), world = this.world(), myself = this, + shiftClicked = world.currentKey === 16, alternatives, + top, blck; menu.addItem( "help...", 'showHelp' ); + if (shiftClicked) { + top = this.topBlock(); + if (top instanceof ReporterBlockMorph) { + menu.addItem( + "script pic with result...", + function () { + top.ExportResultPic(); + }, + 'open a new window\n' + + 'with a picture of both\nthis script and its result', + new Color(100, 0, 0) + ); + } + } if (this.isTemplate) { if (!(this.parent instanceof SyntaxElementMorph)) { if (this.selector !== 'evaluateCustomBlock') { @@ -4115,6 +4149,23 @@ ReporterBlockMorph.prototype.mouseClickLeft = function (pos) { } }; +// ReporterBlock exporting picture with result bubble + +ReporterBlockMorph.prototype.ExportResultPic = function () { + var top = this.topBlock(), + receiver = top.receiver(), + stage; + if (top !== this) {return; } + if (receiver) { + stage = receiver.parentThatIsA(StageMorph); + if (stage) { + stage.threads.stopProcess(top); + stage.threads.startProcess(top, false, true); + } + } +}; + + // ReporterBlockMorph deleting ReporterBlockMorph.prototype.userDestroy = function () { @@ -6704,9 +6755,6 @@ InputSlotMorph.prototype.soundsMenu = function () { InputSlotMorph.prototype.getVarNamesDict = function () { var block = this.parentThatIsA(BlockMorph), rcvr, - proto, - rings, - declarations, tempVars = [], dict; @@ -6714,28 +6762,26 @@ InputSlotMorph.prototype.getVarNamesDict = function () { return {}; } rcvr = block.receiver(); - - proto = detect(block.allParents(), function (morph) { - return morph instanceof PrototypeHatBlockMorph; - }); - if (proto) { - tempVars = proto.inputs()[0].inputFragmentNames(); - } - - rings = block.allParents().filter(function (block) { - return block instanceof RingMorph; - }); - rings.forEach(function (block) { - tempVars = tempVars.concat(block.inputs()[1].evaluate()); - }); - - declarations = block.allParents().filter(function (block) { - return block.selector === 'doDeclareVariables'; - }); - declarations.forEach(function (block) { - tempVars = tempVars.concat(block.inputs()[0].evaluate()); + block.allParents().forEach(function (morph) { + if (morph instanceof PrototypeHatBlockMorph) { + tempVars.push.apply( + tempVars, + morph.inputs()[0].inputFragmentNames() + ); + } else if (morph instanceof BlockMorph) { + morph.inputs().forEach(function (inp) { + if (inp instanceof TemplateSlotMorph) { + tempVars.push(inp.contents()); + } else if (inp instanceof MultiArgMorph) { + inp.children.forEach(function (m) { + if (m instanceof TemplateSlotMorph) { + tempVars.push(m.contents()); + } + }); + } + }); + } }); - if (rcvr) { dict = rcvr.variables.allNamesDict(); tempVars.forEach(function (name) { |
