Fixed setTheme so it doesn't error when no workspace is created

This commit is contained in:
alschmiedt
2019-03-21 15:32:18 -07:00
parent ba67d2082d
commit 5c18e102ca

View File

@@ -690,28 +690,30 @@ Blockly.setTheme = function(theme) {
this.theme_ = theme;
var ws = Blockly.getMainWorkspace();
//update all blocks in workspace that have a style name
this.updateBlockStyles_(ws.getAllBlocks().filter(
function(block){
return block.getStyleName() !== undefined;
}
));
if (ws) {
//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_) {
this.updateBlockStyles_(ws.flyout_.workspace_.getAllBlocks());
} else {
ws.refreshToolboxSelection();
//update blocks in the flyout
if (!ws.toolbox_ && ws.flyout_ && ws.flyout_.workspace_) {
this.updateBlockStyles_(ws.flyout_.workspace_.getAllBlocks());
} else {
ws.refreshToolboxSelection();
}
//update colours on the categories
if (ws.toolbox_) {
ws.toolbox_.updateColourFromTheme();
}
var event = new Blockly.Events.Ui(null, 'theme');
event.workspaceId = ws.id;
Blockly.Events.fire(event);
}
//update colours on the categories
if (ws.toolbox_) {
ws.toolbox_.updateColourFromTheme();
}
var event = new Blockly.Events.Ui(null, 'theme');
event.workspaceId = ws.id;
Blockly.Events.fire(event);
};
/**