From f454f77910e863de87f9a2bbacc8546dca389a67 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 30 Apr 2015 14:57:14 -0700 Subject: [PATCH] Break out procedure call argument rendering into separate function. --- blocks/procedures.js | 34 +++++++++++++++++++++++----------- blocks_compressed.js | 12 ++++++------ core/mutator.js | 3 ++- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index 450753589..3a616b8f0 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -526,13 +526,12 @@ Blockly.Blocks['procedures_callnoreturn'] = { } // Rebuild the block's arguments. this.arguments_ = [].concat(paramNames); + this.renderArgs_(); this.quarkArguments_ = paramIds; - for (var i = 0; i < this.arguments_.length; i++) { - var input = this.appendValueInput('ARG' + i) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(this.arguments_[i]); - if (this.quarkArguments_) { - // Reconnect any child blocks. + // Reconnect any child blocks. + if (this.quarkArguments_) { + for (var i = 0; i < this.arguments_.length; i++) { + var input = this.getInput('ARG' + i); var quarkName = this.quarkArguments_[i]; if (quarkName in this.quarkConnections_) { var connection = this.quarkConnections_[quarkName]; @@ -545,6 +544,23 @@ Blockly.Blocks['procedures_callnoreturn'] = { } } } + } + // Restore rendering and show the changes. + this.rendered = savedRendered; + if (this.rendered) { + this.render(); + } + }, + /** + * Render the arguments. + * @this Blockly.Block + * @private + */ + renderArgs_: function() { + for (var i = 0; i < this.arguments_.length; i++) { + var input = this.appendValueInput('ARG' + i) + .setAlign(Blockly.ALIGN_RIGHT) + .appendField(this.arguments_[i]); input.init(); } // Add 'with:' if there are parameters. @@ -561,11 +577,6 @@ Blockly.Blocks['procedures_callnoreturn'] = { } } } - // Restore rendering and show the changes. - this.rendered = savedRendered; - if (this.rendered) { - this.render(); - } }, /** * Create XML to represent the (non-editable) name and arguments. @@ -663,6 +674,7 @@ Blockly.Blocks['procedures_callreturn'] = { renameProcedure: Blockly.Blocks['procedures_callnoreturn'].renameProcedure, setProcedureParameters: Blockly.Blocks['procedures_callnoreturn'].setProcedureParameters, + renderArgs_: Blockly.Blocks['procedures_callnoreturn'].renderArgs_, mutationToDom: Blockly.Blocks['procedures_callnoreturn'].mutationToDom, domToMutation: Blockly.Blocks['procedures_callnoreturn'].domToMutation, renameVar: Blockly.Blocks['procedures_callnoreturn'].renameVar, diff --git a/blocks_compressed.js b/blocks_compressed.js index fce61ea76..b3677fb1f 100644 --- a/blocks_compressed.js +++ b/blocks_compressed.js @@ -108,13 +108,13 @@ Blockly.Blocks.procedures_mutatorcontainer={init:function(){this.setColour(Block Blockly.Blocks.procedures_mutatorarg={init:function(){this.setColour(Blockly.Blocks.procedures.HUE);this.appendDummyInput().appendField(Blockly.Msg.PROCEDURES_MUTATORARG_TITLE).appendField(new Blockly.FieldTextInput("x",this.validator_),"NAME");this.setPreviousStatement(!0);this.setNextStatement(!0);this.setTooltip(Blockly.Msg.PROCEDURES_MUTATORARG_TOOLTIP);this.contextMenu=!1},validator_:function(a){return(a=a.replace(/[\s\xa0]+/g," ").replace(/^ | $/g,""))||null}}; Blockly.Blocks.procedures_callnoreturn={init:function(){this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLNORETURN_HELPURL);this.setColour(Blockly.Blocks.procedures.HUE);this.appendDummyInput("TOPROW").appendField(Blockly.Msg.PROCEDURES_CALLNORETURN_CALL).appendField("","NAME");this.setPreviousStatement(!0);this.setNextStatement(!0);this.arguments_=[];this.quarkConnections_={};this.quarkArguments_=null},getProcedureCall:function(){return this.getFieldValue("NAME")},renameProcedure:function(a,b){Blockly.Names.equals(a, this.getProcedureCall())&&(this.setFieldValue(b,"NAME"),this.setTooltip((this.outputConnection?Blockly.Msg.PROCEDURES_CALLRETURN_TOOLTIP:Blockly.Msg.PROCEDURES_CALLNORETURN_TOOLTIP).replace("%1",b)))},setProcedureParameters:function(a,b){if(b)if(goog.array.equals(this.arguments_,a))this.quarkArguments_=b;else{this.setCollapsed(!1);if(b.length!=a.length)throw"Error: paramNames and paramIds must be the same length.";this.quarkArguments_||(this.quarkConnections_={},a.join("\n")==this.arguments_.join("\n")? -this.quarkArguments_=b:this.quarkArguments_=[]);var c=this.rendered;this.rendered=!1;for(var d=this.arguments_.length-1;0<=d;d--){var e=this.getInput("ARG"+d);if(e){var f=e.connection.targetConnection;this.quarkConnections_[this.quarkArguments_[d]]=f;this.removeInput("ARG"+d)}}this.arguments_=[].concat(a);this.quarkArguments_=b;for(d=0;d