File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -281,6 +281,13 @@ const EVENT_HANDLER = {
281281 getEventBlockId : function ( this : EventHandlerBlock ) : string {
282282 return this . mrcOtherBlockId ;
283283 } ,
284+ renameMechanismName : function ( this : EventHandlerBlock , mechanismBlockId : string , newName : string ) : void {
285+ // renameMechanismName is called when a mechanism block in the same module is modified.
286+ if ( this . mrcSenderType === SenderType . MECHANISM &&
287+ mechanismBlockId === this . mrcMechanismBlockId ) {
288+ this . setFieldValue ( newName , FIELD_SENDER ) ;
289+ }
290+ } ,
284291} ;
285292
286293export function setup ( ) : void {
@@ -450,3 +457,11 @@ export function getMechanismEventHandlerBlocks(
450457 }
451458 } ) ;
452459}
460+
461+ export function renameMechanismName ( workspace : Blockly . Workspace , mechanismBlockId : string , newName : string ) : void {
462+ const eventHandlerBlocks : EventHandlerBlock [ ] = [ ] ;
463+ getMechanismEventHandlerBlocks ( workspace , mechanismBlockId , eventHandlerBlocks ) ;
464+ eventHandlerBlocks . forEach ( block => {
465+ ( block as EventHandlerBlock ) . renameMechanismName ( mechanismBlockId , newName ) ;
466+ } ) ;
467+ }
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ import * as storageModuleContent from '../storage/module_content';
3333import * as storageNames from '../storage/names' ;
3434import * as value from './utils/value' ;
3535import { renameMethodCallers } from './mrc_call_python_function'
36+ import { renameMechanismName as renameMechanismNameInEventHandlers } from './mrc_event_handler'
3637
3738export const BLOCK_NAME = 'mrc_mechanism' ;
3839export const OUTPUT_NAME = 'mrc_mechansim' ;
@@ -154,6 +155,8 @@ const MECHANISM = {
154155 if ( oldName && oldName !== name && oldName !== legalName ) {
155156 // Rename any callers.
156157 renameMethodCallers ( this . workspace , this . id , legalName ) ;
158+ // Rename any event handlers
159+ renameMechanismNameInEventHandlers ( this . workspace , this . id , legalName ) ;
157160 }
158161 return legalName ;
159162 } ,
You can’t perform that action at this time.
0 commit comments