diff --git a/core/block.js b/core/block.js index 07fa108c4..f62419231 100644 --- a/core/block.js +++ b/core/block.js @@ -1361,6 +1361,13 @@ Blockly.Block.prototype.jsonInit = function(json) { } // Set basic properties of block. + // Makes styles backward compatible with old way of defining hat style. + if (json['style'] && json['style'].hat) { + this.hat = json['style'].hat; + //Must set to null so it doesn't error when checking for style and colour. + json['style'] = null; + } + if (json['style'] && json['colour']) { throw Error(warningPrefix + 'Must not have both a colour and a style.'); } else if (json['style']) { diff --git a/core/block_render_svg.js b/core/block_render_svg.js index 2cff473c7..c530f6061 100644 --- a/core/block_render_svg.js +++ b/core/block_render_svg.js @@ -566,7 +566,7 @@ Blockly.BlockSvg.prototype.renderDraw_ = function(iconWidth, inputRows) { if (prevBlock && prevBlock.getNextBlock() == this) { this.squareTopLeftCorner_ = true; } - } else if (Blockly.BlockSvg.START_HAT || this.hat) { + } else if (Blockly.BlockSvg.START_HAT || this.hat === 'cap') { // No output or previous connection. this.squareTopLeftCorner_ = true; this.startHat_ = true; diff --git a/core/blockly.js b/core/blockly.js index fcfa0b95d..4f120e4d5 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -689,8 +689,12 @@ Blockly.setTheme = function(theme) { this.theme_ = theme; var ws = Blockly.getMainWorkspace(); - //update blocks in workspace - this.updateBlockStyles_(ws.getAllBlocks()); + //update all blocks in workspace that have a style name + this.updateBlockStyles_(ws.getAllBlocks().filter( + function(block){ + return block.getStyleName() !== undefined; + } + )); //update blocks in the flyout if (!ws.toolbox_ && ws.flyout_ && ws.flyout_.workspace_) { diff --git a/tests/blocks/test_blocks.js b/tests/blocks/test_blocks.js index 3a092309d..f7a00062e 100644 --- a/tests/blocks/test_blocks.js +++ b/tests/blocks/test_blocks.js @@ -30,7 +30,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "message0": "value to stack", "nextStatement": null, "output": null, - "colour": 230 + "style": "math_blocks" }, { "type": "value_to_statement", @@ -42,7 +42,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT } ], "output": null, - "colour": 230 + "style": "math_blocks" }, { "type": "limit_instances", @@ -58,7 +58,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT ], "previousStatement": null, "nextStatement": null, - "colour": 230, + "style": "math_blocks", }, { "type": "example_dropdown_long", @@ -199,7 +199,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "text": "0" } ], - "colour": 230, + "style": "math_blocks", "output": "Number", "tooltip": "A number." }, @@ -214,7 +214,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "text": "0" } ], - "colour": 230, + "style": "math_blocks", "output": "Number", "tooltip": "An integer." }, @@ -229,7 +229,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "text": "0" } ], - "colour": 230, + "style": "math_blocks", "output": "Number", "tooltip": "A dollar amount." }, @@ -246,7 +246,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "text": "0" } ], - "colour": 230, + "style": "math_blocks", "output": "Note", "tooltip": "A midi note." }, @@ -262,7 +262,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "alt": "*" } ], - "colour": 160 + "style": "text_blocks" }, { "type": "image_small", @@ -276,7 +276,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "alt": "*" } ], - "colour": 160 + "style": "text_blocks" }, { "type": "image_large", @@ -290,7 +290,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "alt": "*" } ], - "colour": 160 + "style": "text_blocks" }, { "type": "image_missing", @@ -304,7 +304,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "alt": "*" } ], - "colour": 160 + "style": "text_blocks" }, { "type": "test_with_lots_of_network_icons", @@ -429,7 +429,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "alt": "H" } ], - "colour": 160 + "style": "text_blocks" }, { "type": "styled_event_cap",