2121
2222import * as Blockly from 'blockly/core' ;
2323
24+ import { GeneratorContext } from './generator_context' ;
2425import * as commonStorage from '../storage/common_storage' ;
2526import { MRC_CATEGORY_STYLE_METHODS } from '../themes/styles'
2627import { mechanism_class_blocks } from './mechanism_class_methods' ;
@@ -38,16 +39,13 @@ export const category = {
3839} ;
3940
4041export class MethodsCategory {
41- private currentModule : commonStorage . Module | null = null ;
42+ private generatorContext : GeneratorContext ;
4243
43- constructor ( blocklyWorkspace : Blockly . WorkspaceSvg ) {
44+ constructor ( blocklyWorkspace : Blockly . WorkspaceSvg , generatorContext : GeneratorContext ) {
45+ this . generatorContext = generatorContext ;
4446 blocklyWorkspace . registerToolboxCategoryCallback ( CUSTOM_CATEGORY_METHODS , this . methodsFlyout . bind ( this ) ) ;
4547 }
4648
47- public setCurrentModule ( currentModule : commonStorage . Module | null ) {
48- this . currentModule = currentModule ;
49- }
50-
5149 public methodsFlyout ( workspace : Blockly . WorkspaceSvg ) : ToolboxInfo {
5250 const toolboxInfo = {
5351 contents : [
@@ -110,6 +108,8 @@ export class MethodsCategory {
110108 // mrc_call_python_function block.
111109 workspace . getBlocksByType ( 'mrc_class_method_def' , false ) . forEach ( ( classMethodDefBlock ) => {
112110 if ( classMethodDefBlock . mrcCanBeCalledWithinClass ) {
111+ const nameFieldValue = classMethodDefBlock . getFieldValue ( 'NAME' ) ;
112+ const classMethodName = this . generatorContext . getClassMethodName ( nameFieldValue ) ;
113113 const callPythonFunctionBlock = {
114114 kind : 'block' ,
115115 type : 'mrc_call_python_function' ,
@@ -118,10 +118,10 @@ export class MethodsCategory {
118118 functionKind : 'instance_within' ,
119119 returnType : classMethodDefBlock . mrcReturnType ,
120120 args : [ ] ,
121- actualFunctionName : classMethodDefBlock . mrcPythonMethodName ,
121+ actualFunctionName : classMethodName ,
122122 } ,
123123 fields : {
124- FUNC : classMethodDefBlock . getFieldValue ( 'NAME' ) ,
124+ FUNC : nameFieldValue ,
125125 } ,
126126 } ;
127127 classMethodDefBlock . mrcParameters . forEach ( ( param ) => {
0 commit comments