@@ -211,22 +211,22 @@ const CALL_PYTHON_FUNCTION = {
211211 }
212212 case FunctionKind . EVENT : {
213213 const eventName = this . getFieldValue ( FIELD_EVENT_NAME ) ;
214- tooltip = Blockly . Msg . CALL_INSTANCE_METHOD_WITHIN_TOOLTIP ;
214+ tooltip = Blockly . Msg . FIRE_EVENT_TOOLTIP ;
215215 tooltip = tooltip . replace ( '{{eventName}}' , eventName ) ;
216216 break ;
217217 }
218218 case FunctionKind . INSTANCE_COMPONENT : {
219219 const className = this . mrcComponentClassName ;
220220 const functionName = this . getFieldValue ( FIELD_FUNCTION_NAME ) ;
221221 if ( this . mrcMechanismId ) {
222- tooltip = Blockly . Msg . CALL_MECHANISM_COMPONENT_INSTANCE_METHOD ;
222+ tooltip = Blockly . Msg . CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_TOOLTIP ;
223223 tooltip = tooltip
224224 . replace ( '{{className}}' , className )
225225 . replace ( '{{functionName}}' , functionName )
226226 . replace ( '{{componentName}}' , this . getFieldValue ( FIELD_COMPONENT_NAME ) )
227227 . replace ( '{{mechanismName}}' , this . getFieldValue ( FIELD_MECHANISM_NAME ) ) ;
228228 } else {
229- tooltip = Blockly . Msg . CALL_COMPONENT_INSTANCE_METHOD ;
229+ tooltip = Blockly . Msg . CALL_COMPONENT_INSTANCE_METHOD_TOOLTIP ;
230230 tooltip = tooltip
231231 . replace ( '{{className}}' , className )
232232 . replace ( '{{functionName}}' , functionName )
@@ -236,18 +236,18 @@ const CALL_PYTHON_FUNCTION = {
236236 }
237237 case FunctionKind . INSTANCE_ROBOT : {
238238 const functionName = this . getFieldValue ( FIELD_FUNCTION_NAME ) ;
239- tooltip = Blockly . Msg . CALL_INSTANCE_METHOD_WITHIN_TOOLTIP ;
239+ tooltip = Blockly . Msg . CALL_ROBOT_INSTANCE_METHOD_TOOLTIP ;
240240 tooltip = tooltip . replace ( '{{functionName}}' , functionName ) ;
241241 break ;
242242 }
243243 case FunctionKind . INSTANCE_MECHANISM : {
244244 const className = this . mrcMechanismClassName ;
245245 const functionName = this . getFieldValue ( FIELD_FUNCTION_NAME ) ;
246- tooltip = Blockly . Msg . CALL_MECHANISM_INSTANCE_METHOD ;
247- tooltip = tooltip
248- . replace ( '{{className}}' , className )
249- . replace ( '{{functionName}}' , functionName )
250- . replace ( '{{mechanismName}}' , this . getFieldValue ( FIELD_MECHANISM_NAME ) ) ;
246+ tooltip = Blockly . Msg . CALL_MECHANISM_INSTANCE_METHOD_TOOLTIP ;
247+ tooltip = tooltip
248+ . replace ( '{{className}}' , className )
249+ . replace ( '{{functionName}}' , functionName )
250+ . replace ( '{{mechanismName}}' , this . getFieldValue ( FIELD_MECHANISM_NAME ) ) ;
251251 break ;
252252 }
253253 default :
@@ -436,7 +436,7 @@ const CALL_PYTHON_FUNCTION = {
436436 case FunctionKind . INSTANCE_ROBOT : {
437437 this . appendDummyInput ( INPUT_TITLE )
438438 . appendField ( Blockly . Msg . CALL )
439- . appendField ( createFieldNonEditableText ( Blockly . Msg . ROBOT ) )
439+ . appendField ( createFieldNonEditableText ( Blockly . Msg . ROBOT_LOWER_CASE ) )
440440 . appendField ( '.' )
441441 . appendField ( createFieldNonEditableText ( '' ) , FIELD_FUNCTION_NAME ) ;
442442 break ;
@@ -549,66 +549,59 @@ const CALL_PYTHON_FUNCTION = {
549549 }
550550 this . updateBlock_ ( ) ;
551551 } ,
552- getComponents : function ( this : CallPythonFunctionBlock ) : storageModuleContent . Component [ ] {
552+ getComponents : function ( this : CallPythonFunctionBlock , editor : Editor ) : storageModuleContent . Component [ ] {
553553 // Get the list of components whose type matches this.mrcComponentClassName.
554554 const components : storageModuleContent . Component [ ] = [ ] ;
555- const editor = Editor . getEditorForBlocklyWorkspace ( this . workspace , true /* returnCurrentIfNotFound */ ) ;
556- if ( editor ) {
557- let componentsToConsider : storageModuleContent . Component [ ] = [ ] ;
558- if ( this . mrcMechanismId ) {
559- // Only consider components that belong to the mechanism.
560- // this.mrcMechanismId is the mechanismId from the MechanismInRobot.
561- // We need to get the MechanismInRobot with that id, then get the mechanism, and then get
562- // the public components defined in that mechanism.
563- for ( const mechanismInRobot of editor . getMechanismsFromRobot ( ) ) {
564- if ( mechanismInRobot . mechanismId === this . mrcMechanismId ) {
565- for ( const mechanism of editor . getMechanisms ( ) ) {
566- if ( mechanism . moduleId === mechanismInRobot . moduleId ) {
567- componentsToConsider = editor . getComponentsFromMechanism ( mechanism ) ;
568- break ;
569- }
555+ let componentsToConsider : storageModuleContent . Component [ ] = [ ] ;
556+ if ( this . mrcMechanismId ) {
557+ // Only consider components that belong to the mechanism.
558+ // this.mrcMechanismId is the mechanismId from the MechanismInRobot.
559+ // We need to get the MechanismInRobot with that id, then get the mechanism, and then get
560+ // the public components defined in that mechanism.
561+ for ( const mechanismInRobot of editor . getMechanismsFromRobot ( ) ) {
562+ if ( mechanismInRobot . mechanismId === this . mrcMechanismId ) {
563+ for ( const mechanism of editor . getMechanisms ( ) ) {
564+ if ( mechanism . moduleId === mechanismInRobot . moduleId ) {
565+ componentsToConsider = editor . getComponentsFromMechanism ( mechanism ) ;
566+ break ;
570567 }
571- break ;
572568 }
569+ break ;
573570 }
574- } else if ( editor . getModuleType ( ) === storageModule . ModuleType . MECHANISM ) {
575- // Only consider components (regular and private) in the current workspace.
576- componentsToConsider = editor . getAllComponentsFromWorkspace ( ) ;
577- } else {
578- // Only consider components in the robot.
579- componentsToConsider = editor . getComponentsFromRobot ( ) ;
580571 }
581- componentsToConsider . forEach ( component => {
582- if ( component . className === this . mrcComponentClassName ) {
583- components . push ( component ) ;
584- }
585- } ) ;
572+ } else if ( editor . getModuleType ( ) === storageModule . ModuleType . MECHANISM ) {
573+ // Only consider components (regular and private) in the current workspace.
574+ componentsToConsider = editor . getAllComponentsFromWorkspace ( ) ;
575+ } else {
576+ // Only consider components in the robot.
577+ componentsToConsider = editor . getComponentsFromRobot ( ) ;
586578 }
579+ componentsToConsider . forEach ( component => {
580+ if ( component . className === this . mrcComponentClassName ) {
581+ components . push ( component ) ;
582+ }
583+ } ) ;
587584 return components ;
588585 } ,
589586
590587 /**
591588 * mrcOnModuleCurrent is called for each CallPythonFunctionBlock when the module becomes the current module.
592589 */
593- mrcOnModuleCurrent : function ( this : CallPythonFunctionBlock ) : void {
594- this . checkFunction ( ) ;
590+ mrcOnModuleCurrent : function ( this : CallPythonFunctionBlock , editor : Editor ) : void {
591+ this . checkFunction ( editor ) ;
595592 } ,
596593 /**
597594 * mrcOnLoad is called for each CallPythonFunctionBlock when the blocks are loaded in the blockly
598595 * workspace.
599596 */
600- mrcOnLoad : function ( this : CallPythonFunctionBlock ) : void {
601- this . checkFunction ( ) ;
597+ mrcOnLoad : function ( this : CallPythonFunctionBlock , editor : Editor ) : void {
598+ this . checkFunction ( editor ) ;
602599 } ,
603600 /**
604601 * checkFunction checks the block, updates it, and/or adds a warning balloon if necessary.
605602 * It is called from mrcOnModuleCurrent and mrcOnLoad above.
606603 */
607- checkFunction : function ( this : CallPythonFunctionBlock ) : void {
608- const editor = Editor . getEditorForBlocklyWorkspace ( this . workspace , true /* returnCurrentIfNotFound */ ) ;
609- if ( ! editor ) {
610- return ;
611- }
604+ checkFunction : function ( this : CallPythonFunctionBlock , editor : Editor ) : void {
612605 const warnings : string [ ] = [ ] ;
613606
614607 // If this block is calling a component method, check whether the component
@@ -621,7 +614,7 @@ const CALL_PYTHON_FUNCTION = {
621614 if ( this . mrcFunctionKind === FunctionKind . INSTANCE_COMPONENT ) {
622615 const componentNames : string [ ] = [ ] ;
623616 this . mrcMapComponentNameToId = { }
624- this . getComponents ( ) . forEach ( component => {
617+ this . getComponents ( editor ) . forEach ( component => {
625618 componentNames . push ( component . name ) ;
626619 this . mrcMapComponentNameToId [ component . name ] = component . componentId ;
627620 } ) ;
@@ -865,7 +858,7 @@ export function pythonFromBlock(
865858 generator : ExtendedPythonGenerator ,
866859) {
867860 if ( block . mrcImportModule ) {
868- generator . addImport ( block . mrcImportModule ) ;
861+ generator . importModule ( block . mrcImportModule ) ;
869862 }
870863 let code = '' ;
871864 let needOpenParen = true ;
0 commit comments