/** * Modify this block to have the correct number of arguments. * @private * @this Blockly.Block */ private void updateShape_() { int i; for (i = 0; i < this.arguments_.Length; i++) { var field = this.getField("ARGNAME" + i); if (field != null) { // Ensure argument name is up to date. // The argument name field is deterministic based on the mutation, // no need to fire a change event. Events.disable(); try { field.setValue(this.arguments_[i]); } finally { Events.enable(); } } else { // Add new input. field = new FieldLabel(this.arguments_[i]); var input = this.appendValueInput("ARG" + i) .setAlign(Core.ALIGN_RIGHT) .appendField(field, "ARGNAME" + i); input.init(); } } // Remove deleted inputs. while (this.getInput("ARG" + i) != null) { this.removeInput("ARG" + i); i++; } // Add "with:" if there are parameters, remove otherwise. var topRow = this.getInput("TOPROW"); if (topRow != null) { if (this.arguments_.Length != 0) { if (this.getField("WITH") == null) { topRow.appendField(Msg.PROCEDURES_CALL_BEFORE_PARAMS, "WITH"); topRow.init(); } } else { if (this.getField("WITH") != null) { topRow.removeField("WITH"); } } } }
/// <summary> /// Add an item to the end of the input's field row. /// </summary> /// <param name="field">Something to add as a field.</param> /// <param name="opt_name">Language-neutral identifier which may used to find /// this field again.Should be unique to the host block.</param> /// <returns>The input being append to (to allow chaining).</returns> public Input appendField(Union <string, Field> field_, string opt_name = null) { // Empty string, Null or undefined generates no field, unless field is named. if (field_ == null && opt_name == null) { return(this); } Field field; // Generate a FieldLabel when given a plain text field. if (field_.Is <string>()) { field = new FieldLabel(field_.As <string>()); } else { field = field_.As <Field>(); } field.setSourceBlock(this.sourceBlock_); if (this.sourceBlock_.rendered) { field.init(); } field.name = opt_name; if (field.prefixField != null) { // Add any prefix. this.appendField(field.prefixField); } // Add the field to the field row. this.fieldRow.Push(field); if (field.suffixField != null) { // Add any suffix. this.appendField(field.suffixField); } if (this.sourceBlock_.rendered) { this.sourceBlock_.render(); // Adding a field will cause the block to change shape. this.sourceBlock_.bumpNeighbours_(); } return(this); }