-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathloops.js
More file actions
51 lines (50 loc) · 1.67 KB
/
Copy pathloops.js
File metadata and controls
51 lines (50 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Blockly.Blocks['controls_forEach'] = {
/**
* Block for 'for each' loop.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "for each item %1 in list %2 : ", //Blockly.Msg.CONTROLS_FOREACH_TITLE,
"args0": [
{
"type": "input_value",
"name": "VAR",
"check": "Tuple"
},
{
"type": "input_value",
"name": "LIST",
"check": "Array"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Blocks.loops.HUE,
"helpUrl": Blockly.Msg.CONTROLS_FOREACH_HELPURL
});
this.appendStatementInput('DO')
.appendField(Blockly.Msg.CONTROLS_FOREACH_INPUT_DO);
this.setInputsInline(true);
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
this.setTooltip(function() {
return Blockly.Msg.CONTROLS_FOREACH_TOOLTIP.replace('%1',
Blockly.Python.valueToCode(thisBlock, 'VAR', Blockly.Python.ORDER_RELATIONAL) || '___');
});
},
customContextMenu: Blockly.Blocks['controls_for'].customContextMenu
};
Blockly.Python['controls_forEach'] = function(block) {
// For each loop.
var variable0 = Blockly.Python.valueToCode(block, 'VAR',
Blockly.Python.ORDER_RELATIONAL) || '___';
var argument0 = Blockly.Python.valueToCode(block, 'LIST',
Blockly.Python.ORDER_RELATIONAL) || '___';
var branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) ||
Blockly.Python.PASS;
var code = 'for ' + variable0 + ' in ' + argument0 + ':\n' + branch;
return code;
};