mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -250,7 +250,7 @@ Blockly.DropDownDiv.showPositionedByField = function(owner,
|
||||
// Set bounds to workspace; show the drop-down.
|
||||
Blockly.DropDownDiv.positionToField_ = true;
|
||||
Blockly.DropDownDiv.setBoundsElement(
|
||||
owner.sourceBlock_.workspace.getParentSvg().parentNode);
|
||||
owner.getSourceBlock().workspace.getParentSvg().parentNode);
|
||||
return Blockly.DropDownDiv.show(
|
||||
owner, primaryX, primaryY, secondaryX, secondaryY, opt_onHide);
|
||||
};
|
||||
@@ -514,7 +514,7 @@ Blockly.DropDownDiv.repositionForWindowResize = function() {
|
||||
// when a field is focused, the soft keyboard opens triggering a window resize
|
||||
// event and we want the dropdown div to stick around so users can type into it.
|
||||
if (Blockly.DropDownDiv.owner_) {
|
||||
var block = Blockly.DropDownDiv.owner_.sourceBlock_;
|
||||
var block = Blockly.DropDownDiv.owner_.getSourceBlock();
|
||||
var scale = block.workspace.scale;
|
||||
var bBox = {
|
||||
width: Blockly.DropDownDiv.positionToField_ ?
|
||||
|
||||
@@ -211,6 +211,14 @@ Blockly.Field.prototype.setSourceBlock = function(block) {
|
||||
this.sourceBlock_ = block;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the block this field is attached to.
|
||||
* @return {Blockly.Block} The block containing this field.
|
||||
*/
|
||||
Blockly.Field.prototype.getSourceBlock = function() {
|
||||
return this.sourceBlock_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize everything to render this field. Override
|
||||
* methods initModel and initView rather than this method.
|
||||
|
||||
@@ -163,11 +163,11 @@ Blockly.Procedures.rename = function(name) {
|
||||
name = name.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '');
|
||||
|
||||
// Ensure two identically-named procedures don't exist.
|
||||
var legalName = Blockly.Procedures.findLegalName(name, this.sourceBlock_);
|
||||
var legalName = Blockly.Procedures.findLegalName(name, this.getSourceBlock());
|
||||
var oldName = this.text_;
|
||||
if (oldName != name && oldName != legalName) {
|
||||
// Rename any callers.
|
||||
var blocks = this.sourceBlock_.workspace.getAllBlocks(false);
|
||||
var blocks = this.getSourceBlock().workspace.getAllBlocks(false);
|
||||
for (var i = 0; i < blocks.length; i++) {
|
||||
if (blocks[i].renameProcedure) {
|
||||
blocks[i].renameProcedure(oldName, legalName);
|
||||
|
||||
@@ -46,9 +46,9 @@ Blockly.Blocks['factory_base'] = {
|
||||
['↑ top connection', 'TOP'],
|
||||
['↓ bottom connection', 'BOTTOM']],
|
||||
function(option) {
|
||||
this.sourceBlock_.updateShape_(option);
|
||||
this.getSourceBlock().updateShape_(option);
|
||||
// Connect a shadow block to this new input.
|
||||
this.sourceBlock_.spawnOutputShadow_(option);
|
||||
this.getSourceBlock().spawnOutputShadow_(option);
|
||||
});
|
||||
this.appendDummyInput()
|
||||
.appendField(dropdown, 'CONNECTIONS');
|
||||
@@ -863,7 +863,7 @@ Blockly.Blocks['colour_hue'] = {
|
||||
// Update the current block's colour to match.
|
||||
var hue = parseInt(text, 10);
|
||||
if (!isNaN(hue)) {
|
||||
this.sourceBlock_.setColour(hue);
|
||||
this.getSourceBlock().setColour(hue);
|
||||
}
|
||||
},
|
||||
mutationToDom: function(workspace) {
|
||||
|
||||
Reference in New Issue
Block a user