Skip to content
6 changes: 3 additions & 3 deletions block-lexical-variables/src/blocks/lexical-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,10 @@ Blockly.Blocks['local_declaration_statement'] = {
newLocals[paramIndex] = newParamName;

// If there's an open mutator, change the name in the corresponding slot.
if (localDecl.mutator && localDecl.mutator.rootBlock_) {
if (localDecl.mutator && localDecl.mutator.rootBlock) {
// Iterate through mutatorarg param blocks and change name of one at
// paramIndex
const mutatorContainer = localDecl.mutator.rootBlock_;
const mutatorContainer = localDecl.mutator.rootBlock;
let mutatorargIndex = 0;
let mutatorarg = mutatorContainer.getInputTargetBlock('STACK');
while (mutatorarg && mutatorargIndex < paramIndex) {
Expand Down Expand Up @@ -585,7 +585,7 @@ Blockly.Blocks['local_declaration_statement'] = {
this.updateDeclarationInputs_(renamedLocalNames, initializerConnections);
// Update the mutator's variables if the mutator is open.
if (this.mutator && this.mutator.isVisible()) {
const blocks = this.mutator.workspace_.getAllBlocks();
const blocks = this.mutator.getWorkspace().getAllBlocks();
for (let x = 0, block; block = blocks[x]; x++) {
if (block.type == 'procedures_mutatorarg') {
const oldName = block.getFieldValue('NAME');
Expand Down
20 changes: 10 additions & 10 deletions block-lexical-variables/src/blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
// procedure arguments_ list rather than mutate that list, but I'd be
// wrong! Turns out that *not* mutating list here causes trouble below in
// the line
// Blockly.Field.prototype.setText.call(mutatorarg.getTitle_("NAME"),
// Blockly.Field.prototype.setValue.call(mutatorarg.getTitle_("NAME"),
// newParamName); The reason is that this fires a change event in
// mutator workspace, which causes a call to the proc decl compose()
// method, and when it detects a difference in the arguments it calls
Expand All @@ -291,10 +291,10 @@ Blockly.Blocks['procedures_defnoreturn'] = {

// 2. If there's an open mutator, change the name in the corresponding
// slot.
if (procDecl.mutator && procDecl.mutator.rootBlock_) {
if (procDecl.mutator && procDecl.mutator.rootBlock) {
// Iterate through mutatorarg param blocks and change name of one at
// paramIndex
const mutatorContainer = procDecl.mutator.rootBlock_;
const mutatorContainer = procDecl.mutator.rootBlock;
let mutatorargIndex = 0;
let mutatorarg = mutatorContainer.getInputTargetBlock('STACK');
while (mutatorarg && mutatorargIndex < paramIndex) {
Expand All @@ -307,13 +307,13 @@ Blockly.Blocks['procedures_defnoreturn'] = {
// will be invoked several times, and on one of those times, it will
// find new param name in the procedures arguments_ instance variable
// and will try to renumber it (e.g. "a" -> "a2"). To avoid this,
// invoke the setText method of its Field s superclass directly.
// invoke the setValue method of its Field superclass directly.
// I.e., can't do this:
// mutatorarg.getTitle_("NAME").setValue(newParamName); so instead do
// this:
mutatorarg.getField('NAME').setValue(newParamName);
// mutatorarg.getField("NAME").doValueUpdate_(newParamName);
// Blockly.Field.prototype.setText.call(mutatorarg.getField("NAME"),
// Blockly.Field.prototype.setValue.call(mutatorarg.getField("NAME"),
// newParamName);
}
}
Expand Down Expand Up @@ -470,7 +470,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
this.updateParams_(newParams);
// Update the mutator's variables if the mutator is open.
if (this.mutator.isVisible()) {
const blocks = this.mutator.workspace_.getAllBlocks();
const blocks = this.mutator.getWorkspace().getAllBlocks();
for (let x = 0, block; block = blocks[x]; x++) {
if (block.type == 'procedures_mutatorarg') {
const oldName = block.getFieldValue('NAME');
Expand Down Expand Up @@ -643,13 +643,13 @@ Blockly.Blocks['procedures_mutatorarg'] = {
LexicalVariable.renameParam);
// 2017 Blockly's text input change breaks our renaming behavior.
// The following is a version we've defined.
editor.onHtmlInputChange_ = function(e) {
editor.onHtmlInputChange = function(e) {
const oldValue = this.getValue();
FieldFlydown.prototype.onHtmlInputChange_.call(this, e);
FieldFlydown.prototype.onHtmlInputChange.call(this, e);
const newValue = this.getValue();
if (newValue && oldValue !== newValue && Blockly.Events.isEnabled()) {
Blockly.Events.fire(
new Blockly.Events.BlockChange(this.sourceBlock_, 'field', this.name,
new Blockly.Events.BlockChange(this.getSourceBlock(), 'field', this.name,
oldValue, newValue));
}
};
Expand Down Expand Up @@ -887,7 +887,7 @@ Blockly.Blocks['procedures_callnoreturn'] = {
if (quarkName in this.quarkConnections_) {
connection = this.quarkConnections_[quarkName];
if (!connection || connection.targetConnection ||
connection.sourceBlock_.workspace != this.workspace) {
connection.getSourceBlock().workspace != this.workspace) {
// Block no longer exists or has been attached elsewhere.
delete this.quarkConnections_[quarkName];
} else {
Expand Down
10 changes: 5 additions & 5 deletions block-lexical-variables/src/fields/field_flydown.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ FieldFlydown.prototype.flyoutCSSClassName =

FieldFlydown.prototype.onMouseOver_ = function(e) {
// [lyn, 10/22/13] No flydowns in a flyout!
if (!this.sourceBlock_.isInFlyout && FieldFlydown.showPid_ == 0) {
if (!this.getSourceBlock().isInFlyout && FieldFlydown.showPid_ == 0) {
FieldFlydown.showPid_ =
window.setTimeout(this.showFlydownMaker_(),
FieldFlydown.timeout);
Expand Down Expand Up @@ -250,13 +250,13 @@ function callAllValidators(field, text) {
// Override Blockly's behavior; they call the validator after setting the text,
// which is incompatible with how our validators work (we expect to be called
// before the change since in order to find the old references to be renamed).
FieldFlydown.prototype.onHtmlInputChange_ = function(e) {
FieldFlydown.prototype.onHtmlInputChange = function(e) {
const htmlInput = this.htmlInput_;
const text = htmlInput.value;
if (text !== htmlInput.oldValue_) {
htmlInput.oldValue_ = text;
let valid = true;
if (this.sourceBlock_) {
if (this.getSourceBlock()) {
valid = callAllValidators(this, htmlInput.value);
}
if (valid === null) {
Expand All @@ -268,15 +268,15 @@ FieldFlydown.prototype.onHtmlInputChange_ = function(e) {
} else if (Blockly.utils.userAgent.WEBKIT) {
// Cursor key. Render the source block to show the caret moving.
// Chrome only (version 26, OS X).
this.sourceBlock_.render();
this.getSourceBlock().render();
}

// We need all of the following to cause the field to resize!
this.textContent_.nodeValue = text;
this.forceRerender();
this.resizeEditor_();

Blockly.svgResize(this.sourceBlock_.workspace);
Blockly.svgResize(this.getSourceBlock().workspace);
};

/**
Expand Down
38 changes: 19 additions & 19 deletions block-lexical-variables/src/fields/field_lexical_variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ FieldLexicalVariable.getGlobalNames = function(optExcludedBlock) {
// Shared.showPrefixToUser is true, non-global names are prefixed with labels
// specified in blocklyeditor.js
FieldLexicalVariable.prototype.getNamesInScope = function() {
return FieldLexicalVariable.getNamesInScope(this.sourceBlock_);
return FieldLexicalVariable.getNamesInScope(this.getSourceBlock());
};

/**
Expand Down Expand Up @@ -372,29 +372,29 @@ FieldLexicalVariable.prototype.doValueUpdate_ = function(newValue) {
*/
FieldLexicalVariable.prototype.updateMutation = function() {
const text = this.getText();
if (this.sourceBlock_ && this.sourceBlock_.getParent()) {
this.sourceBlock_.eventparam = undefined;
if (this.getSourceBlock() && this.getSourceBlock().getParent()) {
this.getSourceBlock().eventparam = undefined;
if (text.indexOf(Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + ' ') === 0) {
this.sourceBlock_.eventparam = null;
this.getSourceBlock().eventparam = null;
this.translatedName = undefined;
this.varname = undefined;
return;
}
let i, parent = this.sourceBlock_.getParent();
let i, parent = this.getSourceBlock().getParent();
while (parent) {
const variables = parent.declaredVariables ? parent.declaredVariables() : [];
for (i = 0; i < variables.length; i++) {
if (variables[i] == text) {
if (parent.type == 'component_event') {
// Innermost scope is an event block, so eventparam can be set.
const codeName = parent.getParameters()[i].name;
this.sourceBlock_.eventparam = codeName;
this.getSourceBlock().eventparam = codeName;
this.translatedName = variables[i];
this.varname = codeName;
return;
} else {
// Innermost scope is not an event, so eventparam can be nulled.
this.sourceBlock_.eventparam = null;
this.getSourceBlock().eventparam = null;
this.translatedName = undefined;
this.varname = undefined;
return;
Expand Down Expand Up @@ -422,12 +422,12 @@ FieldLexicalVariable.prototype.getOptions = function(opt_useCache,
}
const extraOption = opt_extraOption || [];
if (this.isOptionListDynamic()) {
if (!this.generatedOptions_ || !opt_useCache) {
this.generatedOptions_ =
if (!this.generatedOptions || !opt_useCache) {
this.generatedOptions =
this.menuGenerator_.call(this).concat(extraOption);
validateOptions(this.generatedOptions_);
validateOptions(this.generatedOptions);
}
return this.generatedOptions_.concat(extraOption);
return this.generatedOptions.concat(extraOption);
}
return /** @type {!Array<!Array<string>>} */ (this.menuGenerator_);
};
Expand Down Expand Up @@ -488,9 +488,9 @@ const validateOptions = function(options) {
FieldLexicalVariable.dropdownChange = function(text) {
if (text) {
this.doValueUpdate_(text);
const topWorkspace = this.sourceBlock_.workspace.getTopWorkspace();
const topWorkspace = this.getSourceBlock().workspace.getTopWorkspace();
if (topWorkspace.getWarningHandler) {
topWorkspace.getWarningHandler().checkErrors(this.sourceBlock_);
topWorkspace.getWarningHandler().checkErrors(this.getSourceBlock());
}
}
// window.setTimeout(Blockly.Variables.refreshFlyoutCategory, 1);
Expand Down Expand Up @@ -610,13 +610,13 @@ LexicalVariable.renameGlobal = function(newName) {
// [lyn, 10/27/13] now check legality of identifiers
newName = LexicalVariable.makeLegalIdentifier(newName);

this.sourceBlock_.getField('NAME').doValueUpdate_(newName);
this.getSourceBlock().getField('NAME').doValueUpdate_(newName);

const globals = FieldLexicalVariable.getGlobalNames(this.sourceBlock_);
// this.sourceBlock excludes block being renamed from consideration
const globals = FieldLexicalVariable.getGlobalNames(this.getSourceBlock());
// this.getSourceBlock excludes block being renamed from consideration
// Potentially rename declaration against other occurrences
newName = FieldLexicalVariable.nameNotIn(newName, globals);
if (this.sourceBlock_.rendered) {
if (this.getSourceBlock().rendered) {
// Rename getters and setters
if (Blockly.common.getMainWorkspace()) {
const blocks = Blockly.common.getMainWorkspace().getAllBlocks();
Expand Down Expand Up @@ -675,10 +675,10 @@ LexicalVariable.renameParam = function(newName) {
// Default behavior consistent with previous behavior is to use "false" for
// last argument -- I.e., will not rename inner declarations, but may rename
// newName
return LexicalVariable.renameParamFromTo(this.sourceBlock_, oldName,
return LexicalVariable.renameParamFromTo(this.getSourceBlock(), oldName,
newName, false);
// Default should be false (as above), but can also play with true:
// return LexicalVariable.renameParamFromTo(this.sourceBlock_,
// return LexicalVariable.renameParamFromTo(this.getSourceBlock(),
// oldName, newName, true);
};

Expand Down
16 changes: 8 additions & 8 deletions block-lexical-variables/src/fields/field_procedurename.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ export class FieldProcedureName extends Blockly.FieldTextInput {
this.oldName_ = oldValue;
this.doValueUpdate_(newValue);
super.setValue(newValue);
if (this.sourceBlock_ && this.sourceBlock_.isInFlyout) {
if (this.getSourceBlock() && this.getSourceBlock().isInFlyout) {
// Do not take action for blocks in flyouts
return;
}
newValue = this.getValue();
if (typeof newValue === 'string' && this.sourceBlock_) {
const procDb = this.sourceBlock_.workspace.getProcedureDatabase();
if (typeof newValue === 'string' && this.getSourceBlock()) {
const procDb = this.getSourceBlock().workspace.getProcedureDatabase();
if (procDb) {
if (procDb.getProcedure(this.sourceBlock_.id)) {
procDb.renameProcedure(this.sourceBlock_.id, oldValue, newValue);
if (procDb.getProcedure(this.getSourceBlock().id)) {
procDb.renameProcedure(this.getSourceBlock().id, oldValue, newValue);
} else {
procDb.addProcedure(newValue, this.sourceBlock_);
procDb.addProcedure(newValue, this.getSourceBlock());
}
}
}
Expand All @@ -58,13 +58,13 @@ export class FieldProcedureName extends Blockly.FieldTextInput {
}

/*
FieldProcedureName.prototype.onHtmlInputChange_ = function(e) {
FieldProcedureName.prototype.onHtmlInputChange = function(e) {
if (e.type == 'keypress') {
console.log('Suppressed keypress event');
return; // suppress change handling on key press
}
console.log("input's value is " + Blockly.FieldTextInput.htmlInput_.value);
FieldProcedureName.superClass_.onHtmlInputChange_.call(this, e);
FieldProcedureName.superClass_.onHtmlInputChange.call(this, e);
};
*/

Expand Down
6 changes: 3 additions & 3 deletions block-lexical-variables/src/fields/flydown.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ Flydown.prototype.placeNewBlock_ = function(originBlock) {
xyNew.y +=
targetWorkspace.scrollY / targetWorkspace.scale - targetWorkspace.scrollY;
// If the flyout is collapsible and the workspace can't be scrolled.
if (targetWorkspace.toolbox_ && !targetWorkspace.scrollbar) {
xyNew.x += targetWorkspace.toolbox_.getWidth() / targetWorkspace.scale;
xyNew.y += targetWorkspace.toolbox_.getHeight() / targetWorkspace.scale;
if (targetWorkspace.getToolbox() && !targetWorkspace.scrollbar) {
xyNew.x += targetWorkspace.getToolbox().getWidth() / targetWorkspace.scale;
xyNew.y += targetWorkspace.getToolbox().getHeight() / targetWorkspace.scale;
}

// Move the new block to where the old block is.
Expand Down
7 changes: 3 additions & 4 deletions block-lexical-variables/src/procedure_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const procDefaultValue = ['', ''];

export const onChange = function(procedureId) {
let workspace = this.block.workspace.getTopWorkspace();
// [lyn, 10/14/13] .editable is undefined on blocks. Changed to .editable_
if (!this.block.isEditable()) {
return;
}
Expand Down Expand Up @@ -136,7 +135,7 @@ export const removeProcedureValues = function(name, workspace) {
* @return {string} The new, validated name of the block.
*/
export const renameProcedure = function(newName) {
if (this.sourceBlock_ && this.sourceBlock_.isInFlyout) {
if (this.getSourceBlock() && this.getSourceBlock().isInFlyout) {
// Do not rename procedures in flyouts
return newName;
}
Expand All @@ -149,7 +148,7 @@ export const renameProcedure = function(newName) {

// [lyn, 10/28/13] Prevent two procedures from having the same name.
const procBlocks = getAllProcedureDeclarationBlocksExcept(
this.sourceBlock_);
this.getSourceBlock());
const procNames = procBlocks.map(function(decl) {
return decl.getFieldValue('NAME');
});
Expand All @@ -158,7 +157,7 @@ export const renameProcedure = function(newName) {
this.doValueUpdate_(newName);
}
// Rename any callers.
const blocks = this.sourceBlock_.workspace.getAllBlocks();
const blocks = this.getSourceBlock().workspace.getAllBlocks();
for (let x = 0; x < blocks.length; x++) {
const func = blocks[x].renameProcedure;
if (func) {
Expand Down
10 changes: 5 additions & 5 deletions block-lexical-variables/src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import './msg.js';
* @return {boolean}
*/
export const InstantInTime = function(myConn, otherConn) {
if (!myConn.sourceBlock_.rendered ||
!otherConn.sourceBlock_.rendered) {
if (otherConn.check_ && !otherConn.check_.includes('InstantInTime')) {
otherConn.sourceBlock_.badBlock();
if (!myConn.getSourceBlock().rendered ||
!otherConn.getSourceBlock().rendered) {
if (otherConn.getCheck() && !otherConn.getCheck().includes('InstantInTime')) {
otherConn.getSourceBlock().badBlock();
}
return true;
}
return !otherConn.check_ || otherConn.check_.includes('InstantInTime');
return !otherConn.getCheck() || otherConn.getCheck().includes('InstantInTime');
};


Expand Down
2 changes: 1 addition & 1 deletion block-lexical-variables/src/warningHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class ErrorCheckers {

for (let i=0; i<params.dropDowns.length; i++) {
const dropDown = block.getField(params.dropDowns[i]);
const dropDownList = dropDown.menuGenerator_();
const dropDownList = dropDown.getOptions(false);
const text = dropDown.getText();
const value = dropDown.getValue();
let textInDropDown = false;
Expand Down