diff --git a/core/block.js b/core/block.js index 260483c60..27b3c94c8 100644 --- a/core/block.js +++ b/core/block.js @@ -933,19 +933,20 @@ Blockly.Block.prototype.setColour = function(colour) { * @throws {Error} if the block style does not exist. */ Blockly.Block.prototype.setStyle = function(blockStyleName) { - if (blockStyleName) { - var blockStyle = Blockly.getStyle().getBlockStyle(blockStyleName); + var dereferenced = Blockly.utils.replaceMessageReferences(blockStyleName); + var blockStyle = Blockly.getStyle().getBlockStyle(dereferenced); + this.styleName_ = dereferenced; - if (blockStyle) { - this.style_ = blockStyle; - this.setColour(blockStyle.primaryColour); - this.secondaryColour_ = blockStyle.secondaryColour; - this.tertiaryColour_ = blockStyle.tertiaryColour; - } - else { - var errorMsg = 'Invalid style name: ' + blockStyleName; - throw errorMsg; - } + if (blockStyle) { + this.style_ = blockStyle; + this.secondaryColour_ = blockStyle.secondaryColour; + this.tertiaryColour_ = blockStyle.tertiaryColour; + // Set colour will trigger an updateColour() on a block_svg + this.setColour(blockStyle.primaryColour); + } + else { + var errorMsg = 'Invalid style name: ' + blockStyleName; + throw errorMsg; } }; @@ -1449,14 +1450,12 @@ Blockly.Block.prototype.jsonInitColour_ = function(json, warningPrefix) { Blockly.Block.prototype.jsonInitStyle_ = function(json, warningPrefix) { var blockStyleName = json['style']; try { - this.styleName_ = blockStyleName; this.setStyle(blockStyleName); } catch (colorError) { console.warn(warningPrefix + 'Style does not exist: ', blockStyleName); } }; - /** * Add key/values from mixinObj to this block object. By default, this method * will check that the keys in mixinObj will not overwrite existing values in diff --git a/core/blockly.js b/core/blockly.js index 556ae7e8d..f9ef77992 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -688,7 +688,6 @@ Blockly.setStyle = function(style){ for (var i = 0; i < blocks.length; i++) { var block = blocks[i]; block.setStyle(block.getStyleName()); - block.updateColour(); } var event = new Blockly.Events.Ui(null, 'styleChanged');