diff --git a/core/variables.js b/core/variables.js index ea354ec6b..0049ed388 100644 --- a/core/variables.js +++ b/core/variables.js @@ -37,13 +37,14 @@ 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) { + if (root instanceof Blockly.Block) { // Root is Block. blocks = root.getDescendants(); } else if (root.getAllBlocks) { @@ -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 instanceof Blockly.Block) { + // 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. diff --git a/core/workspace.js b/core/workspace.js index 6e044fcb4..71d5cfa45 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]);