From 5c18e102ca3c989e8ff03cb46e43807618a01e62 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 21 Mar 2019 15:32:18 -0700 Subject: [PATCH] Fixed setTheme so it doesn't error when no workspace is created --- core/blockly.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index f8b21e1e5..ab4923f96 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -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); }; /**