Added getSourceBlock function to field. (#2508)

This commit is contained in:
Beka Westberg
2019-05-29 12:50:00 -07:00
committed by RoboErikG
parent 9099ee8c14
commit 73ff710a4d
8 changed files with 26 additions and 19 deletions

View File

@@ -334,7 +334,7 @@ Blockly.Blocks['lists_getIndex'] = {
this.setStyle('list_blocks');
var modeMenu = new Blockly.FieldDropdown(MODE, function(value) {
var isStatement = (value == 'REMOVE');
this.sourceBlock_.updateStatement_(isStatement);
this.getSourceBlock().updateStatement_(isStatement);
});
this.appendValueInput('VALUE')
.setCheck('Array')
@@ -480,7 +480,7 @@ Blockly.Blocks['lists_getIndex'] = {
var newAt = (value == 'FROM_START') || (value == 'FROM_END');
// The 'isAt' variable is available due to this function being a closure.
if (newAt != isAt) {
var block = this.sourceBlock_;
var block = this.getSourceBlock();
block.updateAt_(newAt);
// This menu has been destroyed and replaced. Update the replacement.
block.setFieldValue(value, 'WHERE');
@@ -618,7 +618,7 @@ Blockly.Blocks['lists_setIndex'] = {
var newAt = (value == 'FROM_START') || (value == 'FROM_END');
// The 'isAt' variable is available due to this function being a closure.
if (newAt != isAt) {
var block = this.sourceBlock_;
var block = this.getSourceBlock();
block.updateAt_(newAt);
// This menu has been destroyed and replaced. Update the replacement.
block.setFieldValue(value, 'WHERE');
@@ -723,14 +723,13 @@ Blockly.Blocks['lists_getSublist'] = {
// The 'isAt' variable is available due to this function being a
// closure.
if (newAt != isAt) {
var block = this.sourceBlock_;
var block = this.getSourceBlock();
block.updateAt_(n, newAt);
// This menu has been destroyed and replaced.
// Update the replacement.
block.setFieldValue(value, 'WHERE' + n);
return null;
}
return undefined;
});
this.getInput('AT' + n)
.appendField(menu, 'WHERE' + n);

View File

@@ -504,7 +504,7 @@ Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN = {
Blockly.Constants.Math.IS_DIVISIBLE_MUTATOR_EXTENSION = function() {
this.getField('PROPERTY').setValidator(function(option) {
var divisorInput = (option == 'DIVISIBLE_BY');
this.sourceBlock_.updateShape_(divisorInput);
this.getSourceBlock().updateShape_(divisorInput);
});
};

View File

@@ -572,15 +572,15 @@ Blockly.Blocks['procedures_mutatorarg'] = {
* @this Blockly.FieldTextInput
*/
validator_: function(varName) {
var outerWs = Blockly.Mutator.findParentWs(this.sourceBlock_.workspace);
var outerWs = Blockly.Mutator.findParentWs(this.getSourceBlock().workspace);
varName = varName.replace(/[\s\xa0]+/g, ' ').replace(/^ | $/g, '');
if (!varName) {
return null;
}
// Prevents duplicate parameter names in functions
var blocks = this.sourceBlock_.workspace.getAllBlocks();
var blocks = this.getSourceBlock().workspace.getAllBlocks();
for (var i = 0; i < blocks.length; i += 1) {
if (blocks[i].id == this.sourceBlock_.id) {
if (blocks[i].id == this.getSourceBlock().id) {
continue;
}
if (blocks[i].getFieldValue('NAME') == varName) {
@@ -609,7 +609,7 @@ Blockly.Blocks['procedures_mutatorarg'] = {
* @this Blockly.FieldTextInput
*/
deleteIntermediateVars_: function(newText) {
var outerWs = Blockly.Mutator.findParentWs(this.sourceBlock_.workspace);
var outerWs = Blockly.Mutator.findParentWs(this.getSourceBlock().workspace);
if (!outerWs) {
return;
}

View File

@@ -296,7 +296,7 @@ Blockly.Blocks['text_getSubstring'] = {
// The 'isAt' variable is available due to this function being a
// closure.
if (newAt != isAt) {
var block = this.sourceBlock_;
var block = this.getSourceBlock();
block.updateAt_(n, newAt);
// This menu has been destroyed and replaced.
// Update the replacement.
@@ -862,7 +862,7 @@ Blockly.Constants.Text.TEXT_CHARAT_EXTENSION = function() {
dropdown.setValidator(function(value) {
var newAt = (value == 'FROM_START') || (value == 'FROM_END');
if (newAt != this.isAt_) {
var block = this.sourceBlock_;
var block = this.getSourceBlock();
block.updateAt_(newAt);
}
});