@@ -36,7 +36,7 @@ import * as storageModuleContent from '../storage/module_content';
3636export const BLOCK_NAME = 'mrc_event_handler' ;
3737
3838const BUTTON_CALLBACK_KEY = 'EVENT_HANDLER_ALREADY_ON_WORKSPACE' ;
39- const BUTTON_STYLE = 'eventHandlerButtonStyle ' ;
39+ const BUTTON_STYLE_PREFIX = 'eventHandlerButtonStyle_ ' ;
4040
4141const FIELD_SENDER = 'SENDER' ;
4242const FIELD_EVENT_NAME = 'EVENT_NAME' ;
@@ -421,9 +421,7 @@ export function addRobotEventHandlerBlocks(
421421 events . forEach ( event => {
422422 if ( eventIds . includes ( event . eventId ) ) {
423423 // If there is already an event handler for this event, put a button in the toolbox.
424- const text = makeButtonText ( workspace , SENDER_VALUE_ROBOT , event . name ) ;
425- const button = new toolboxItems . Button ( text , BUTTON_CALLBACK_KEY , BUTTON_STYLE ) ;
426- contents . push ( button ) ;
424+ contents . push ( createButton ( workspace , SENDER_VALUE_ROBOT , event . name ) ) ;
427425 } else {
428426 contents . push ( createRobotEventHandlerBlock ( event ) ) ;
429427 }
@@ -464,23 +462,22 @@ export function addMechanismEventHandlerBlocks(
464462 events . forEach ( event => {
465463 if ( eventIds . includes ( event . eventId ) ) {
466464 // If there is already an event handler for this event, put a button in the toolbox.
467- const text = makeButtonText ( workspace , mechanismInRobot . name , event . name ) ;
468- const button = new toolboxItems . Button ( text , BUTTON_CALLBACK_KEY , BUTTON_STYLE ) ;
469- contents . push ( button ) ;
465+ contents . push ( createButton ( workspace , mechanismInRobot . name , event . name ) ) ;
470466 } else {
471467 contents . push ( createMechanismEventHandlerBlock ( mechanismInRobot , event ) ) ;
472468 }
473469 } ) ;
474470}
475471
476- function makeButtonText (
477- workspace : Blockly . WorkspaceSvg , senderName : string , eventName : string ) : string {
478- // Add non-breakable spaces so it looks more like an event handler block.
472+ function createButton (
473+ workspace : Blockly . WorkspaceSvg , senderName : string , eventName : string ) : toolboxItems . Button {
474+ // Use non-breakable spaces so it looks more like an event handler block.
479475 const spaces = '\u00A0\u00A0' ;
480- if ( workspace . RTL ) {
481- return spaces + eventName + spaces + senderName + spaces + Blockly . Msg . WHEN + spaces ;
482- }
483- return spaces + Blockly . Msg . WHEN + spaces + senderName + spaces + eventName + spaces ;
476+ const text = workspace . RTL
477+ ? ( spaces + eventName + spaces + senderName + spaces + Blockly . Msg . WHEN + spaces )
478+ : ( spaces + Blockly . Msg . WHEN + spaces + senderName + spaces + eventName + spaces ) ;
479+ const style = BUTTON_STYLE_PREFIX + workspace . getTheme ( ) . name ;
480+ return new toolboxItems . Button ( text , BUTTON_CALLBACK_KEY , style ) ;
484481}
485482
486483function createMechanismEventHandlerBlock (
0 commit comments