From 211595075ea3d7dc8e5a0645cb12b4a4dbbf2fec Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 28 Jan 2016 14:25:38 -0500 Subject: [PATCH] Make colour optional in JSON. Add ;/n in generator stub. --- blocks/procedures.js | 2 +- core/block.js | 4 +++- core/connection.js | 7 ++----- demos/blockfactory/factory.js | 10 +++++++++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index d8acb93e3..c9698f973 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -647,7 +647,7 @@ Blockly.Blocks['procedures_callnoreturn'] = { for (var i = 0; i < this.arguments_.length; i++) { if (Blockly.Names.equals(oldName, this.arguments_[i])) { this.arguments_[i] = newName; - this.getInput('ARG' + i).fieldRow[0].setText(newName); + this.getInput('ARG' + i).fieldRow[0].setValue(newName); } } }, diff --git a/core/block.js b/core/block.js index c93deff6b..ba3831c5d 100644 --- a/core/block.js +++ b/core/block.js @@ -929,7 +929,9 @@ Blockly.Block.prototype.jsonInit = function(json) { 'Must not have both an output and a previousStatement.'); // Set basic properties of block. - this.setColour(json['colour']); + if (json['colour'] !== undefined) { + this.setColour(json['colour']); + } // Interpolate the message blocks. var i = 0; diff --git a/core/connection.js b/core/connection.js index 53be62779..c111de5f3 100644 --- a/core/connection.js +++ b/core/connection.js @@ -642,11 +642,8 @@ Blockly.Connection.prototype.setCheck = function(check) { this.check_ = check; // The new value type may not be compatible with the existing connection. if (this.targetConnection && !this.checkType_(this.targetConnection)) { - if (this.isSuperior()) { - this.targetBlock().setParent(null); - } else { - this.sourceBlock_.setParent(null); - } + var child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; + child.setParent(null); // Bump away. this.sourceBlock_.bumpNeighbours_(); } diff --git a/demos/blockfactory/factory.js b/demos/blockfactory/factory.js index 6256c13dc..6182a5b26 100644 --- a/demos/blockfactory/factory.js +++ b/demos/blockfactory/factory.js @@ -576,12 +576,20 @@ function updateGenerator(block) { } } } + // Most languages end lines with a semicolon. Python does not. + var lineEnd = { + 'JavaScript': ';', + 'Python': '', + 'PHP': ';', + 'Dart': ';' + }; code.push(" // TODO: Assemble " + language + " into code variable."); - code.push(" var code = \'...\';"); if (block.outputConnection) { + code.push(" var code = '...';"); code.push(" // TODO: Change ORDER_NONE to the correct strength."); code.push(" return [code, Blockly." + language + ".ORDER_NONE];"); } else { + code.push(" var code = '..." + (lineEnd[language] || '') + "\\n';"); code.push(" return code;"); } code.push("};");