From b36a88f42346e09db3cf4dfd4b682f808ca8b787 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 10 Feb 2015 14:42:54 -0800 Subject: [PATCH] Fix bad rendering of collapsed function calls. --- blocks/procedures.js | 39 +++++++++++++++++++++++++-------------- blocks_compressed.js | 18 +++++++++--------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index 0118ee0ae0c..a11839aa7c7 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -273,7 +273,7 @@ Blockly.Blocks['procedures_defnoreturn'] = { if (change) { this.updateParams_(); // Update the mutator's variables if the mutator is open. - if (this.mutator.isVisible_()) { + if (this.mutator.isVisible()) { var blocks = this.mutator.workspace_.getAllBlocks(); for (var i = 0, block; block = blocks[i]; i++) { if (block.type == 'procedures_mutatorarg' && @@ -428,10 +428,9 @@ Blockly.Blocks['procedures_callnoreturn'] = { init: function() { this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLNORETURN_HELPURL); this.setColour(Blockly.Blocks.procedures.HUE); - this.appendDummyInput() + this.appendDummyInput('TOPROW') .appendField(Blockly.Msg.PROCEDURES_CALLNORETURN_CALL) - .appendField('', 'NAME') - .appendField(Blockly.Msg.PROCEDURES_CALL_BEFORE_PARAMS, 'WITH'); + .appendField('', 'NAME'); this.setPreviousStatement(true); this.setNextStatement(true); // Tooltip is set in domToMutation. @@ -488,6 +487,12 @@ Blockly.Blocks['procedures_callnoreturn'] = { this.quarkArguments_ = null; return; } + if (goog.array.equals(this.arguments_, paramNames)) { + // No change. + this.quarkArguments_ = paramIds; + return; + } + this.setCollapsed(false); if (paramIds.length != paramNames.length) { throw 'Error: paramNames and paramIds must be the same length.'; } @@ -536,14 +541,21 @@ Blockly.Blocks['procedures_callnoreturn'] = { } } } - if (savedRendered) { - input.init(); - } + input.init(); } // Add 'with:' if there are parameters. - var withField = this.getField_('WITH'); - if (withField) { - withField.setVisible(!!this.arguments_.length); + var input = this.getInput('TOPROW'); + if (input) { + if (this.arguments_.length) { + if (!this.getField_('WITH')) { + input.appendField(Blockly.Msg.PROCEDURES_CALL_BEFORE_PARAMS, 'WITH'); + input.init(); + } + } else { + if (this.getField_('WITH')) { + input.removeField('WITH'); + } + } } // Restore rendering and show the changes. this.rendered = savedRendered; @@ -578,7 +590,7 @@ Blockly.Blocks['procedures_callnoreturn'] = { (this.outputConnection ? Blockly.Msg.PROCEDURES_CALLRETURN_TOOLTIP : Blockly.Msg.PROCEDURES_CALLNORETURN_TOOLTIP).replace('%1', name)); var def = Blockly.Procedures.getDefinition(name, this.workspace); - if (def && def.mutator.isVisible()) { + if (def && def.mutator && def.mutator.isVisible()) { // Initialize caller with the mutator's IDs. this.setProcedureParameters(def.arguments_, def.paramIds_); } else { @@ -634,10 +646,9 @@ Blockly.Blocks['procedures_callreturn'] = { init: function() { this.setHelpUrl(Blockly.Msg.PROCEDURES_CALLRETURN_HELPURL); this.setColour(Blockly.Blocks.procedures.HUE); - this.appendDummyInput() + this.appendDummyInput('TOPROW') .appendField(Blockly.Msg.PROCEDURES_CALLRETURN_CALL) - .appendField('', 'NAME') - .appendField(Blockly.Msg.PROCEDURES_CALL_BEFORE_PARAMS, 'WITH'); + .appendField('', 'NAME'); this.setOutput(true); // Tooltip is set in domToMutation. this.arguments_ = []; diff --git a/blocks_compressed.js b/blocks_compressed.js index cf84608534e..4306cae51f5 100644 --- a/blocks_compressed.js +++ b/blocks_compressed.js @@ -97,7 +97,7 @@ this.arguments_=[];this.setStatements_(!0);this.statementConnection_=null},setSt Blockly.Block.obtain(a,"procedures_mutatorarg");e.initSvg();e.setFieldValue(this.arguments_[d],"NAME");e.oldLocation=d;c.connect(e.previousConnection);c=e.nextConnection}Blockly.Procedures.mutateCallers(this.getFieldValue("NAME"),this.workspace,this.arguments_,null);return b},compose:function(a){this.arguments_=[];this.paramIds_=[];for(var b=a.getInputTargetBlock("STACK");b;)this.arguments_.push(b.getFieldValue("NAME")),this.paramIds_.push(b.id),b=b.nextConnection&&b.nextConnection.targetBlock(); this.updateParams_();Blockly.Procedures.mutateCallers(this.getFieldValue("NAME"),this.workspace,this.arguments_,this.paramIds_);a=a.getFieldValue("STATEMENTS");if(null!==a&&(a="TRUE"==a,this.hasStatements_!=a))if(a)this.setStatements_(!0),a=this.getInput("STACK").connection,a.targetConnection||!this.statementConnection_||this.statementConnection_.targetConnection||this.statementConnection_.sourceBlock_.workspace!=this.workspace?this.statementConnection_=null:a.connect(this.statementConnection_);else{a= this.getInput("STACK").connection;if(this.statementConnection_=a.targetConnection)a=a.targetBlock(),a.setParent(null),a.bumpNeighbours_();this.setStatements_(!1)}},dispose:function(){var a=this.getFieldValue("NAME");Blockly.Procedures.disposeCallers(a,this.workspace);this.constructor.prototype.dispose.apply(this,arguments)},getProcedureDef:function(){return[this.getFieldValue("NAME"),this.arguments_,!1]},getVars:function(){return this.arguments_},renameVar:function(a,b){for(var c=!1,d=0;d