From caf664db042284503b34a853ad70ff81b700f56d Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Wed, 9 Jan 2019 15:38:30 -0800 Subject: [PATCH] Small fixes --- core/block.js | 12 ++++++------ core/blockly.js | 2 +- core/mutator.js | 9 ++++++--- core/theme.js | 5 ++--- tests/generators/index.html | 1 - tests/jsunit/theme_test.js | 6 +++--- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/core/block.js b/core/block.js index f62419231..7dddd6774 100644 --- a/core/block.js +++ b/core/block.js @@ -239,7 +239,7 @@ Blockly.Block.prototype.colour_ = '#000000'; /** * Secondary colour of the block. - * Colour of the block if it is a shadow + * Colour of shadow blocks. * @type {?string} * @private */ @@ -247,7 +247,7 @@ Blockly.Block.prototype.secondaryColour_ = null; /** * Tertiary colour of the block. - * Colour of the border on the block. + * Colour of the block's border. * @type {?string} * @private */ @@ -935,12 +935,12 @@ Blockly.Block.prototype.setColour = function(colour) { * @throws {Error} if the block style does not exist. */ Blockly.Block.prototype.setStyle = function(blockStyleName) { - var style = Blockly.getTheme(); - if (!style) { + var theme = Blockly.getTheme(); + if (!theme) { throw Error('Trying to set block style to ' + blockStyleName + - ' before style was defined via Blockly.setStyle().'); + ' before theme was defined via Blockly.setTheme().'); } - var blockStyle = style.getBlockStyle(blockStyleName); + var blockStyle = theme.getBlockStyle(blockStyleName); this.styleName_ = blockStyleName; if (blockStyle) { diff --git a/core/blockly.js b/core/blockly.js index 4f120e4d5..1030f8a7a 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -114,7 +114,7 @@ Blockly.cache3dSupported_ = null; /** * Holds all Blockly style attributes. - * @type {?Blockly.Style} + * @type {?Blockly.Theme} * @private */ Blockly.theme_ = null; diff --git a/core/mutator.js b/core/mutator.js index ed85ce149..004be6996 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -402,13 +402,16 @@ Blockly.Mutator.prototype.dispose = function() { * @public */ Blockly.Mutator.prototype.updateBlockStyle = function() { - if (this.workspace_ && this.workspace_.getAllBlocks()){ - var workspaceBlocks = this.workspace_.getAllBlocks(); + var ws = this.workspace_; + + if (ws && ws.getAllBlocks()){ + var workspaceBlocks = ws.getAllBlocks(); for (var i = 0; i < workspaceBlocks.length; i++) { var block = workspaceBlocks[i]; block.setStyle(block.getStyleName()); } - var flyoutBlocks = this.workspace_.flyout_.workspace_.getAllBlocks(); + + var flyoutBlocks = ws.flyout_.workspace_.getAllBlocks(); for (var i = 0; i < flyoutBlocks.length; i++) { var block = flyoutBlocks[i]; block.setStyle(block.getStyleName()); diff --git a/core/theme.js b/core/theme.js index c4d3dddfa..993e59bc4 100644 --- a/core/theme.js +++ b/core/theme.js @@ -20,16 +20,15 @@ /** * @fileoverview The class representing a theme. - * @author aschmiedt@google.com (Abby Schmiedt) */ 'use strict'; goog.provide('Blockly.Theme'); /** * Class for a theme. - * @param {Object.} blockStyles A map from style + * @param {?Object.} blockStyles A map from style * names (strings) to objects with style attributes relating to blocks. - * @param {Object.} categoryStyles A map from style + * @param {?Object.} categoryStyles A map from style * names (strings) to objects with style attributes relating to categories. * @constructor */ diff --git a/tests/generators/index.html b/tests/generators/index.html index be72c7675..a3bb602f7 100644 --- a/tests/generators/index.html +++ b/tests/generators/index.html @@ -91,7 +91,6 @@ function start() { zoom: {controls: true, wheel: true} }); changeIndex(); - Blockly.setTheme(Blockly.Themes.Classic); } /* diff --git a/tests/jsunit/theme_test.js b/tests/jsunit/theme_test.js index 07e3cfdb3..782b8be90 100644 --- a/tests/jsunit/theme_test.js +++ b/tests/jsunit/theme_test.js @@ -91,7 +91,7 @@ function test_getAllBlockStyles() { function test_getBlockStyles() { var theme = new Blockly.Theme(createBlockStyles()); - var blockStyle = theme.getBlockStyle("styleOne"); + var blockStyle = theme.getBlockStyle('styleOne'); stringifyAndCompare(blockStyle, createBlockStyles().styleOne); } @@ -99,7 +99,7 @@ function test_getBlockStyles() { function test_setBlockStyleUpdate() { var theme = new Blockly.Theme(createBlockStyles()); var blockStyle = createBlockStyles(); - blockStyle.styleOne.primaryColour = "somethingElse"; + blockStyle.styleOne.primaryColour = 'somethingElse'; theme.setBlockStyle('styleOne', blockStyle.styleOne); @@ -142,7 +142,7 @@ function test_setTheme() { //check that the toolbox refreshed method was called assertEquals(workspace.refreshToolboxSelection(), 3); - assertEquals(Blockly.Events.FIRE_QUEUE_.pop().element, "themeChanged"); + assertEquals(Blockly.Events.FIRE_QUEUE_.pop().element, 'themeChanged'); undefineThemeTestBlocks(); }