Skip to content

Commit 092a065

Browse files
committed
Update event handler blocks if the user renames a mechanism.
1 parent 6ebb3b5 commit 092a065

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/blocks/mrc_event_handler.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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

286293
export 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+
}

src/blocks/mrc_mechanism.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import * as storageModuleContent from '../storage/module_content';
3333
import * as storageNames from '../storage/names';
3434
import * as value from './utils/value';
3535
import { renameMethodCallers } from './mrc_call_python_function'
36+
import { renameMechanismName as renameMechanismNameInEventHandlers } from './mrc_event_handler'
3637

3738
export const BLOCK_NAME = 'mrc_mechanism';
3839
export 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
},

0 commit comments

Comments
 (0)