From 1b3955d9d650addfeaf9899c97697ab2a0448159 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Fri, 21 Dec 2018 07:52:50 -0800 Subject: [PATCH] Fixing review comments --- blocks/lists.js | 16 +++++++-------- blocks/procedures.js | 14 ++++++------- blocks/text.js | 10 ++++----- core/block.js | 10 ++++----- core/inject.js | 2 ++ core/options.js | 5 +++++ core/style.js | 27 ++++++++++++++++++++++--- style/classic.js | 26 ++++++++++++++++++++++++ style/highcontrast.js | 28 ++++++++++++++++++++++++-- style/modern.js | 26 ++++++++++++++++++++++++ style/style_script/styles_example.json | 20 ++++++++++++++++++ tests/jsunit/block_test.js | 2 +- tests/playground.html | 2 -- 13 files changed, 154 insertions(+), 34 deletions(-) diff --git a/blocks/lists.js b/blocks/lists.js index f40493286..92b485d5c 100644 --- a/blocks/lists.js +++ b/blocks/lists.js @@ -133,7 +133,7 @@ Blockly.Blocks['lists_create_with'] = { */ init: function() { this.setHelpUrl(Blockly.Msg['LISTS_CREATE_WITH_HELPURL']); - this.setStyle("lists"); + this.setStyle('lists'); this.itemCount_ = 3; this.updateShape_(); this.setOutput(true, 'Array'); @@ -256,7 +256,7 @@ Blockly.Blocks['lists_create_with_container'] = { * @this Blockly.Block */ init: function() { - this.setStyle("lists"); + this.setStyle('lists'); this.appendDummyInput() .appendField(Blockly.Msg['LISTS_CREATE_WITH_CONTAINER_TITLE_ADD']); this.appendStatementInput('STACK'); @@ -271,7 +271,7 @@ Blockly.Blocks['lists_create_with_item'] = { * @this Blockly.Block */ init: function() { - this.setStyle("lists"); + this.setStyle('lists'); this.appendDummyInput() .appendField(Blockly.Msg['LISTS_CREATE_WITH_ITEM_TITLE']); this.setPreviousStatement(true); @@ -293,7 +293,7 @@ Blockly.Blocks['lists_indexOf'] = { [Blockly.Msg['LISTS_INDEX_OF_LAST'], 'LAST'] ]; this.setHelpUrl(Blockly.Msg['LISTS_INDEX_OF_HELPURL']); - this.setStyle("lists"); + this.setStyle('lists'); this.setOutput(true, 'Number'); this.appendValueInput('VALUE') .setCheck('Array') @@ -331,7 +331,7 @@ Blockly.Blocks['lists_getIndex'] = { [Blockly.Msg['LISTS_GET_INDEX_RANDOM'], 'RANDOM'] ]; this.setHelpUrl(Blockly.Msg['LISTS_GET_INDEX_HELPURL']); - this.setStyle("lists"); + this.setStyle('lists'); var modeMenu = new Blockly.FieldDropdown(MODE, function(value) { var isStatement = (value == 'REMOVE'); this.sourceBlock_.updateStatement_(isStatement); @@ -515,7 +515,7 @@ Blockly.Blocks['lists_setIndex'] = { [Blockly.Msg['LISTS_GET_INDEX_RANDOM'], 'RANDOM'] ]; this.setHelpUrl(Blockly.Msg['LISTS_SET_INDEX_HELPURL']); - this.setStyle("lists"); + this.setStyle('lists'); this.appendValueInput('LIST') .setCheck('Array') .appendField(Blockly.Msg['LISTS_SET_INDEX_INPUT_IN_LIST']); @@ -654,7 +654,7 @@ Blockly.Blocks['lists_getSublist'] = { [Blockly.Msg['LISTS_GET_SUBLIST_END_LAST'], 'LAST'] ]; this.setHelpUrl(Blockly.Msg['LISTS_GET_SUBLIST_HELPURL']); - this.setStyle("lists"); + this.setStyle('lists'); this.appendValueInput('LIST') .setCheck('Array') .appendField(Blockly.Msg['LISTS_GET_SUBLIST_INPUT_IN_LIST']); @@ -803,7 +803,7 @@ Blockly.Blocks['lists_split'] = { thisBlock.updateType_(newMode); }); this.setHelpUrl(Blockly.Msg['LISTS_SPLIT_HELPURL']); - this.setStyle("lists"); + this.setStyle('lists'); this.appendValueInput('INPUT') .setCheck('String') .appendField(dropdown, 'MODE'); diff --git a/blocks/procedures.js b/blocks/procedures.js index 46fa63a33..4425f185a 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -50,7 +50,7 @@ Blockly.Blocks['procedures_defnoreturn'] = { Blockly.Msg['PROCEDURES_DEFNORETURN_COMMENT']) { this.setCommentText(Blockly.Msg['PROCEDURES_DEFNORETURN_COMMENT']); } - this.setStyle("procedures"); + this.setStyle('procedures'); this.setTooltip(Blockly.Msg['PROCEDURES_DEFNORETURN_TOOLTIP']); this.setHelpUrl(Blockly.Msg['PROCEDURES_DEFNORETURN_HELPURL']); this.arguments_ = []; @@ -416,7 +416,7 @@ Blockly.Blocks['procedures_defreturn'] = { Blockly.Msg['PROCEDURES_DEFRETURN_COMMENT']) { this.setCommentText(Blockly.Msg['PROCEDURES_DEFRETURN_COMMENT']); } - this.setStyle("procedures"); + this.setStyle('procedures'); this.setTooltip(Blockly.Msg['PROCEDURES_DEFRETURN_TOOLTIP']); this.setHelpUrl(Blockly.Msg['PROCEDURES_DEFRETURN_HELPURL']); this.arguments_ = []; @@ -462,7 +462,7 @@ Blockly.Blocks['procedures_mutatorcontainer'] = { this.appendDummyInput('STATEMENT_INPUT') .appendField(Blockly.Msg['PROCEDURES_ALLOW_STATEMENTS']) .appendField(new Blockly.FieldCheckbox('TRUE'), 'STATEMENTS'); - this.setStyle("procedures"); + this.setStyle('procedures'); this.setTooltip(Blockly.Msg['PROCEDURES_MUTATORCONTAINER_TOOLTIP']); this.contextMenu = false; } @@ -489,7 +489,7 @@ Blockly.Blocks['procedures_mutatorarg'] = { .appendField(field, 'NAME'); this.setPreviousStatement(true); this.setNextStatement(true); - this.setStyle("procedures"); + this.setStyle('procedures'); this.setTooltip(Blockly.Msg['PROCEDURES_MUTATORARG_TOOLTIP']); this.contextMenu = false; @@ -562,7 +562,7 @@ Blockly.Blocks['procedures_callnoreturn'] = { .appendField(this.id, 'NAME'); this.setPreviousStatement(true); this.setNextStatement(true); - this.setStyle("procedures"); + this.setStyle('procedures'); // Tooltip is set in renameProcedure. this.setHelpUrl(Blockly.Msg['PROCEDURES_CALLNORETURN_HELPURL']); this.arguments_ = []; @@ -903,7 +903,7 @@ Blockly.Blocks['procedures_callreturn'] = { this.appendDummyInput('TOPROW') .appendField('', 'NAME'); this.setOutput(true); - this.setStyle("procedures"); + this.setStyle('procedures'); // Tooltip is set in domToMutation. this.setHelpUrl(Blockly.Msg['PROCEDURES_CALLRETURN_HELPURL']); this.arguments_ = []; @@ -940,7 +940,7 @@ Blockly.Blocks['procedures_ifreturn'] = { this.setInputsInline(true); this.setPreviousStatement(true); this.setNextStatement(true); - this.setStyle("procedures"); + this.setStyle('procedures'); this.setTooltip(Blockly.Msg['PROCEDURES_IFRETURN_TOOLTIP']); this.setHelpUrl(Blockly.Msg['PROCEDURES_IFRETURN_HELPURL']); this.hasReturnValue_ = true; diff --git a/blocks/text.js b/blocks/text.js index d58fadd37..9d3f8833a 100644 --- a/blocks/text.js +++ b/blocks/text.js @@ -221,7 +221,7 @@ Blockly.Blocks['text_getSubstring'] = { [Blockly.Msg['TEXT_GET_SUBSTRING_END_LAST'], 'LAST'] ]; this.setHelpUrl(Blockly.Msg['TEXT_GET_SUBSTRING_HELPURL']); - this.setStyle("text"); + this.setStyle('text'); this.appendValueInput('STRING') .setCheck('String') .appendField(Blockly.Msg['TEXT_GET_SUBSTRING_INPUT_IN_TEXT']); @@ -329,7 +329,7 @@ Blockly.Blocks['text_changeCase'] = { [Blockly.Msg['TEXT_CHANGECASE_OPERATOR_TITLECASE'], 'TITLECASE'] ]; this.setHelpUrl(Blockly.Msg['TEXT_CHANGECASE_HELPURL']); - this.setStyle("text"); + this.setStyle('text'); this.appendValueInput('TEXT') .setCheck('String') .appendField(new Blockly.FieldDropdown(OPERATORS), 'CASE'); @@ -350,7 +350,7 @@ Blockly.Blocks['text_trim'] = { [Blockly.Msg['TEXT_TRIM_OPERATOR_RIGHT'], 'RIGHT'] ]; this.setHelpUrl(Blockly.Msg['TEXT_TRIM_HELPURL']); - this.setStyle("text"); + this.setStyle('text'); this.appendValueInput('TEXT') .setCheck('String') .appendField(new Blockly.FieldDropdown(OPERATORS), 'MODE'); @@ -393,7 +393,7 @@ Blockly.Blocks['text_prompt_ext'] = { [Blockly.Msg['TEXT_PROMPT_TYPE_NUMBER'], 'NUMBER'] ]; this.setHelpUrl(Blockly.Msg['TEXT_PROMPT_HELPURL']); - this.setStyle("text"); + this.setStyle('text'); // Assign 'this' to a variable for use in the closures below. var thisBlock = this; var dropdown = new Blockly.FieldDropdown(TYPES, function(newOp) { @@ -453,7 +453,7 @@ Blockly.Blocks['text_prompt'] = { // Assign 'this' to a variable for use in the closures below. var thisBlock = this; this.setHelpUrl(Blockly.Msg['TEXT_PROMPT_HELPURL']); - this.setStyle("text"); + this.setStyle('text'); var dropdown = new Blockly.FieldDropdown(TYPES, function(newOp) { thisBlock.updateType_(newOp); }); diff --git a/core/block.js b/core/block.js index 680bc5161..e1b626e63 100644 --- a/core/block.js +++ b/core/block.js @@ -928,13 +928,12 @@ Blockly.Block.prototype.setColour = function(colour) { * @throws {Error} if the block style does not exist. */ Blockly.Block.prototype.setStyle = function(blockStyleName) { - var dereferenced = Blockly.utils.replaceMessageReferences(blockStyleName); var style = Blockly.getStyle(); if (!style) { - throw 'Trying to set block style before Blockly.setStyle() has been called'; + throw Error('Trying to set block style before Blockly.setStyle() has been called'); } - var blockStyle = style.getBlockStyle(dereferenced); - this.styleName_ = dereferenced; + var blockStyle = style.getBlockStyle(blockStyleName); + this.styleName_ = blockStyleName; if (blockStyle) { this.style_ = blockStyle; @@ -944,8 +943,7 @@ Blockly.Block.prototype.setStyle = function(blockStyleName) { this.setColour(blockStyle.primaryColour); } else { - var errorMsg = 'Invalid style name: ' + blockStyleName; - throw errorMsg; + throw Error('Invalid style name: ' + blockStyleName); } }; diff --git a/core/inject.js b/core/inject.js index 2792f54e1..94e67ea0e 100644 --- a/core/inject.js +++ b/core/inject.js @@ -73,6 +73,8 @@ Blockly.inject = function(container, opt_options) { Blockly.mainWorkspace = workspace; Blockly.svgResize(workspace); + + Blockly.setStyle(options.style); return workspace; }; diff --git a/core/options.js b/core/options.js index 0bbf36889..29355941b 100644 --- a/core/options.js +++ b/core/options.js @@ -119,6 +119,10 @@ Blockly.Options = function(options) { } else { var oneBasedIndex = !!options['oneBasedIndex']; } + var style = options['style']; + if (style === undefined) { + style = Blockly.Styles.Classic; + } this.RTL = rtl; this.oneBasedIndex = oneBasedIndex; @@ -140,6 +144,7 @@ Blockly.Options = function(options) { this.gridOptions = Blockly.Options.parseGridOptions_(options); this.zoomOptions = Blockly.Options.parseZoomOptions_(options); this.toolboxPosition = toolboxPosition; + this.style = style; }; /** diff --git a/core/style.js b/core/style.js index 5e535cd80..d0f60f90f 100644 --- a/core/style.js +++ b/core/style.js @@ -1,3 +1,27 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2018 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview The class representing a style. + * @author aschmiedt@google.com (Abby Schmiedt) + */ 'use strict'; goog.provide('Blockly.Style'); @@ -45,8 +69,5 @@ Blockly.Style.prototype.getBlockStyle = function(blockStyleName) { * @param{Blockly.BlockStyle} blockStyle The block style */ Blockly.Style.prototype.setBlockStyle = function(blockStyleName, blockStyle) { - var event = new Blockly.Events.Ui(null, 'blockStyleChanged', - this.blockStyles_[blockStyleName], blockStyle); this.blockStyles_[blockStyleName] = blockStyle; - Blockly.Events.fire(event); }; diff --git a/style/classic.js b/style/classic.js index 1810341a9..176d3b44d 100644 --- a/style/classic.js +++ b/style/classic.js @@ -1,3 +1,29 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2018 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Classic style. + * Contains multi colored border to create shadow effect. + * @author aschmiedt@google.com (Abby Schmiedt) + */ + 'use strict'; goog.provide('Blockly.Styles.Classic'); diff --git a/style/highcontrast.js b/style/highcontrast.js index 416f54c25..c318d2997 100644 --- a/style/highcontrast.js +++ b/style/highcontrast.js @@ -1,3 +1,28 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2018 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview High contrast style. + * Darker colors to contrast the white block font. + * @author aschmiedt@google.com (Abby Schmiedt) + */ 'use strict'; goog.provide('Blockly.Styles.HighContrast'); @@ -52,6 +77,5 @@ var defaultBlockStyles = { } }; - - +//This style is still being fleshed out and may change. Blockly.Styles.HighContrast = new Blockly.Style(defaultBlockStyles); diff --git a/style/modern.js b/style/modern.js index 7206e671c..e568f4b95 100644 --- a/style/modern.js +++ b/style/modern.js @@ -1,3 +1,28 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2018 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Modern style. + * Same colors as classic, but single colored border. + * @author aschmiedt@google.com (Abby Schmiedt) + */ 'use strict'; goog.provide('Blockly.Styles.Modern'); @@ -52,4 +77,5 @@ var defaultBlockStyles = { } }; +//This style is still being fleshed out and may change. Blockly.Styles.Modern = new Blockly.Style(defaultBlockStyles); diff --git a/style/style_script/styles_example.json b/style/style_script/styles_example.json index e58191c18..9fb8fc100 100644 --- a/style/style_script/styles_example.json +++ b/style/style_script/styles_example.json @@ -1,3 +1,23 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2018 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + { "colour":"#A5745B", "lists":"260", diff --git a/tests/jsunit/block_test.js b/tests/jsunit/block_test.js index ecf0de5d8..5c26893c1 100644 --- a/tests/jsunit/block_test.js +++ b/tests/jsunit/block_test.js @@ -293,7 +293,7 @@ function test_set_style_throw_exception() { try { blockA.setStyle('styleOne'); }catch(error) { - assertEquals(error, "Invalid style name: styleOne"); + assertEquals(error.message, "Invalid style name: styleOne"); }finally { blockTest_tearDown(); } diff --git a/tests/playground.html b/tests/playground.html index 26e4d5895..24262cb5c 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -139,8 +139,6 @@ function start() { logEvents(false); } taChange(); - changeStyle(); - } function changeStyle() {