Deprecated field setText function.

This commit is contained in:
Beka Westberg
2019-07-18 10:38:13 -07:00
parent 674b2621ea
commit 20837da54f
4 changed files with 24 additions and 2 deletions

View File

@@ -1078,7 +1078,7 @@ Blockly.Block.prototype.updateVarName = function(variable) {
for (var j = 0, field; field = input.fieldRow[j]; j++) {
if (field.referencesVariables() &&
variable.getId() == field.getValue()) {
field.setText(variable.name);
field.updateVariableName();
}
}
}

View File

@@ -706,6 +706,7 @@ Blockly.Field.prototype.getText = function() {
/**
* Set the text in this field. Trigger a rerender of the source block.
* @param {*} newText New text.
* @deprecated 2019 setText should not be used directly. Use setValue instead.
*/
Blockly.Field.prototype.setText = function(newText) {
if (newText === null) {

View File

@@ -167,8 +167,19 @@ Blockly.FieldImage.prototype.getFlipRtl = function() {
* Set the alt text of this image.
* @param {?string} alt New alt text.
* @override
* @deprecated 2019 setText has been deprecated for all fields. Instead use
* setAlt to set the alt text of the field.
*/
Blockly.FieldImage.prototype.setText = function(alt) {
this.setAlt(alt);
};
/**
* Set the alt text of this image.
* @param {?string} alt New alt text.
* @public
*/
Blockly.FieldImage.prototype.setAlt = function(alt) {
if (alt === null) {
// No change if null.
return;

View File

@@ -253,7 +253,7 @@ Blockly.FieldVariable.prototype.doClassValidation_ = function(newId) {
Blockly.FieldVariable.prototype.doValueUpdate_ = function(newId) {
this.variable_ = Blockly.Variables.getVariable(this.workspace_, newId);
this.value_ = newId;
this.text_ = (this.variable_.name);
this.text_ = this.variable_.name;
this.isDirty_ = true;
};
@@ -341,6 +341,16 @@ Blockly.FieldVariable.prototype.setTypes_ = function(opt_variableTypes,
this.variableTypes = variableTypes;
};
/**
* A callback to update the name of a variable. Should only be called by
* the block.
* @package
*/
Blockly.FieldVariable.prototype.updateVariableName = function() {
this.text_ = this.variable_.name;
this.forceRerender();
};
/**
* Return a sorted list of variable names for variable dropdown menus.
* Include a special option at the end for creating a new variable name.