From 2364aed7160e2f60227ca6dadaa63fa292eb5949 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 7 Jul 2016 15:23:20 -0700 Subject: [PATCH 1/3] Distinguish between allVariables and allUsedVariables --- core/variables.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/core/variables.js b/core/variables.js index ea354ec6..d9af525c 100644 --- a/core/variables.js +++ b/core/variables.js @@ -37,11 +37,12 @@ goog.require('goog.string'); Blockly.Variables.NAME_TYPE = 'VARIABLE'; /** - * Find all user-created variables. + * Find all user-created variables that are in use in the workspace. + * For use by generators. * @param {!Blockly.Block|!Blockly.Workspace} root Root block or workspace. * @return {!Array.} Array of variable names. */ -Blockly.Variables.allVariables = function(root) { +Blockly.Variables.allUsedVariables = function(root) { var blocks; if (root.getDescendants) { // Root is Block. @@ -74,6 +75,22 @@ Blockly.Variables.allVariables = function(root) { return variableList; }; +/** + * Find all variables that the user has created through the workspace or + * toolbox. For use by generators. + * @param {!Blockly.Workspace} root The workspace to inspect. + * @return {!Array.} Array of variable names. + */ +Blockly.Variables.allVariables = function(root) { + if (root.getDescendants) { + // Root is Block. + console.warn('Deprecated call to Blockly.Variables.allVariables ' + + 'with a block instead of a workspace. You may want ' + + 'Blockly.Variables.allUsedVariables'); + } + return root.variableList; +}; + /** * Find all instances of the specified variable and rename them. * @param {string} oldName Variable to rename. From 3f0b2961a1c419c3b5985967c160ea8ef5484133 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 7 Jul 2016 15:28:23 -0700 Subject: [PATCH 2/3] call allUsedVariables in addTopBlock --- core/workspace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/workspace.js b/core/workspace.js index 6e044fcb..71d5cfa4 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -119,7 +119,7 @@ Blockly.Workspace.SCAN_ANGLE = 3; Blockly.Workspace.prototype.addTopBlock = function(block) { this.topBlocks_.push(block); if (this.isFlyout) { - var variables = Blockly.Variables.allVariables(block); + var variables = Blockly.Variables.allUsedVariables(block); for (var i = 0; i < variables.length; i++) { if (this.variableList.indexOf(variables[i]) == -1) { this.variableList.push(variables[i]); From 75e06de477ff9770896139b29729d9c28a5dd294 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 13 Jul 2016 12:50:44 -0700 Subject: [PATCH 3/3] Use instanceof to distinguish between blocks and workspaces. --- core/variables.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/variables.js b/core/variables.js index d9af525c..0049ed38 100644 --- a/core/variables.js +++ b/core/variables.js @@ -44,7 +44,7 @@ Blockly.Variables.NAME_TYPE = 'VARIABLE'; */ Blockly.Variables.allUsedVariables = function(root) { var blocks; - if (root.getDescendants) { + if (root instanceof Blockly.Block) { // Root is Block. blocks = root.getDescendants(); } else if (root.getAllBlocks) { @@ -82,7 +82,7 @@ Blockly.Variables.allUsedVariables = function(root) { * @return {!Array.} Array of variable names. */ Blockly.Variables.allVariables = function(root) { - if (root.getDescendants) { + if (root instanceof Blockly.Block) { // Root is Block. console.warn('Deprecated call to Blockly.Variables.allVariables ' + 'with a block instead of a workspace. You may want ' +