Skip to content

Commit 62b3583

Browse files
authored
Update to Blockly 11 (#81)
* Change Field setText() to setValue() RaspberryPiFoundation/blockly@520aa60#diff-c31ad3fa2aed6dafcf75d583f81f27b4349b02e43e84efdf900f124ab61ddaf0L821-L834 * Change Connection check_ to getCheck() RaspberryPiFoundation/blockly@85013f8#diff-dd85563e074ebb74e4c34eee01568971430f3cb7a6b846feef8044ad8d5dcd61L54-R54 https://github.com/google/blockly/blob/blockly-v11.2.2/core/connection.ts#L428 * Change FieldDropdown generatedOptions_ to generatedOptions RaspberryPiFoundation/blockly@c458d63#diff-af2458fcf0c5427418a18bfcc195a5f27fb6177b212fdc523f31c077819035f1L75-R75 https://github.com/google/blockly/blob/blockly-v11.2.2/core/field_dropdown.ts#L403 * Change FieldDropdown menuGenerator_() to getOptions() https://github.com/google/blockly/blob/blockly-v11.2.2/core/field_dropdown.ts#L403 * Change FieldInput onHtmlInputChange_ to onHtmlInputChange RaspberryPiFoundation/blockly@61bbd7d#diff-6e809b7c830fc095183f413ca9bf0b89fdaeaffa92c189d758597b368ff1b1a1L577-R577 * Change MutatorIcon rootBlock_ to rootBlock RaspberryPiFoundation/blockly@f95af36#diff-7eb8337e1180eb397247bb8e8f91ac5f1d94e06d6518261ff71d28f664b0bef9L66-R66 * Change Connection sourceBlock_ to getSourceBlock() https://github.com/google/blockly/blob/blockly-v11.2.2/core/connection.ts#L177 * Change Field sourceBlock_ to getSourceBlock() https://github.com/google/blockly/blob/blockly-v11.2.2/core/field.ts#L291 * Change WorkspaceSvg toolbox_ to getToolbox() RaspberryPiFoundation/blockly@61bbd7d#diff-5175ae7b6cd103f9910b04fab3e7c4b2007b60078a396af66e63a6e8c63e6aceL209-R212 https://github.com/google/blockly/blob/blockly-v11.2.2/core/workspace_svg.ts#L1009 * Change Mutator workspace_ to getWorkspace() RaspberryPiFoundation/blockly@2f74ce8#diff-7eb8337e1180eb397247bb8e8f91ac5f1d94e06d6518261ff71d28f664b0bef9L48 RaspberryPiFoundation/blockly@2f74ce8#diff-aeb28553e3f549c3f6fcdeb09b161c70732f73df152f7e7dccd36fe535fc49f0R311 * Remove outdated comment
1 parent 186c4c9 commit 62b3583

9 files changed

Lines changed: 57 additions & 58 deletions

File tree

block-lexical-variables/src/blocks/lexical-variables.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,10 @@ Blockly.Blocks['local_declaration_statement'] = {
457457
newLocals[paramIndex] = newParamName;
458458

459459
// If there's an open mutator, change the name in the corresponding slot.
460-
if (localDecl.mutator && localDecl.mutator.rootBlock_) {
460+
if (localDecl.mutator && localDecl.mutator.rootBlock) {
461461
// Iterate through mutatorarg param blocks and change name of one at
462462
// paramIndex
463-
const mutatorContainer = localDecl.mutator.rootBlock_;
463+
const mutatorContainer = localDecl.mutator.rootBlock;
464464
let mutatorargIndex = 0;
465465
let mutatorarg = mutatorContainer.getInputTargetBlock('STACK');
466466
while (mutatorarg && mutatorargIndex < paramIndex) {
@@ -585,7 +585,7 @@ Blockly.Blocks['local_declaration_statement'] = {
585585
this.updateDeclarationInputs_(renamedLocalNames, initializerConnections);
586586
// Update the mutator's variables if the mutator is open.
587587
if (this.mutator && this.mutator.isVisible()) {
588-
const blocks = this.mutator.workspace_.getAllBlocks();
588+
const blocks = this.mutator.getWorkspace().getAllBlocks();
589589
for (let x = 0, block; block = blocks[x]; x++) {
590590
if (block.type == 'procedures_mutatorarg') {
591591
const oldName = block.getFieldValue('NAME');

block-lexical-variables/src/blocks/procedures.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
267267
// procedure arguments_ list rather than mutate that list, but I'd be
268268
// wrong! Turns out that *not* mutating list here causes trouble below in
269269
// the line
270-
// Blockly.Field.prototype.setText.call(mutatorarg.getTitle_("NAME"),
270+
// Blockly.Field.prototype.setValue.call(mutatorarg.getTitle_("NAME"),
271271
// newParamName); The reason is that this fires a change event in
272272
// mutator workspace, which causes a call to the proc decl compose()
273273
// method, and when it detects a difference in the arguments it calls
@@ -291,10 +291,10 @@ Blockly.Blocks['procedures_defnoreturn'] = {
291291

292292
// 2. If there's an open mutator, change the name in the corresponding
293293
// slot.
294-
if (procDecl.mutator && procDecl.mutator.rootBlock_) {
294+
if (procDecl.mutator && procDecl.mutator.rootBlock) {
295295
// Iterate through mutatorarg param blocks and change name of one at
296296
// paramIndex
297-
const mutatorContainer = procDecl.mutator.rootBlock_;
297+
const mutatorContainer = procDecl.mutator.rootBlock;
298298
let mutatorargIndex = 0;
299299
let mutatorarg = mutatorContainer.getInputTargetBlock('STACK');
300300
while (mutatorarg && mutatorargIndex < paramIndex) {
@@ -307,13 +307,13 @@ Blockly.Blocks['procedures_defnoreturn'] = {
307307
// will be invoked several times, and on one of those times, it will
308308
// find new param name in the procedures arguments_ instance variable
309309
// and will try to renumber it (e.g. "a" -> "a2"). To avoid this,
310-
// invoke the setText method of its Field s superclass directly.
310+
// invoke the setValue method of its Field superclass directly.
311311
// I.e., can't do this:
312312
// mutatorarg.getTitle_("NAME").setValue(newParamName); so instead do
313313
// this:
314314
mutatorarg.getField('NAME').setValue(newParamName);
315315
// mutatorarg.getField("NAME").doValueUpdate_(newParamName);
316-
// Blockly.Field.prototype.setText.call(mutatorarg.getField("NAME"),
316+
// Blockly.Field.prototype.setValue.call(mutatorarg.getField("NAME"),
317317
// newParamName);
318318
}
319319
}
@@ -470,7 +470,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
470470
this.updateParams_(newParams);
471471
// Update the mutator's variables if the mutator is open.
472472
if (this.mutator.isVisible()) {
473-
const blocks = this.mutator.workspace_.getAllBlocks();
473+
const blocks = this.mutator.getWorkspace().getAllBlocks();
474474
for (let x = 0, block; block = blocks[x]; x++) {
475475
if (block.type == 'procedures_mutatorarg') {
476476
const oldName = block.getFieldValue('NAME');
@@ -643,13 +643,13 @@ Blockly.Blocks['procedures_mutatorarg'] = {
643643
LexicalVariable.renameParam);
644644
// 2017 Blockly's text input change breaks our renaming behavior.
645645
// The following is a version we've defined.
646-
editor.onHtmlInputChange_ = function(e) {
646+
editor.onHtmlInputChange = function(e) {
647647
const oldValue = this.getValue();
648-
FieldFlydown.prototype.onHtmlInputChange_.call(this, e);
648+
FieldFlydown.prototype.onHtmlInputChange.call(this, e);
649649
const newValue = this.getValue();
650650
if (newValue && oldValue !== newValue && Blockly.Events.isEnabled()) {
651651
Blockly.Events.fire(
652-
new Blockly.Events.BlockChange(this.sourceBlock_, 'field', this.name,
652+
new Blockly.Events.BlockChange(this.getSourceBlock(), 'field', this.name,
653653
oldValue, newValue));
654654
}
655655
};
@@ -887,7 +887,7 @@ Blockly.Blocks['procedures_callnoreturn'] = {
887887
if (quarkName in this.quarkConnections_) {
888888
connection = this.quarkConnections_[quarkName];
889889
if (!connection || connection.targetConnection ||
890-
connection.sourceBlock_.workspace != this.workspace) {
890+
connection.getSourceBlock().workspace != this.workspace) {
891891
// Block no longer exists or has been attached elsewhere.
892892
delete this.quarkConnections_[quarkName];
893893
} else {

block-lexical-variables/src/fields/field_flydown.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ FieldFlydown.prototype.flyoutCSSClassName =
123123

124124
FieldFlydown.prototype.onMouseOver_ = function(e) {
125125
// [lyn, 10/22/13] No flydowns in a flyout!
126-
if (!this.sourceBlock_.isInFlyout && FieldFlydown.showPid_ == 0) {
126+
if (!this.getSourceBlock().isInFlyout && FieldFlydown.showPid_ == 0) {
127127
FieldFlydown.showPid_ =
128128
window.setTimeout(this.showFlydownMaker_(),
129129
FieldFlydown.timeout);
@@ -250,13 +250,13 @@ function callAllValidators(field, text) {
250250
// Override Blockly's behavior; they call the validator after setting the text,
251251
// which is incompatible with how our validators work (we expect to be called
252252
// before the change since in order to find the old references to be renamed).
253-
FieldFlydown.prototype.onHtmlInputChange_ = function(e) {
253+
FieldFlydown.prototype.onHtmlInputChange = function(e) {
254254
const htmlInput = this.htmlInput_;
255255
const text = htmlInput.value;
256256
if (text !== htmlInput.oldValue_) {
257257
htmlInput.oldValue_ = text;
258258
let valid = true;
259-
if (this.sourceBlock_) {
259+
if (this.getSourceBlock()) {
260260
valid = callAllValidators(this, htmlInput.value);
261261
}
262262
if (valid === null) {
@@ -268,15 +268,15 @@ FieldFlydown.prototype.onHtmlInputChange_ = function(e) {
268268
} else if (Blockly.utils.userAgent.WEBKIT) {
269269
// Cursor key. Render the source block to show the caret moving.
270270
// Chrome only (version 26, OS X).
271-
this.sourceBlock_.render();
271+
this.getSourceBlock().render();
272272
}
273273

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

279-
Blockly.svgResize(this.sourceBlock_.workspace);
279+
Blockly.svgResize(this.getSourceBlock().workspace);
280280
};
281281

282282
/**

block-lexical-variables/src/fields/field_lexical_variable.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ FieldLexicalVariable.getGlobalNames = function(optExcludedBlock) {
191191
// Shared.showPrefixToUser is true, non-global names are prefixed with labels
192192
// specified in blocklyeditor.js
193193
FieldLexicalVariable.prototype.getNamesInScope = function() {
194-
return FieldLexicalVariable.getNamesInScope(this.sourceBlock_);
194+
return FieldLexicalVariable.getNamesInScope(this.getSourceBlock());
195195
};
196196

197197
/**
@@ -372,29 +372,29 @@ FieldLexicalVariable.prototype.doValueUpdate_ = function(newValue) {
372372
*/
373373
FieldLexicalVariable.prototype.updateMutation = function() {
374374
const text = this.getText();
375-
if (this.sourceBlock_ && this.sourceBlock_.getParent()) {
376-
this.sourceBlock_.eventparam = undefined;
375+
if (this.getSourceBlock() && this.getSourceBlock().getParent()) {
376+
this.getSourceBlock().eventparam = undefined;
377377
if (text.indexOf(Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + ' ') === 0) {
378-
this.sourceBlock_.eventparam = null;
378+
this.getSourceBlock().eventparam = null;
379379
this.translatedName = undefined;
380380
this.varname = undefined;
381381
return;
382382
}
383-
let i, parent = this.sourceBlock_.getParent();
383+
let i, parent = this.getSourceBlock().getParent();
384384
while (parent) {
385385
const variables = parent.declaredVariables ? parent.declaredVariables() : [];
386386
for (i = 0; i < variables.length; i++) {
387387
if (variables[i] == text) {
388388
if (parent.type == 'component_event') {
389389
// Innermost scope is an event block, so eventparam can be set.
390390
const codeName = parent.getParameters()[i].name;
391-
this.sourceBlock_.eventparam = codeName;
391+
this.getSourceBlock().eventparam = codeName;
392392
this.translatedName = variables[i];
393393
this.varname = codeName;
394394
return;
395395
} else {
396396
// Innermost scope is not an event, so eventparam can be nulled.
397-
this.sourceBlock_.eventparam = null;
397+
this.getSourceBlock().eventparam = null;
398398
this.translatedName = undefined;
399399
this.varname = undefined;
400400
return;
@@ -422,12 +422,12 @@ FieldLexicalVariable.prototype.getOptions = function(opt_useCache,
422422
}
423423
const extraOption = opt_extraOption || [];
424424
if (this.isOptionListDynamic()) {
425-
if (!this.generatedOptions_ || !opt_useCache) {
426-
this.generatedOptions_ =
425+
if (!this.generatedOptions || !opt_useCache) {
426+
this.generatedOptions =
427427
this.menuGenerator_.call(this).concat(extraOption);
428-
validateOptions(this.generatedOptions_);
428+
validateOptions(this.generatedOptions);
429429
}
430-
return this.generatedOptions_.concat(extraOption);
430+
return this.generatedOptions.concat(extraOption);
431431
}
432432
return /** @type {!Array<!Array<string>>} */ (this.menuGenerator_);
433433
};
@@ -488,9 +488,9 @@ const validateOptions = function(options) {
488488
FieldLexicalVariable.dropdownChange = function(text) {
489489
if (text) {
490490
this.doValueUpdate_(text);
491-
const topWorkspace = this.sourceBlock_.workspace.getTopWorkspace();
491+
const topWorkspace = this.getSourceBlock().workspace.getTopWorkspace();
492492
if (topWorkspace.getWarningHandler) {
493-
topWorkspace.getWarningHandler().checkErrors(this.sourceBlock_);
493+
topWorkspace.getWarningHandler().checkErrors(this.getSourceBlock());
494494
}
495495
}
496496
// window.setTimeout(Blockly.Variables.refreshFlyoutCategory, 1);
@@ -610,13 +610,13 @@ LexicalVariable.renameGlobal = function(newName) {
610610
// [lyn, 10/27/13] now check legality of identifiers
611611
newName = LexicalVariable.makeLegalIdentifier(newName);
612612

613-
this.sourceBlock_.getField('NAME').doValueUpdate_(newName);
613+
this.getSourceBlock().getField('NAME').doValueUpdate_(newName);
614614

615-
const globals = FieldLexicalVariable.getGlobalNames(this.sourceBlock_);
616-
// this.sourceBlock excludes block being renamed from consideration
615+
const globals = FieldLexicalVariable.getGlobalNames(this.getSourceBlock());
616+
// this.getSourceBlock excludes block being renamed from consideration
617617
// Potentially rename declaration against other occurrences
618618
newName = FieldLexicalVariable.nameNotIn(newName, globals);
619-
if (this.sourceBlock_.rendered) {
619+
if (this.getSourceBlock().rendered) {
620620
// Rename getters and setters
621621
if (Blockly.common.getMainWorkspace()) {
622622
const blocks = Blockly.common.getMainWorkspace().getAllBlocks();
@@ -675,10 +675,10 @@ LexicalVariable.renameParam = function(newName) {
675675
// Default behavior consistent with previous behavior is to use "false" for
676676
// last argument -- I.e., will not rename inner declarations, but may rename
677677
// newName
678-
return LexicalVariable.renameParamFromTo(this.sourceBlock_, oldName,
678+
return LexicalVariable.renameParamFromTo(this.getSourceBlock(), oldName,
679679
newName, false);
680680
// Default should be false (as above), but can also play with true:
681-
// return LexicalVariable.renameParamFromTo(this.sourceBlock_,
681+
// return LexicalVariable.renameParamFromTo(this.getSourceBlock(),
682682
// oldName, newName, true);
683683
};
684684

block-lexical-variables/src/fields/field_procedurename.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ export class FieldProcedureName extends Blockly.FieldTextInput {
3737
this.oldName_ = oldValue;
3838
this.doValueUpdate_(newValue);
3939
super.setValue(newValue);
40-
if (this.sourceBlock_ && this.sourceBlock_.isInFlyout) {
40+
if (this.getSourceBlock() && this.getSourceBlock().isInFlyout) {
4141
// Do not take action for blocks in flyouts
4242
return;
4343
}
4444
newValue = this.getValue();
45-
if (typeof newValue === 'string' && this.sourceBlock_) {
46-
const procDb = this.sourceBlock_.workspace.getProcedureDatabase();
45+
if (typeof newValue === 'string' && this.getSourceBlock()) {
46+
const procDb = this.getSourceBlock().workspace.getProcedureDatabase();
4747
if (procDb) {
48-
if (procDb.getProcedure(this.sourceBlock_.id)) {
49-
procDb.renameProcedure(this.sourceBlock_.id, oldValue, newValue);
48+
if (procDb.getProcedure(this.getSourceBlock().id)) {
49+
procDb.renameProcedure(this.getSourceBlock().id, oldValue, newValue);
5050
} else {
51-
procDb.addProcedure(newValue, this.sourceBlock_);
51+
procDb.addProcedure(newValue, this.getSourceBlock());
5252
}
5353
}
5454
}
@@ -58,13 +58,13 @@ export class FieldProcedureName extends Blockly.FieldTextInput {
5858
}
5959

6060
/*
61-
FieldProcedureName.prototype.onHtmlInputChange_ = function(e) {
61+
FieldProcedureName.prototype.onHtmlInputChange = function(e) {
6262
if (e.type == 'keypress') {
6363
console.log('Suppressed keypress event');
6464
return; // suppress change handling on key press
6565
}
6666
console.log("input's value is " + Blockly.FieldTextInput.htmlInput_.value);
67-
FieldProcedureName.superClass_.onHtmlInputChange_.call(this, e);
67+
FieldProcedureName.superClass_.onHtmlInputChange.call(this, e);
6868
};
6969
*/
7070

block-lexical-variables/src/fields/flydown.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ Flydown.prototype.placeNewBlock_ = function(originBlock) {
234234
xyNew.y +=
235235
targetWorkspace.scrollY / targetWorkspace.scale - targetWorkspace.scrollY;
236236
// If the flyout is collapsible and the workspace can't be scrolled.
237-
if (targetWorkspace.toolbox_ && !targetWorkspace.scrollbar) {
238-
xyNew.x += targetWorkspace.toolbox_.getWidth() / targetWorkspace.scale;
239-
xyNew.y += targetWorkspace.toolbox_.getHeight() / targetWorkspace.scale;
237+
if (targetWorkspace.getToolbox() && !targetWorkspace.scrollbar) {
238+
xyNew.x += targetWorkspace.getToolbox().getWidth() / targetWorkspace.scale;
239+
xyNew.y += targetWorkspace.getToolbox().getHeight() / targetWorkspace.scale;
240240
}
241241

242242
// Move the new block to where the old block is.

block-lexical-variables/src/procedure_utils.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const procDefaultValue = ['', ''];
2323

2424
export const onChange = function(procedureId) {
2525
let workspace = this.block.workspace.getTopWorkspace();
26-
// [lyn, 10/14/13] .editable is undefined on blocks. Changed to .editable_
2726
if (!this.block.isEditable()) {
2827
return;
2928
}
@@ -136,7 +135,7 @@ export const removeProcedureValues = function(name, workspace) {
136135
* @return {string} The new, validated name of the block.
137136
*/
138137
export const renameProcedure = function(newName) {
139-
if (this.sourceBlock_ && this.sourceBlock_.isInFlyout) {
138+
if (this.getSourceBlock() && this.getSourceBlock().isInFlyout) {
140139
// Do not rename procedures in flyouts
141140
return newName;
142141
}
@@ -149,7 +148,7 @@ export const renameProcedure = function(newName) {
149148

150149
// [lyn, 10/28/13] Prevent two procedures from having the same name.
151150
const procBlocks = getAllProcedureDeclarationBlocksExcept(
152-
this.sourceBlock_);
151+
this.getSourceBlock());
153152
const procNames = procBlocks.map(function(decl) {
154153
return decl.getFieldValue('NAME');
155154
});
@@ -158,7 +157,7 @@ export const renameProcedure = function(newName) {
158157
this.doValueUpdate_(newName);
159158
}
160159
// Rename any callers.
161-
const blocks = this.sourceBlock_.workspace.getAllBlocks();
160+
const blocks = this.getSourceBlock().workspace.getAllBlocks();
162161
for (let x = 0; x < blocks.length; x++) {
163162
const func = blocks[x].renameProcedure;
164163
if (func) {

block-lexical-variables/src/utilities.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import './msg.js';
2222
* @return {boolean}
2323
*/
2424
export const InstantInTime = function(myConn, otherConn) {
25-
if (!myConn.sourceBlock_.rendered ||
26-
!otherConn.sourceBlock_.rendered) {
27-
if (otherConn.check_ && !otherConn.check_.includes('InstantInTime')) {
28-
otherConn.sourceBlock_.badBlock();
25+
if (!myConn.getSourceBlock().rendered ||
26+
!otherConn.getSourceBlock().rendered) {
27+
if (otherConn.getCheck() && !otherConn.getCheck().includes('InstantInTime')) {
28+
otherConn.getSourceBlock().badBlock();
2929
}
3030
return true;
3131
}
32-
return !otherConn.check_ || otherConn.check_.includes('InstantInTime');
32+
return !otherConn.getCheck() || otherConn.getCheck().includes('InstantInTime');
3333
};
3434

3535

block-lexical-variables/src/warningHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class ErrorCheckers {
123123

124124
for (let i=0; i<params.dropDowns.length; i++) {
125125
const dropDown = block.getField(params.dropDowns[i]);
126-
const dropDownList = dropDown.menuGenerator_();
126+
const dropDownList = dropDown.getOptions(false);
127127
const text = dropDown.getText();
128128
const value = dropDown.getValue();
129129
let textInDropDown = false;

0 commit comments

Comments
 (0)