Skip to content

Commit 1cec386

Browse files
committed
Rename mrcValidate to mrcOnModuleCurrent because it is called when the module becomes the current module.
1 parent 9565afd commit 1cec386

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

src/blocks/mrc_call_python_function.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ const CALL_PYTHON_FUNCTION = {
340340
this.mrcMechanismId = extraState.mechanismId ? extraState.mechanismId : '';
341341
this.mrcComponentClassName = extraState.componentClassName ? extraState.componentClassName : '';
342342
this.mrcMechanismClassName = extraState.mechanismClassName ? extraState.mechanismClassName : '';
343-
// Initialize mrcMapComponentNameToId here. It will be filled during mrcValidate.
343+
// Initialize mrcMapComponentNameToId here. It will be filled during checkFunction.
344344
this.mrcMapComponentNameToId = {};
345345
this.updateBlock_();
346346
},
@@ -426,7 +426,7 @@ const CALL_PYTHON_FUNCTION = {
426426
.appendField('.');
427427
}
428428
// Here we create a text field for the component name.
429-
// Later, in mrcValidate, we will replace it with a dropdown.
429+
// Later, in checkFunction, we will replace it with a dropdown.
430430
titleInput
431431
.appendField(createFieldNonEditableText(''), FIELD_COMPONENT_NAME)
432432
.appendField('.')
@@ -586,18 +586,25 @@ const CALL_PYTHON_FUNCTION = {
586586
}
587587
return components;
588588
},
589+
590+
/**
591+
* mrcOnModuleCurrent is called for each CallPythonFunctionBlock when the module becomes the current module.
592+
*/
593+
mrcOnModuleCurrent: function(this: CallPythonFunctionBlock): void {
594+
this.checkFunction();
595+
},
589596
/**
590597
* mrcOnLoad is called for each CallPythonFunctionBlock when the blocks are loaded in the blockly
591598
* workspace.
592599
*/
593600
mrcOnLoad: function(this: CallPythonFunctionBlock): void {
594-
this.mrcValidate();
601+
this.checkFunction();
595602
},
596603
/**
597-
* mrcValidate checks the block, updates it, and/or adds a warning balloon if necessary.
598-
* It is called from mrcOnLoad above and from Editor.makeCurrent.
604+
* checkFunction checks the block, updates it, and/or adds a warning balloon if necessary.
605+
* It is called from mrcOnModuleCurrent and mrcOnLoad above.
599606
*/
600-
mrcValidate: function(this: CallPythonFunctionBlock): void {
607+
checkFunction: function(this: CallPythonFunctionBlock): void {
601608
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);
602609
if (!editor) {
603610
return;

src/blocks/mrc_event_handler.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,24 @@ const EVENT_HANDLER = {
167167
});
168168
},
169169

170+
/**
171+
* mrcOnModuleCurrent is called for each EventHandlerBlock when the module becomes the current module.
172+
*/
173+
mrcOnModuleCurrent: function(this: EventHandlerBlock): void {
174+
this.checkEvent();
175+
},
170176
/**
171177
* mrcOnLoad is called for each EventHandlerBlock when the blocks are loaded in the blockly
172178
* workspace.
173179
*/
174180
mrcOnLoad: function(this: EventHandlerBlock): void {
175-
this.mrcValidate();
181+
this.checkEvent();
176182
},
177183
/**
178-
* mrcValidate checks the block, updates it, and/or adds a warning balloon if necessary.
179-
* It is called from mrcOnLoad above and from Editor.makeCurrent.
184+
* checkEvent checks the block, updates it, and/or adds a warning balloon if necessary.
185+
* It is called from mrcOnModuleCurrent and mrcOnLoad above.
180186
*/
181-
mrcValidate: function(this: EventHandlerBlock): void {
187+
checkEvent: function(this: EventHandlerBlock): void {
182188
const warnings: string[] = [];
183189

184190
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);

src/blocks/mrc_mechanism.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,24 @@ const MECHANISM = {
175175
};
176176
},
177177

178+
/**
179+
* mrcOnModuleCurrent is called for each MechanismBlock when the module becomes the current module.
180+
*/
181+
mrcOnModuleCurrent: function(this: MechanismBlock): void {
182+
this.checkMechanism();
183+
},
178184
/**
179185
* mrcOnLoad is called for each MechanismBlock when the blocks are loaded in the blockly
180186
* workspace.
181187
*/
182188
mrcOnLoad: function(this: MechanismBlock): void {
183-
this.mrcValidate();
189+
this.checkMechanism();
184190
},
185191
/**
186-
* mrcValidate checks the block, updates it, and/or adds a warning balloon if necessary.
187-
* It is called from mrcOnLoad above and from Editor.makeCurrent.
192+
* checkMechanism checks the block, updates it, and/or adds a warning balloon if necessary.
193+
* It is called from mrcOnModuleCurrent and mrcOnLoad above.
188194
*/
189-
mrcValidate: function(this: MechanismBlock): void {
195+
checkMechanism: function(this: MechanismBlock): void {
190196
const warnings: string[] = [];
191197

192198
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);

src/editor/editor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxInfo = {
4141
const MRC_ON_LOAD = 'mrcOnLoad';
4242
const MRC_ON_MOVE = 'mrcOnMove';
4343
const MRC_ON_ANCESTOR_MOVE = 'mrcOnAncestorMove';
44-
const MRC_VALIDATE = 'mrcValidate';
44+
const MRC_ON_MODULE_CURRENT = 'mrcOnModuleCurrent';
4545

4646
export class Editor {
4747
private static workspaceIdToEditor: { [workspaceId: string]: Editor } = {};
@@ -152,10 +152,10 @@ export class Editor {
152152
this.parseModules(project, modulePathToContentText);
153153
this.updateToolboxImpl();
154154

155-
// Go through all the blocks in the workspace and call their mrcValidate method.
155+
// Go through all the blocks in the workspace and call their mrcOnModuleCurrent method.
156156
this.blocklyWorkspace.getAllBlocks().forEach(block => {
157-
if (MRC_VALIDATE in block && typeof block[MRC_VALIDATE] === 'function') {
158-
block[MRC_VALIDATE]();
157+
if (MRC_ON_MODULE_CURRENT in block && typeof block[MRC_ON_MODULE_CURRENT] === 'function') {
158+
block[MRC_ON_MODULE_CURRENT]();
159159
}
160160
});
161161
}

0 commit comments

Comments
 (0)