Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/blocks/mrc_call_python_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ const CALL_PYTHON_FUNCTION = {
this.mrcMechanismId = extraState.mechanismId ? extraState.mechanismId : '';
this.mrcComponentClassName = extraState.componentClassName ? extraState.componentClassName : '';
this.mrcMechanismClassName = extraState.mechanismClassName ? extraState.mechanismClassName : '';
// Initialize mrcComponentNames and mrcMapComponentNameToId here. They will be filled during mrcOnLoad.
// Initialize mrcComponentNames and mrcMapComponentNameToId here. They will be filled during mrcValidate.
this.mrcComponentNames = [];
this.mrcMapComponentNameToId = {};
this.updateBlock_();
Expand Down Expand Up @@ -405,7 +405,7 @@ const CALL_PYTHON_FUNCTION = {
.appendField('.');
}
// Here we create a text field for the component name.
// Later, in mrcOnLoad, we will replace it with a dropdown.
// Later, in mrcValidate, we will replace it with a dropdown.
titleInput
.appendField(createFieldNonEditableText(''), FIELD_COMPONENT_NAME)
.appendField('.')
Expand Down Expand Up @@ -565,8 +565,18 @@ const CALL_PYTHON_FUNCTION = {
}
return components;
},
/**
* mrcOnLoad is called for each CallPythonFunctionBlock when the blocks are loaded in the blockly
* workspace.
*/
mrcOnLoad: function(this: CallPythonFunctionBlock): void {
// mrcOnLoad is called for each CallPythonFunctionBlock when the blocks are loaded in the blockly workspace.
this.mrcValidate();
},
/**
* mrcValidate checks the block, updates it, and/or adds a warning balloon if necessary.
* It is called from mrcOnLoad above and from Editor.makeCurrent.
*/
mrcValidate: function(this: CallPythonFunctionBlock): void {
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);
if (!editor) {
return;
Expand Down
7 changes: 7 additions & 0 deletions src/blocks/mrc_event_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ const EVENT_HANDLER = {
* workspace.
*/
mrcOnLoad: function(this: EventHandlerBlock): void {
this.mrcValidate();
},
/**
* mrcValidate checks the block, updates it, and/or adds a warning balloon if necessary.
* It is called from mrcOnLoad above and from Editor.makeCurrent.
*/
mrcValidate: function(this: EventHandlerBlock): void {
const warnings: string[] = [];

const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);
Expand Down
13 changes: 12 additions & 1 deletion src/blocks/mrc_mechanism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,19 @@ const MECHANISM = {
className: mechanismType,
};
},

/**
* mrcOnLoad is called for each MechanismBlock when the blocks are loaded in the blockly
* workspace.
*/
mrcOnLoad: function(this: MechanismBlock): void {
// mrcOnLoad is called for each MechanismBlock when the blocks are loaded in the blockly workspace.
this.mrcValidate();
},
/**
* mrcValidate checks the block, updates it, and/or adds a warning balloon if necessary.
* It is called from mrcOnLoad above and from Editor.makeCurrent.
*/
mrcValidate: function(this: MechanismBlock): void {
const warnings: string[] = [];

const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);
Expand Down
7 changes: 7 additions & 0 deletions src/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ export class Editor {
// Parse modules since they might have changed.
this.parseModules(project, modulePathToContentText);
this.updateToolboxImpl();

// Go through all the blocks in the workspace and call their mrcValidate method.
this.blocklyWorkspace.getAllBlocks().forEach(block => {
if ('mrcValidate' in block && typeof block.mrcValidate === "function") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should 'mrcValidate' be a defined constant? Also why is one of these a single quoted string and one a double quoted one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

block.mrcValidate();
}
});
}

public abandon(): void {
Expand Down