mirror of
https://github.com/google/blockly.git
synced 2026-01-11 10:57:07 +01:00
Added getSourceBlock function to field. (#2508)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user