diff --git a/block-lexical-variables/src/blocks/lexical-variables.js b/block-lexical-variables/src/blocks/lexical-variables.js index dfa6904..84616a4 100644 --- a/block-lexical-variables/src/blocks/lexical-variables.js +++ b/block-lexical-variables/src/blocks/lexical-variables.js @@ -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) { @@ -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'); diff --git a/block-lexical-variables/src/blocks/procedures.js b/block-lexical-variables/src/blocks/procedures.js index 21d7a83..a1d7eb7 100644 --- a/block-lexical-variables/src/blocks/procedures.js +++ b/block-lexical-variables/src/blocks/procedures.js @@ -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 @@ -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) { @@ -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); } } @@ -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'); @@ -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)); } }; @@ -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 { diff --git a/block-lexical-variables/src/fields/field_flydown.js b/block-lexical-variables/src/fields/field_flydown.js index 2557b21..da88829 100644 --- a/block-lexical-variables/src/fields/field_flydown.js +++ b/block-lexical-variables/src/fields/field_flydown.js @@ -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); @@ -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) { @@ -268,7 +268,7 @@ 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! @@ -276,7 +276,7 @@ FieldFlydown.prototype.onHtmlInputChange_ = function(e) { this.forceRerender(); this.resizeEditor_(); - Blockly.svgResize(this.sourceBlock_.workspace); + Blockly.svgResize(this.getSourceBlock().workspace); }; /** diff --git a/block-lexical-variables/src/fields/field_lexical_variable.js b/block-lexical-variables/src/fields/field_lexical_variable.js index 77714fe..613ba4e 100644 --- a/block-lexical-variables/src/fields/field_lexical_variable.js +++ b/block-lexical-variables/src/fields/field_lexical_variable.js @@ -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()); }; /** @@ -372,15 +372,15 @@ 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++) { @@ -388,13 +388,13 @@ FieldLexicalVariable.prototype.updateMutation = function() { 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; @@ -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>} */ (this.menuGenerator_); }; @@ -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); @@ -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(); @@ -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); }; diff --git a/block-lexical-variables/src/fields/field_procedurename.js b/block-lexical-variables/src/fields/field_procedurename.js index 2a725df..27b3bc5 100644 --- a/block-lexical-variables/src/fields/field_procedurename.js +++ b/block-lexical-variables/src/fields/field_procedurename.js @@ -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()); } } } @@ -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); }; */ diff --git a/block-lexical-variables/src/fields/flydown.js b/block-lexical-variables/src/fields/flydown.js index 7d8f699..a2707ff 100644 --- a/block-lexical-variables/src/fields/flydown.js +++ b/block-lexical-variables/src/fields/flydown.js @@ -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. diff --git a/block-lexical-variables/src/procedure_utils.js b/block-lexical-variables/src/procedure_utils.js index 7c5d174..2a493e5 100644 --- a/block-lexical-variables/src/procedure_utils.js +++ b/block-lexical-variables/src/procedure_utils.js @@ -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; } @@ -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; } @@ -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'); }); @@ -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) { diff --git a/block-lexical-variables/src/utilities.js b/block-lexical-variables/src/utilities.js index 7ea76a7..d0c6afc 100644 --- a/block-lexical-variables/src/utilities.js +++ b/block-lexical-variables/src/utilities.js @@ -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'); }; diff --git a/block-lexical-variables/src/warningHandler.js b/block-lexical-variables/src/warningHandler.js index be6d585..c27f212 100644 --- a/block-lexical-variables/src/warningHandler.js +++ b/block-lexical-variables/src/warningHandler.js @@ -123,7 +123,7 @@ export class ErrorCheckers { for (let i=0; i