From 5c18e102ca3c989e8ff03cb46e43807618a01e62 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 21 Mar 2019 15:32:18 -0700 Subject: [PATCH 1/3] 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); }; /** From b6b7ab009146db594e638f899911f60a20432095 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Fri, 22 Mar 2019 09:54:52 -0700 Subject: [PATCH 2/3] Refactor setTheme --- core/blockly.js | 52 ++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index ab4923f96..c707a50e4 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -691,31 +691,39 @@ Blockly.setTheme = function(theme) { var ws = Blockly.getMainWorkspace(); 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 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); + this.refreshTheme_(ws); } }; +/** + * Refresh the theme for all items on the workspace. + * @param {Blockly.Workspace} ws Blockly workspace to refresh theme on. + */ +Blockly.refreshTheme_ = function(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 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); +}; + /** * Updates all the blocks with new style. * @param {!Array.} blocks List of blocks to update the style on. From bf45c85bf16a7d40d799c9d8e3f0cecb6cadf798 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Fri, 22 Mar 2019 10:14:43 -0700 Subject: [PATCH 3/3] Add private annotation --- core/blockly.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/blockly.js b/core/blockly.js index c707a50e4..24a8ed923 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -698,6 +698,7 @@ Blockly.setTheme = function(theme) { /** * Refresh the theme for all items on the workspace. * @param {Blockly.Workspace} ws Blockly workspace to refresh theme on. + * @private */ Blockly.refreshTheme_ = function(ws) { //update all blocks in workspace that have a style name