Provide default getVars and renameVar functions. Issue 265.

This commit is contained in:
Neil Fraser
2016-02-27 12:28:32 -08:00
parent a22b936229
commit 4c542240e2
6 changed files with 34 additions and 121 deletions

View File

@@ -168,26 +168,6 @@ Blockly.Blocks['controls_for'] = {
thisBlock.getFieldValue('VAR'));
});
},
/**
* Return all variables referenced by this block.
* @return {!Array.<string>} 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.<string>} 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
};

View File

@@ -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.<string>} 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');
}
}
};

View File

@@ -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.<string>} 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');
}
}
};

View File

@@ -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.<string>} 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.<string>} 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
};