@@ -28,6 +28,9 @@ import { getLegalName } from './utils/python';
2828import { Order } from 'blockly/python' ;
2929import { ExtendedPythonGenerator } from '../editor/extended_python_generator' ;
3030import { renameMethodCallers , mutateMethodCallers } from './mrc_call_python_function'
31+ import { findConnectedBlocksOfType } from './utils/find_connected_blocks' ;
32+ import { BLOCK_NAME as MRC_GET_PARAMETER_BLOCK_NAME } from './mrc_get_parameter' ;
33+
3134
3235export const BLOCK_NAME = 'mrc_class_method_def' ;
3336
@@ -170,11 +173,16 @@ const CLASS_METHOD_DEF = {
170173 this . mrcParameters = [ ] ;
171174
172175 let paramBlock = containerBlock . getInputTargetBlock ( 'STACK' ) ;
173- while ( paramBlock && ! paramBlock . isInsertionMarker ( ) ) {
176+ while ( paramBlock ) {
174177 const param : Parameter = {
175178 name : paramBlock . getFieldValue ( 'NAME' ) ,
176179 type : ''
177180 }
181+ if ( paramBlock . originalName ) {
182+ // This is a mutator arg block, so we can get the original name.
183+ this . mrcRenameParameter ( paramBlock . originalName , param . name ) ;
184+ paramBlock . originalName = param . name ;
185+ }
178186 this . mrcParameters . push ( param ) ;
179187 paramBlock =
180188 paramBlock . nextConnection && paramBlock . nextConnection . targetBlock ( ) ;
@@ -194,13 +202,25 @@ const CLASS_METHOD_DEF = {
194202 for ( let i = 0 ; i < this . mrcParameters . length ; i ++ ) {
195203 let itemBlock = workspace . newBlock ( MUTATOR_BLOCK_NAME ) ;
196204 ( itemBlock as Blockly . BlockSvg ) . initSvg ( ) ;
197- itemBlock . setFieldValue ( this . mrcParameters [ i ] . name , 'NAME' )
205+ itemBlock . setFieldValue ( this . mrcParameters [ i ] . name , 'NAME' ) ;
206+ ( itemBlock as MethodMutatorArgBlock ) . originalName = this . mrcParameters [ i ] . name ;
198207
199208 connection ! . connect ( itemBlock . previousConnection ! ) ;
200209 connection = itemBlock . nextConnection ;
201210 }
202211 return topBlock ;
203212 } ,
213+ mrcRenameParameter : function ( this : ClassMethodDefBlock , oldName : string , newName : string ) {
214+ let nextBlock = this . getInputTargetBlock ( 'STACK' ) ;
215+
216+ if ( nextBlock ) {
217+ findConnectedBlocksOfType ( nextBlock , MRC_GET_PARAMETER_BLOCK_NAME ) . forEach ( ( block ) => {
218+ if ( block . getFieldValue ( 'PARAMETER_NAME' ) === oldName ) {
219+ block . setFieldValue ( newName , 'PARAMETER_NAME' ) ;
220+ }
221+ } ) ;
222+ }
223+ } ,
204224 mrcUpdateParams : function ( this : ClassMethodDefBlock ) {
205225 if ( this . mrcParameters . length > 0 ) {
206226 let input = this . getInput ( 'TITLE' ) ;
@@ -305,8 +325,9 @@ const METHOD_PARAM_CONTAINER = {
305325
306326type MethodMutatorArgBlock = Blockly . Block & MethodMutatorArgMixin & Blockly . BlockSvg ;
307327interface MethodMutatorArgMixin extends MethodMutatorArgMixinType {
308-
328+ originalName : string ,
309329}
330+
310331type MethodMutatorArgMixinType = typeof METHODS_MUTATORARG ;
311332
312333function setName ( block : Blockly . BlockSvg ) {
@@ -332,6 +353,7 @@ const METHODS_MUTATORARG = {
332353 this . setPreviousStatement ( true ) ;
333354 this . setNextStatement ( true ) ;
334355 this . setStyle ( MRC_STYLE_CLASS_BLOCKS ) ;
356+ this . originalName = '' ;
335357 this . contextMenu = false ;
336358 ChangeFramework . registerCallback ( MUTATOR_BLOCK_NAME , [ Blockly . Events . BLOCK_MOVE , Blockly . Events . BLOCK_CHANGE ] , this . onBlockChanged ) ;
337359 } ,
@@ -350,6 +372,7 @@ const METHODS_MUTATORARG = {
350372 } ,
351373}
352374
375+
353376/**
354377 * Updates the procedure mutator's flyout so that the arg block is not a
355378 * duplicate of another arg.
0 commit comments