diff --git a/blocks/loops.js b/blocks/loops.js index adf03a1bd..ad65adae2 100644 --- a/blocks/loops.js +++ b/blocks/loops.js @@ -168,26 +168,6 @@ Blockly.Blocks['controls_for'] = { thisBlock.getFieldValue('VAR')); }); }, - /** - * Return all variables referenced by this block. - * @return {!Array.} List of variable names. - * @this Blockly.Block - */ - getVars: function() { - return [this.getFieldValue('VAR')]; - }, - /** - * Notification that a variable is renaming. - * If the name matches one of this block's variables, rename it. - * @param {string} oldName Previous name of variable. - * @param {string} newName Renamed variable. - * @this Blockly.Block - */ - renameVar: function(oldName, newName) { - if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) { - this.setFieldValue(newName, 'VAR'); - } - }, /** * Add menu option to create getter block for loop variable. * @param {!Array} options List of menu options to add to. @@ -242,26 +222,6 @@ Blockly.Blocks['controls_forEach'] = { thisBlock.getFieldValue('VAR')); }); }, - /** - * Return all variables referenced by this block. - * @return {!Array.} List of variable names. - * @this Blockly.Block - */ - getVars: function() { - return [this.getFieldValue('VAR')]; - }, - /** - * Notification that a variable is renaming. - * If the name matches one of this block's variables, rename it. - * @param {string} oldName Previous name of variable. - * @param {string} newName Renamed variable. - * @this Blockly.Block - */ - renameVar: function(oldName, newName) { - if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) { - this.setFieldValue(newName, 'VAR'); - } - }, customContextMenu: Blockly.Blocks['controls_for'].customContextMenu }; diff --git a/blocks/math.js b/blocks/math.js index 81fadc5b8..4e87d5a7a 100644 --- a/blocks/math.js +++ b/blocks/math.js @@ -288,26 +288,6 @@ Blockly.Blocks['math_change'] = { return Blockly.Msg.MATH_CHANGE_TOOLTIP.replace('%1', thisBlock.getFieldValue('VAR')); }); - }, - /** - * Return all variables referenced by this block. - * @return {!Array.} List of variable names. - * @this Blockly.Block - */ - getVars: function() { - return [this.getFieldValue('VAR')]; - }, - /** - * Notification that a variable is renaming. - * If the name matches one of this block's variables, rename it. - * @param {string} oldName Previous name of variable. - * @param {string} newName Renamed variable. - * @this Blockly.Block - */ - renameVar: function(oldName, newName) { - if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) { - this.setFieldValue(newName, 'VAR'); - } } }; diff --git a/blocks/text.js b/blocks/text.js index c95f79ef8..55308e1d1 100644 --- a/blocks/text.js +++ b/blocks/text.js @@ -247,26 +247,6 @@ Blockly.Blocks['text_append'] = { return Blockly.Msg.TEXT_APPEND_TOOLTIP.replace('%1', thisBlock.getFieldValue('VAR')); }); - }, - /** - * Return all variables referenced by this block. - * @return {!Array.} List of variable names. - * @this Blockly.Block - */ - getVars: function() { - return [this.getFieldValue('VAR')]; - }, - /** - * Notification that a variable is renaming. - * If the name matches one of this block's variables, rename it. - * @param {string} oldName Previous name of variable. - * @param {string} newName Renamed variable. - * @this Blockly.Block - */ - renameVar: function(oldName, newName) { - if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) { - this.setFieldValue(newName, 'VAR'); - } } }; diff --git a/blocks/variables.js b/blocks/variables.js index 5aab716eb..3b7d99f92 100644 --- a/blocks/variables.js +++ b/blocks/variables.js @@ -49,26 +49,6 @@ Blockly.Blocks['variables_get'] = { this.setTooltip(Blockly.Msg.VARIABLES_GET_TOOLTIP); this.contextMenuMsg_ = Blockly.Msg.VARIABLES_GET_CREATE_SET; }, - /** - * Return all variables referenced by this block. - * @return {!Array.} List of variable names. - * @this Blockly.Block - */ - getVars: function() { - return [this.getFieldValue('VAR')]; - }, - /** - * Notification that a variable is renaming. - * If the name matches one of this block's variables, rename it. - * @param {string} oldName Previous name of variable. - * @param {string} newName Renamed variable. - * @this Blockly.Block - */ - renameVar: function(oldName, newName) { - if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) { - this.setFieldValue(newName, 'VAR'); - } - }, contextMenuType_: 'variables_set', /** * Add menu option to create getter/setter block for this setter/getter. @@ -115,26 +95,6 @@ Blockly.Blocks['variables_set'] = { }); this.contextMenuMsg_ = Blockly.Msg.VARIABLES_SET_CREATE_GET; }, - /** - * Return all variables referenced by this block. - * @return {!Array.} List of variable names. - * @this Blockly.Block - */ - getVars: function() { - return [this.getFieldValue('VAR')]; - }, - /** - * Notification that a variable is renaming. - * If the name matches one of this block's variables, rename it. - * @param {string} oldName Previous name of variable. - * @param {string} newName Renamed variable. - * @this Blockly.Block - */ - renameVar: function(oldName, newName) { - if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) { - this.setFieldValue(newName, 'VAR'); - } - }, contextMenuType_: 'variables_get', customContextMenu: Blockly.Blocks['variables_get'].customContextMenu }; diff --git a/core/block.js b/core/block.js index ca4a6f978..07fca2678 100644 --- a/core/block.js +++ b/core/block.js @@ -623,6 +623,39 @@ Blockly.Block.prototype.getField = function(name) { return null; }; +/** + * Return all variables referenced by this block. + * @return {!Array.} List of variable names. + */ +Blockly.Block.prototype.getVars = function() { + var vars = []; + for (var i = 0, input; input = this.inputList[i]; i++) { + for (var j = 0, field; field = input.fieldRow[j]; j++) { + if (field instanceof Blockly.FieldVariable) { + vars.push(field.getValue()); + } + } + } + return vars; +}; + +/** + * Notification that a variable is renaming. + * If the name matches one of this block's variables, rename it. + * @param {string} oldName Previous name of variable. + * @param {string} newName Renamed variable. + */ +Blockly.Block.prototype.renameVar = function(oldName, newName) { + for (var i = 0, input; input = this.inputList[i]; i++) { + for (var j = 0, field; field = input.fieldRow[j]; j++) { + if (field instanceof Blockly.FieldVariable && + Blockly.Names.equals(oldName, field.getValue())) { + field.setValue(newName); + } + } + } +}; + /** * Returns the language-neutral value from the field of a block. * @param {string} name The name of the field. diff --git a/core/widgetdiv.js b/core/widgetdiv.js index 3342aa365..817d15bac 100644 --- a/core/widgetdiv.js +++ b/core/widgetdiv.js @@ -89,12 +89,12 @@ Blockly.WidgetDiv.show = function(newOwner, rtl, dispose) { */ Blockly.WidgetDiv.hide = function() { if (Blockly.WidgetDiv.owner_) { + Blockly.WidgetDiv.owner_ = null; Blockly.WidgetDiv.DIV.style.display = 'none'; Blockly.WidgetDiv.DIV.style.left = ''; Blockly.WidgetDiv.DIV.style.top = ''; Blockly.WidgetDiv.DIV.style.height = ''; Blockly.WidgetDiv.dispose_ && Blockly.WidgetDiv.dispose_(); - Blockly.WidgetDiv.owner_ = null; Blockly.WidgetDiv.dispose_ = null; goog.dom.removeChildren(Blockly.WidgetDiv.DIV); }