From 4192ca6b52f5b28ac7602e220b04515e436a1b2b Mon Sep 17 00:00:00 2001 From: Emma Dauterman Date: Fri, 26 Aug 2016 11:35:53 -0700 Subject: [PATCH] Blockly Factory: Prompt User to Add Variables/Functions Category (#589) * Fixed marking shadow blocks so keeps warnings when switching between categories * Done with variable and procedure block checks * Used setShadowDom instead of shadowDom_, and nit changes in wfactory init * Fixed bug of disable div covering whole screen --- demos/blocklyfactory/factory.css | 16 +- demos/blocklyfactory/factory_utils.js | 37 ++++ demos/blocklyfactory/index.html | 1 - .../workspacefactory/wfactory_controller.js | 203 ++++++++++-------- .../workspacefactory/wfactory_init.js | 53 ++++- .../workspacefactory/wfactory_view.js | 32 ++- 6 files changed, 229 insertions(+), 113 deletions(-) diff --git a/demos/blocklyfactory/factory.css b/demos/blocklyfactory/factory.css index 5a6600eeb..dad8922c3 100644 --- a/demos/blocklyfactory/factory.css +++ b/demos/blocklyfactory/factory.css @@ -430,8 +430,9 @@ td { padding-right: 20px; } -.test { - border: 1px solid black; +.disabled { + background-color: white; + opacity: 0.5; } #toolbox_div { @@ -466,17 +467,6 @@ td { margin-top: 2%; } -#disable_div { - background-color: white; - height: 100%; - left: 0; - opacity: .5; - position: absolute; - top: 0; - width: 100%; - z-index: -1; /* Start behind workspace */ -} - /* Rules for Closure popup color picker */ .goog-palette { outline: none; diff --git a/demos/blocklyfactory/factory_utils.js b/demos/blocklyfactory/factory_utils.js index f8ce4c861..89e421663 100644 --- a/demos/blocklyfactory/factory_utils.js +++ b/demos/blocklyfactory/factory_utils.js @@ -913,3 +913,40 @@ FactoryUtils.sameBlockXml = function(blockXml1, blockXml2) { return blockXmlText1 == blockXmlText2; }; +/* + * Checks if a block has a variable field. Blocks with variable fields cannot + * be shadow blocks. + * + * @param {Blockly.Block} block The block to check if a variable field exists. + * @return {boolean} True if the block has a variable field, false otherwise. + */ +FactoryUtils.hasVariableField = function(block) { + if (!block) { + return false; + } + for (var i = 0, input; input = block.inputList[i]; i++) { + for (var j = 0, field; field = input.fieldRow[j]; j++) { + if (field.name == 'VAR') { + return true; + } + } + } + return false; +}; + +/** + * Checks if a block is a procedures block. If procedures block names are + * ever updated or expanded, this function should be updated as well (no + * other known markers for procedure blocks beyond name). + * + * @param {Blockly.Block} block The block to check. + * @return {boolean} True if hte block is a procedure block, false otherwise. + */ +FactoryUtils.isProcedureBlock = function(block) { + return block && + (block.type == 'procedures_defnoreturn' || + block.type == 'procedures_defreturn' || + block.type == 'procedures_callnoreturn' || + block.type == 'procedures_callreturn' || + block.type == 'procedures_ifreturn'); +}; diff --git a/demos/blocklyfactory/index.html b/demos/blocklyfactory/index.html index 641ec2e16..8a5e8fd23 100644 --- a/demos/blocklyfactory/index.html +++ b/demos/blocklyfactory/index.html @@ -180,7 +180,6 @@
-