diff --git a/blocks_vertical/data.js b/blocks_vertical/data.js index a610ae8788..02cdf4781a 100644 --- a/blocks_vertical/data.js +++ b/blocks_vertical/data.js @@ -403,6 +403,33 @@ Blockly.Blocks['data_replaceitemoflist'] = { } }; + +Blockly.Blocks['data_setlist'] = { + /** + * Block to insert item to list. + * @this Blockly.Block + */ + init: function() { + this.jsonInit({ + "message0": Blockly.Msg.DATA_SETLIST, + "args0": [ + { + "type": "field_variable", + "name": "LIST", + "variableTypes": [Blockly.LIST_VARIABLE_TYPE] + }, + { + "type": "input_value", + "name": "ARRAY", + "check": "Array" + } + ], + "category": Blockly.Categories.dataLists, + "extensions": ["colours_data_lists", "shape_statement"] + }); + } +}; + Blockly.Blocks['data_itemoflist'] = { /** * Block for reporting item of list. diff --git a/core/data_category.js b/core/data_category.js index b2b73eea9d..3ed440497b 100644 --- a/core/data_category.js +++ b/core/data_category.js @@ -83,6 +83,7 @@ Blockly.DataCategory = function(workspace) { // Blockly.DataCategory.addDeleteAllOfList(xmlList, firstVariable); Blockly.DataCategory.addInsertAtList(xmlList, firstVariable); Blockly.DataCategory.addReplaceItemOfList(xmlList, firstVariable); + Blockly.DataCategory.addSetList(xmlList, firstVariable); Blockly.DataCategory.addSep(xmlList); Blockly.DataCategory.addItemOfList(xmlList, firstVariable); Blockly.DataCategory.addItemNumberOfList(xmlList, firstVariable); @@ -310,6 +311,16 @@ Blockly.DataCategory.addReplaceItemOfList = function(xmlList, variable) { 'LIST', ['INDEX', 'data_listindexrandom', 1], ['ITEM', 'text', Blockly.Msg.DEFAULT_LIST_ITEM]); }; +/** + * Construct and add a data_setlist block to xmlList. + * @param {!Array.} xmlList Array of XML block elements. + * @param {?Blockly.VariableModel} variable Variable to select in the field. + */ +Blockly.DataCategory.addSetList = function(xmlList, variable) { + Blockly.DataCategory.addBlock(xmlList, variable, 'data_setlist', + 'LIST', 'ARRAY'); +}; + /** * Construct and add a data_itemoflist block to xmlList. * @param {!Array.} xmlList Array of XML block elements. @@ -476,6 +487,9 @@ Blockly.DataCategory.addBlock = function(xmlList, variable, blockType, */ Blockly.DataCategory.createValue = function(valueName, type, value) { var fieldName; + if (valueName === 'ARRAY') { + return ''; + } switch (valueName) { case 'ITEM': fieldName = 'TEXT'; diff --git a/msg/messages.js b/msg/messages.js index c490bceda4..28b51c9926 100644 --- a/msg/messages.js +++ b/msg/messages.js @@ -66,6 +66,7 @@ Blockly.Msg.DATA_DELETEOFLIST = 'delete %1 of %2'; Blockly.Msg.DATA_DELETEALLOFLIST = 'delete all of %1'; Blockly.Msg.DATA_INSERTATLIST = 'insert %1 at %2 of %3'; Blockly.Msg.DATA_REPLACEITEMOFLIST = 'replace item %1 of %2 with %3'; +Blockly.Msg.DATA_SETLIST = 'set list %1 to %2'; Blockly.Msg.DATA_ITEMOFLIST = 'item %1 of %2'; Blockly.Msg.DATA_ITEMNUMOFLIST = 'item # of %1 in %2'; Blockly.Msg.DATA_LENGTHOFLIST = 'length of %1';