2121 */
2222import * as Blockly from 'blockly' ;
2323
24- import { ExtendedPythonGenerator } from '../editor/extended_python_generator' ;
25- import { createFieldNonEditableText } from '../fields/FieldNonEditableText' ;
26- import { MRC_STYLE_VARIABLES } from '../themes/styles' ;
27- import { BLOCK_NAME as MRC_STEPS , StepsBlock } from './mrc_steps'
24+ import { ExtendedPythonGenerator } from '../editor/extended_python_generator' ;
25+ import { createFieldNonEditableText } from '../fields/FieldNonEditableText' ;
26+ import { MRC_STYLE_VARIABLES } from '../themes/styles' ;
27+ import { BLOCK_NAME as MRC_STEPS , StepsBlock } from './mrc_steps'
2828
2929export const BLOCK_NAME = 'mrc_jump_to_step' ;
3030
@@ -45,60 +45,60 @@ const JUMP_TO_STEP_BLOCK = {
4545 /**
4646 * Block initialization.
4747 */
48- init : function ( this : JumpToStepBlock ) : void {
48+ init : function ( this : JumpToStepBlock ) : void {
4949 this . appendDummyInput ( )
50- . appendField ( 'Jump to' )
51- . appendField ( createFieldNonEditableText ( '' ) , FIELD_STEP_NAME ) ;
50+ . appendField ( 'Jump to' )
51+ . appendField ( createFieldNonEditableText ( '' ) , FIELD_STEP_NAME ) ;
5252 this . setPreviousStatement ( true , null ) ;
5353 this . setInputsInline ( true ) ;
5454 this . setStyle ( MRC_STYLE_VARIABLES ) ;
55- this . setTooltip ( 'Jump to the specified step.' ) ;
55+ this . setTooltip ( 'Jump to the specified step.' ) ;
56+ } ,
57+ /**
58+ * mrcOnMove is called when an EventBlock is moved.
59+ */
60+ mrcOnMove : function ( this : JumpToStepBlock , _reason : string [ ] ) : void {
61+ this . checkBlockPlacement ( ) ;
62+ } ,
63+ mrcOnAncestorMove : function ( this : JumpToStepBlock ) : void {
64+ this . checkBlockPlacement ( ) ;
65+ } ,
66+ checkBlockPlacement : function ( this : JumpToStepBlock ) : void {
67+ const legalStepNames : string [ ] = [ ] ;
68+
69+ const rootBlock : Blockly . Block | null = this . getRootBlock ( ) ;
70+ if ( rootBlock . type === MRC_STEPS ) {
71+ // This block is within a class method definition.
72+ const stepsBlock = rootBlock as StepsBlock ;
73+ // Add the method's parameter names to legalStepNames.
74+ legalStepNames . push ( ...stepsBlock . mrcGetStepNames ( ) ) ;
75+ }
76+
77+ if ( legalStepNames . includes ( this . getFieldValue ( FIELD_STEP_NAME ) ) ) {
78+ // If this blocks's parameter name is in legalParameterNames, it's good.
79+ this . setWarningText ( null , WARNING_ID_NOT_IN_STEP ) ;
80+ this . mrcHasWarning = false ;
81+ } else {
82+ // Otherwise, add a warning to this block.
83+ if ( ! this . mrcHasWarning ) {
84+ this . setWarningText ( Blockly . Msg . JUMP_CAN_ONLY_GO_IN_THEIR_STEPS_BLOCK , WARNING_ID_NOT_IN_STEP ) ;
85+ this . getIcon ( Blockly . icons . IconType . WARNING ) ! . setBubbleVisible ( true ) ;
86+ this . mrcHasWarning = true ;
87+ }
88+ }
5689 } ,
57- /**
58- * mrcOnMove is called when an EventBlock is moved.
59- */
60- mrcOnMove : function ( this : JumpToStepBlock , _reason : string [ ] ) : void {
61- this . checkBlockPlacement ( ) ;
62- } ,
63- mrcOnAncestorMove : function ( this : JumpToStepBlock ) : void {
64- this . checkBlockPlacement ( ) ;
65- } ,
66- checkBlockPlacement : function ( this : JumpToStepBlock ) : void {
67- const legalStepNames : string [ ] = [ ] ;
68-
69- const rootBlock : Blockly . Block | null = this . getRootBlock ( ) ;
70- if ( rootBlock . type === MRC_STEPS ) {
71- // This block is within a class method definition.
72- const stepsBlock = rootBlock as StepsBlock ;
73- // Add the method's parameter names to legalStepNames.
74- legalStepNames . push ( ...stepsBlock . mrcGetStepNames ( ) ) ;
75- }
76-
77- if ( legalStepNames . includes ( this . getFieldValue ( FIELD_STEP_NAME ) ) ) {
78- // If this blocks's parameter name is in legalParameterNames, it's good.
79- this . setWarningText ( null , WARNING_ID_NOT_IN_STEP ) ;
80- this . mrcHasWarning = false ;
81- } else {
82- // Otherwise, add a warning to this block.
83- if ( ! this . mrcHasWarning ) {
84- this . setWarningText ( Blockly . Msg . JUMP_CAN_ONLY_GO_IN_THEIR_STEPS_BLOCK , WARNING_ID_NOT_IN_STEP ) ;
85- this . getIcon ( Blockly . icons . IconType . WARNING ) ! . setBubbleVisible ( true ) ;
86- this . mrcHasWarning = true ;
87- }
88- }
89- } ,
9090} ;
9191
92- export const setup = function ( ) {
92+ export const setup = function ( ) {
9393 Blockly . Blocks [ BLOCK_NAME ] = JUMP_TO_STEP_BLOCK ;
9494} ;
9595
96- export const pythonFromBlock = function (
97- block : JumpToStepBlock ,
98- _generator : ExtendedPythonGenerator ,
96+ export const pythonFromBlock = function (
97+ block : JumpToStepBlock ,
98+ _generator : ExtendedPythonGenerator ,
9999) {
100100 let code = 'self.current_step_index = self.mrc_step_name_to_index["' +
101- block . getFieldValue ( FIELD_STEP_NAME ) + '"]\n' ;
101+ block . getFieldValue ( FIELD_STEP_NAME ) + '"]\n' ;
102102 code += 'return\n' ;
103103
104104 return code ;
0 commit comments