Fixes error thrown for style defined inline

This commit is contained in:
alschmiedt
2019-01-09 13:44:22 -08:00
parent 40a1ae752b
commit 55a46f8299
4 changed files with 26 additions and 15 deletions

View File

@@ -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']) {

View File

@@ -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;

View File

@@ -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_) {

View File

@@ -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",