Skip to content

Commit d061fd4

Browse files
committed
Use Blockly.Msg.When instead of 'when'.
If the blockly workspace is RTL, reverse the words in the button text.
1 parent da56a34 commit d061fd4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/blocks/mrc_event_handler.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ function generateRegisterEventHandler(
409409
// Functions used for creating blocks for the toolbox.
410410

411411
export function addRobotEventHandlerBlocks(
412+
workspace: Blockly.WorkspaceSvg,
412413
events: storageModuleContent.Event[],
413414
eventHandlerBlocks: EventHandlerBlock[],
414415
contents: toolboxItems.ContentsType[]) {
@@ -420,7 +421,7 @@ export function addRobotEventHandlerBlocks(
420421
events.forEach(event => {
421422
if (eventIds.includes(event.eventId)) {
422423
// If there is already an event handler for this event, put a button in the toolbox.
423-
const text = '\u00A0\u00A0when\u00A0\u00A0' + SENDER_VALUE_ROBOT + '\u00A0\u00A0' + event.name + '\u00A0\u00A0';
424+
const text = makeButtonText(workspace, SENDER_VALUE_ROBOT, event.name);
424425
const button = new toolboxItems.Button(text, BUTTON_CALLBACK_KEY, BUTTON_STYLE);
425426
contents.push(button);
426427
} else {
@@ -450,6 +451,7 @@ function createRobotEventHandlerBlock(
450451
}
451452

452453
export function addMechanismEventHandlerBlocks(
454+
workspace: Blockly.WorkspaceSvg,
453455
mechanismInRobot: storageModuleContent.MechanismInRobot,
454456
events: storageModuleContent.Event[],
455457
eventHandlerBlocks: EventHandlerBlock[],
@@ -462,7 +464,7 @@ export function addMechanismEventHandlerBlocks(
462464
events.forEach(event => {
463465
if (eventIds.includes(event.eventId)) {
464466
// If there is already an event handler for this event, put a button in the toolbox.
465-
const text = 'when ' + mechanismInRobot.name + ' ' + event.name;
467+
const text = makeButtonText(workspace, mechanismInRobot.name, event.name);
466468
const button = new toolboxItems.Button(text, BUTTON_CALLBACK_KEY, BUTTON_STYLE);
467469
contents.push(button);
468470
} else {
@@ -471,6 +473,16 @@ export function addMechanismEventHandlerBlocks(
471473
});
472474
}
473475

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.
479+
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;
484+
}
485+
474486
function createMechanismEventHandlerBlock(
475487
mechanismInRobot: storageModuleContent.MechanismInRobot,
476488
event: storageModuleContent.Event): toolboxItems.Block {

src/toolbox/event_handlers_category.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class EventHandlersCategory {
9797
// Get the list of events from the robot.
9898
const eventsFromRobot = editor.getEventsFromRobot();
9999
const eventHandlerBlocks = editor.getRobotEventHandlersAlreadyInWorkspace();
100-
addRobotEventHandlerBlocks(eventsFromRobot, eventHandlerBlocks, contents);
100+
addRobotEventHandlerBlocks(workspace, eventsFromRobot, eventHandlerBlocks, contents);
101101

102102
const toolboxInfo = {
103103
contents: contents,
@@ -124,7 +124,7 @@ class EventHandlersCategory {
124124
const eventHandlerBlocks = editor.getMechanismEventHandlersAlreadyInWorkspace(
125125
this.mechanismInRobot);
126126
addMechanismEventHandlerBlocks(
127-
this.mechanismInRobot, eventsFromMechanism, eventHandlerBlocks, contents);
127+
workspace, this.mechanismInRobot, eventsFromMechanism, eventHandlerBlocks, contents);
128128
if (contents.length === 0) {
129129
const label : toolboxItems.Label = new toolboxItems.Label(Blockly.Msg['NO_MECHANISM_CONTENTS']);
130130
contents.push(label);

0 commit comments

Comments
 (0)