Skip to content

Commit 692d421

Browse files
committed
Run Blockly migration script
Change-Id: Id5fa531daa6c08fd8d38fa23dcf928f4253b07a2
1 parent 6e10ac3 commit 692d421

21 files changed

+195
-192
lines changed

appinventor/blocklyeditor/src/backpack.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Blockly.Backpack.backPackId = false;
188188
* @return {!Element} The backpack's SVG group.
189189
*/
190190
Blockly.Backpack.prototype.createDom = function(opt_workspace) {
191-
var workspace = opt_workspace || Blockly.getMainWorkspace();
191+
var workspace = opt_workspace || Blockly.common.getMainWorkspace();
192192
// insert the flyout after the main workspace (except, there's no
193193
// svg.insertAfter method, so we need to insert before the thing following
194194
// the main workspace. Neil Fraser says: this is "less hacky than it looks".
@@ -200,8 +200,8 @@ Blockly.Backpack.prototype.createDom = function(opt_workspace) {
200200
workspace.getParentSvg().appendChild(flyoutGroup);
201201
}
202202

203-
this.svgGroup_ = Blockly.utils.createSvgElement('g', {}, null);
204-
this.svgBody_ = Blockly.utils.createSvgElement('image',
203+
this.svgGroup_ = Blockly.utils.dom.createSvgElement('g', {}, null);
204+
this.svgBody_ = Blockly.utils.dom.createSvgElement('image',
205205
{'width': this.WIDTH_, 'height': this.BODY_HEIGHT_},
206206
this.svgGroup_);
207207
this.svgBody_.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
@@ -218,16 +218,16 @@ Blockly.Backpack.prototype.createDom = function(opt_workspace) {
218218
Blockly.Backpack.prototype.init = function() {
219219
this.position_();
220220
// If the document resizes, reposition the backpack.
221-
Blockly.bindEvent_(window, 'resize', this, this.position_);
221+
Blockly.browserEvents.bind(window, 'resize', this, this.position_);
222222
// Fixes a bug in Firefox where the backpack cannot be opened.
223-
Blockly.bindEvent_(this.svgBody_, 'mousedown', this, function(e) { e.stopPropagation(); e.preventDefault(); });
224-
Blockly.bindEvent_(this.svgBody_, 'click', this, this.openBackpack);
225-
Blockly.bindEvent_(this.svgBody_, 'contextmenu', this, this.openBackpackMenu);
223+
Blockly.browserEvents.bind(this.svgBody_, 'mousedown', this, function(e) { e.stopPropagation(); e.preventDefault(); });
224+
Blockly.browserEvents.bind(this.svgBody_, 'click', this, this.openBackpack);
225+
Blockly.browserEvents.bind(this.svgBody_, 'contextmenu', this, this.openBackpackMenu);
226226
this.flyout_.init(this.workspace_);
227227
this.flyout_.workspace_.isBackpack = true;
228228

229229
// load files for sound effect
230-
Blockly.getMainWorkspace().loadAudio_(['static/media/backpack.mp3', 'static/media/backpack.ogg', 'static/media/backpack.wav'], 'backpack');
230+
Blockly.common.getMainWorkspace().getAudioManager().load(['static/media/backpack.mp3', 'static/media/backpack.ogg', 'static/media/backpack.wav'], 'backpack');
231231

232232
var p = this;
233233
this.getContents(function(contents) {
@@ -317,7 +317,7 @@ Blockly.Backpack.prototype.checkValidBlockTypes = function(block, arr) {
317317
*
318318
*/
319319
Blockly.Backpack.prototype.addAllToBackpack = function() {
320-
var topBlocks = Blockly.mainWorkspace.getTopBlocks(false);
320+
var topBlocks = Blockly.common.getMainWorkspace().getTopBlocks(false);
321321
var p = this;
322322
this.getContents(function(contents) {
323323
var saveAsync = p.NoAsync_;
@@ -361,7 +361,7 @@ Blockly.Backpack.prototype.addToBackpack = function(block, store) {
361361
// storage in the future.
362362
p.setContents(bp_contents, store);
363363
p.grow();
364-
Blockly.getMainWorkspace().playAudio('backpack');
364+
Blockly.common.getMainWorkspace().playAudio('backpack');
365365

366366
// update the flyout when it's visible
367367
if (p.flyout_.isVisible()) {
@@ -448,8 +448,8 @@ Blockly.Backpack.prototype.openBackpackMenu = function(e) {
448448
var backpackClear = {enabled: true};
449449
backpackClear.text = Blockly.Msg.BACKPACK_EMPTY;
450450
backpackClear.callback = function() {
451-
if (Blockly.getMainWorkspace().hasBackpack()) {
452-
Blockly.getMainWorkspace().getBackpack().clear();
451+
if (Blockly.common.getMainWorkspace().hasBackpack()) {
452+
Blockly.common.getMainWorkspace().getBackpack().clear();
453453
}
454454
};
455455
options.push(backpackClear);
@@ -492,10 +492,10 @@ Blockly.Backpack.prototype.openBackpack = function(e) {
492492
* @param {!goog.math.Coordinate} start coordinate of the mouseDown event
493493
*/
494494
Blockly.Backpack.prototype.onMouseUp = function(e, start){
495-
var xy = Blockly.selected.getRelativeToSurfaceXY();
495+
var xy = Blockly.common.getSelected().getRelativeToSurfaceXY();
496496
var diffXY = goog.math.Coordinate.difference(start, xy);
497-
Blockly.selected.moveBy(diffXY.x, diffXY.y);
498-
Blockly.getMainWorkspace().render();
497+
Blockly.common.getSelected().moveBy(diffXY.x, diffXY.y);
498+
Blockly.common.getMainWorkspace().render();
499499
};
500500

501501
/**
@@ -521,7 +521,7 @@ Blockly.Backpack.prototype.onMouseMove = function(e) {
521521
};
522522

523523
Blockly.Backpack.prototype.mouseIsOver = function(e) {
524-
var xy = Blockly.convertCoordinates(Blockly.getMainWorkspace(), e.clientX, e.clientY, true);
524+
var xy = Blockly.convertCoordinates(Blockly.common.getMainWorkspace(), e.clientX, e.clientY, true);
525525
var mouseX = xy.x;
526526
var mouseY = xy.y;
527527
return (mouseX > this.left_) &&

appinventor/blocklyeditor/src/backpackFlyout.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ Blockly.BackpackFlyout.prototype.createDom = function(tagName) {
5959
*/
6060
Blockly.BackpackFlyout.prototype.dispose = function() {
6161
this.hide();
62-
Blockly.unbindEvent_(this.eventWrappers_);
62+
Blockly.browserEvents.unbind(this.eventWrappers_);
6363
this.eventWrappers_.length = 0;
64-
if (this.scrollbar_) {
65-
this.scrollbar_.dispose();
66-
this.scrollbar_ = null;
64+
if (this.scrollbar) {
65+
this.scrollbar.dispose();
66+
this.scrollbar = null;
6767
}
6868
this.workspace_ = null;
6969
if (this.svgGroup_) {
@@ -90,11 +90,11 @@ Blockly.BackpackFlyout.prototype.isBlockCreatable_ = function(_block) {
9090
*/
9191
Blockly.BackpackFlyout.terminateDrag_ = function() {
9292
if (Blockly.BackpackFlyout.onMouseUpWrapper_) {
93-
Blockly.unbindEvent_(Blockly.BackpackFlyout.onMouseUpWrapper_);
93+
Blockly.browserEvents.unbind(Blockly.BackpackFlyout.onMouseUpWrapper_);
9494
Blockly.BackpackFlyout.onMouseUpWrapper_ = null;
9595
}
9696
if (Blockly.BackpackFlyout.onMouseMoveWrapper_) {
97-
Blockly.unbindEvent_(Blockly.BackpackFlyout.onMouseMoveWrapper_);
97+
Blockly.browserEvents.unbind(Blockly.BackpackFlyout.onMouseMoveWrapper_);
9898
Blockly.BackpackFlyout.onMouseMoveWrapper_ = null;
9999
}
100100
Blockly.BackpackFlyout.startDownEvent_ = null;

appinventor/blocklyeditor/src/block_svg.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Blockly.BlockSvg.prototype.onMouseDown_ = (function(func) {
8383
workspace.getParentSvg().parentNode.focus();
8484
}
8585
if (Blockly.FieldFlydown.openFieldFlydown_) {
86-
var flydown = Blockly.getMainWorkspace().getFlydown();
86+
var flydown = Blockly.common.getMainWorkspace().getFlydown();
8787
if (flydown) {
8888
if (goog.dom.contains(flydown.svgGroup_, this.svgGroup_)) {
8989
//prevent hiding the flyout if a child block is the target
@@ -225,7 +225,7 @@ Blockly.BlockSvg.prototype.renderDown_ = function() {
225225
*/
226226
Blockly.BlockSvg.prototype.renderHere_ = function() {
227227
var start = new Date().getTime();
228-
Blockly.Field.startCache();
228+
Blockly.utils.dom.startTextWidthCache();
229229
this.rendered = true;
230230

231231
if (this.isCollapsed()) {
@@ -258,7 +258,7 @@ Blockly.BlockSvg.prototype.renderHere_ = function() {
258258
this.removeBadBlock();
259259
}
260260

261-
Blockly.Field.stopCache();
261+
Blockly.utils.dom.stopTextWidthCache();
262262
var stop = new Date().getTime();
263263
var timeDiff = stop-start;
264264
Blockly.Instrument.stats.renderHereCalls++;
@@ -348,7 +348,7 @@ Blockly.BlockSvg.prototype.setCollapsed = (function(func) {
348348
*/
349349
Blockly.BlockSvg.prototype.addBadBlock = function() {
350350
if (this.rendered) {
351-
Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_),
351+
Blockly.utils.dom.addClass(/** @type {!Element} */ (this.svgGroup_),
352352
'badBlock');
353353
// Move the selected block to the top of the stack.
354354
this.svgGroup_.parentNode.appendChild(this.svgGroup_);
@@ -360,7 +360,7 @@ Blockly.BlockSvg.prototype.addBadBlock = function() {
360360
*/
361361
Blockly.BlockSvg.prototype.removeBadBlock = function() {
362362
if (this.rendered) {
363-
Blockly.utils.removeClass(/** @type {!Element} */ (this.svgGroup_),
363+
Blockly.utils.dom.removeClass(/** @type {!Element} */ (this.svgGroup_),
364364
'badBlock');
365365
// Move the selected block to the top of the stack.
366366
this.svgGroup_.parentNode.appendChild(this.svgGroup_);
@@ -371,7 +371,7 @@ Blockly.BlockSvg.prototype.removeBadBlock = function() {
371371
* Check to see if the block is marked as bad.
372372
*/
373373
Blockly.BlockSvg.prototype.isBadBlock = function() {
374-
return Blockly.utils.hasClass(/** @type {!Element} */ (this.svgGroup_),
374+
return Blockly.utils.dom.hasClass(/** @type {!Element} */ (this.svgGroup_),
375375
'badBlock');
376376
};
377377

@@ -380,7 +380,7 @@ Blockly.BlockSvg.prototype.isBadBlock = function() {
380380
*/
381381
Blockly.BlockSvg.prototype.badBlock = function() {
382382
this.isBad = true;
383-
if (this.workspace == Blockly.getMainWorkspace()) {
383+
if (this.workspace == Blockly.common.getMainWorkspace()) {
384384
// mark a block bad only if it is on the main workspace
385385
goog.asserts.assertObject(this.svgGroup_, 'Block is not rendered.');
386386
this.addBadBlock();
@@ -392,7 +392,7 @@ Blockly.BlockSvg.prototype.badBlock = function() {
392392
*/
393393
Blockly.BlockSvg.prototype.notBadBlock = function() {
394394
this.isBad = false;
395-
if (this.workspace == Blockly.getMainWorkspace()) {
395+
if (this.workspace == Blockly.common.getMainWorkspace()) {
396396
// mark a block not bad only if it is on the main workspace
397397
goog.asserts.assertObject(this.svgGroup_, 'Block is not rendered.');
398398
this.removeBadBlock();
@@ -518,7 +518,7 @@ Blockly.BlockSvg.prototype.getTopWorkspace = function() {
518518
* Add the selection highlight to the block.
519519
*/
520520
Blockly.BlockSvg.prototype.addSelect = function() {
521-
Blockly.utils.addClass(this.svgGroup_, 'blocklySelected');
521+
Blockly.utils.dom.addClass(this.svgGroup_, 'blocklySelected');
522522
var block_0 = this;
523523
do {
524524
var root = block_0.getSvgRoot();

appinventor/blocklyeditor/src/blockly.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Blockly.hideChaff = (function(func) {
4242
var argCopy = Array.prototype.slice.call(arguments);
4343
func.apply(this, argCopy);
4444
// [lyn, 10/06/13] for handling parameter & procedure flydowns
45-
Blockly.WorkspaceSvg.prototype.hideChaff.call(Blockly.getMainWorkspace(), argCopy);
45+
Blockly.WorkspaceSvg.prototype.hideChaff.call(Blockly.common.getMainWorkspace(), argCopy);
4646
};
4747
f.isWrapped = true;
4848
return f;
@@ -57,11 +57,11 @@ Blockly.hideChaff = (function(func) {
5757
Blockly.confirmDeletion = function(callback) {
5858
var DELETION_THRESHOLD = 3;
5959

60-
var descendantCount = Blockly.mainWorkspace.getAllBlocks().length;
61-
if (Blockly.selected != null) {
62-
descendantCount = Blockly.selected.getDescendants().length;
63-
if (Blockly.selected.nextConnection && Blockly.selected.nextConnection.targetConnection) {
64-
descendantCount -= Blockly.selected.nextConnection.targetBlock().getDescendants().length;
60+
var descendantCount = Blockly.common.getMainWorkspace().getAllBlocks().length;
61+
if (Blockly.common.getSelected() != null) {
62+
descendantCount = Blockly.common.getSelected().getDescendants().length;
63+
if (Blockly.common.getSelected().nextConnection && Blockly.common.getSelected().nextConnection.targetConnection) {
64+
descendantCount -= Blockly.common.getSelected().nextConnection.targetBlock().getDescendants().length;
6565
}
6666
}
6767

@@ -74,7 +74,7 @@ Blockly.confirmDeletion = function(callback) {
7474
var dialog = new Blockly.Util.Dialog(Blockly.Msg.CONFIRM_DELETE, msg, deleteButton, true, cancelButton, 0, function(button) {
7575
dialog.hide();
7676
if (button == deleteButton) {
77-
Blockly.mainWorkspace.playAudio('delete');
77+
Blockly.common.getMainWorkspace().playAudio('delete');
7878
callback(true);
7979
} else {
8080
callback(false);
@@ -83,13 +83,13 @@ Blockly.confirmDeletion = function(callback) {
8383
} else {
8484
var response = confirm(Blockly.Msg.WARNING_DELETE_X_BLOCKS.replace('%1', String(descendantCount)));
8585
if (response) {
86-
Blockly.mainWorkspace.playAudio('delete');
86+
Blockly.common.getMainWorkspace().playAudio('delete');
8787
}
8888
callback(response);
8989
}
9090
}
9191
else {
92-
Blockly.mainWorkspace.playAudio('delete');
92+
Blockly.common.getMainWorkspace().playAudio('delete');
9393
callback(true);
9494
}
9595
};

appinventor/blocklyeditor/src/blocklyeditor.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Blockly.BlocklyEditor.addClearDoItOption = function(myBlock, options) {
232232
clearDoitOption.text = Blockly.Msg.CLEAR_DO_IT_ERROR;
233233
clearDoitOption.callback = function() {
234234
myBlock.replError = null;
235-
Blockly.getMainWorkspace().getWarningHandler().checkErrors(myBlock);
235+
Blockly.common.getMainWorkspace().getWarningHandler().checkErrors(myBlock);
236236
};
237237
options.push(clearDoitOption);
238238
};
@@ -429,7 +429,7 @@ Blockly.BlocklyEditor['create'] = function(container, formName, readOnly, rtl) {
429429
* @param {!Blockly.WorkspaceSvg} workspace
430430
*/
431431
Blockly.ai_inject = function(container, workspace) {
432-
Blockly.mainWorkspace = workspace; // make workspace the 'active' workspace
432+
Blockly.common.setMainWorkspace(workspace); // make workspace the 'active' workspace
433433
workspace.fireChangeListener(new AI.Events.ScreenSwitch(workspace.projectId, workspace.formName));
434434
var gridEnabled = top.BlocklyPanel_getGridEnabled && top.BlocklyPanel_getGridEnabled();
435435
var gridSnap = top.BlocklyPanel_getSnapEnabled && top.BlocklyPanel_getSnapEnabled();
@@ -508,14 +508,14 @@ Blockly.ai_inject = function(container, workspace) {
508508
var flydown = new Blockly.Flydown(new Blockly.Options({scrollbars: false}));
509509
// ***** [lyn, 10/05/2013] NEED TO WORRY ABOUT MULTIPLE BLOCKLIES! *****
510510
workspace.flydown_ = flydown;
511-
Blockly.utils.insertAfter_(flydown.createDom('g'), workspace.svgBubbleCanvas_);
511+
Blockly.utils.dom.insertAfter(flydown.createDom('g'), workspace.getBubbleCanvas());
512512
flydown.init(workspace);
513513
flydown.autoClose = true; // Flydown closes after selecting a block
514514
workspace.addWarningIndicator();
515515
workspace.addBackpack();
516516
Blockly.init_(workspace);
517517
workspace.markFocused();
518-
Blockly.bindEvent_(svg, 'focus', workspace, workspace.markFocused);
518+
Blockly.browserEvents.bind(svg, 'focus', workspace, workspace.markFocused);
519519
workspace.resize();
520520
// Hide scrollbars by default (otherwise ghost rectangles intercept mouse events)
521521
workspace.flyout_.scrollbar_ && workspace.flyout_.scrollbar_.setContainerVisible(false);
@@ -595,7 +595,7 @@ top.document.addEventListener('mousedown', function(e) {
595595
target = target.parentElement;
596596
}
597597
// Make sure the workspace has been injected.
598-
if (Blockly.mainWorkspace) {
598+
if (Blockly.common.getMainWorkspace()) {
599599
Blockly.hideChaff();
600600
}
601601
}, false);

appinventor/blocklyeditor/src/component.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ Blockly.Component.rename = function(oldname, newname, uid) {
7171

7272
console.log("Revised Blockly.ComponentInstances, Blockly.Language, Blockly.Yail for " + newname);
7373

74-
// Revise names, types, and block titles for all blocks containing newname in Blockly.mainWorkspace
75-
var blocks = Blockly.mainWorkspace.getAllBlocks();
74+
// Revise names, types, and block titles for all blocks containing newname in Blockly.common.getMainWorkspace()
75+
var blocks = Blockly.common.getMainWorkspace().getAllBlocks();
7676
for (var x = 0, block; block = blocks[x]; x++) {
7777
if (!block.category) {
7878
continue;
@@ -81,7 +81,7 @@ Blockly.Component.rename = function(oldname, newname, uid) {
8181
}
8282
}
8383

84-
console.log("Revised Blockly.mainWorkspace for " + newname);
84+
console.log("Revised Blockly.common.getMainWorkspace() for " + newname);
8585
};
8686

8787

@@ -92,7 +92,7 @@ Blockly.Component.rename = function(oldname, newname, uid) {
9292
* @param uid, Component's unique id -- not currently used
9393
*
9494
* The component should be listed in the ComponentInstances list.
95-
* - For each instance of the component's block in the Blockly.mainWorkspace
95+
* - For each instance of the component's block in the Blockly.common.getMainWorkspace()
9696
* -- Call its BlocklyBlock.destroy() method to remove the block
9797
* from the workspace and adjust enclosed or enclosing blocks.
9898
* Remove the block's entry from ComponentInstances
@@ -103,7 +103,7 @@ Blockly.Component.remove = function(type, name, uid) {
103103
Blockly.TypeBlock.needsReload.components = true;
104104

105105
// Delete instances of this type of block from the workspace
106-
var allblocks = Blockly.mainWorkspace.getAllBlocks();
106+
var allblocks = Blockly.common.getMainWorkspace().getAllBlocks();
107107
for (var x = 0, block; block = allblocks[x]; x++) {
108108
if (!block.category) {
109109
continue;
@@ -138,7 +138,7 @@ Blockly.Component.buildComponentMap = function(warnings, errors, forRepl, compil
138138

139139
// TODO: populate warnings, errors as we traverse the top-level blocks
140140

141-
var blocks = Blockly.mainWorkspace.getTopBlocks(true);
141+
var blocks = Blockly.common.getMainWorkspace().getTopBlocks(true);
142142
for (var x = 0, block; block = blocks[x]; x++) {
143143

144144
// TODO: deal with unattached blocks that are not valid top-level definitions. Valid blocks
@@ -178,8 +178,8 @@ Blockly.Component.buildComponentMap = function(warnings, errors, forRepl, compil
178178
*/
179179
Blockly.Component.verifyAllBlocks = function () {
180180
// We can only verify blocks once the workspace has been injected...
181-
if (Blockly.mainWorkspace != null) {
182-
var allBlocks = Blockly.mainWorkspace.getAllBlocks();
181+
if (Blockly.common.getMainWorkspace() != null) {
182+
var allBlocks = Blockly.common.getMainWorkspace().getAllBlocks();
183183
for (var x = 0, block; block = allBlocks[x]; ++x) {
184184
if (block.category != 'Component') {
185185
continue;

appinventor/blocklyeditor/src/drawer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Blockly.Drawer.PREFIX_ = 'cat_';
6262
*/
6363
Blockly.Drawer.buildTree_ = function() {
6464
var tree = {};
65-
var formName = Blockly.mainWorkspace.formName;
65+
var formName = Blockly.common.getMainWorkspace().formName;
6666
var screenName = formName.substring(formName.indexOf("_") + 1);
6767

6868
// Check to see if a Blocks Toolkit is defined. If so, use that to build the tree.
@@ -222,7 +222,7 @@ Blockly.Drawer.prototype.instanceRecordToXMLArray = function(instanceRecord) {
222222
var typeName = instanceRecord.typeName;
223223
var componentInfo = this.workspace_.getComponentDatabase().getType(typeName);
224224
225-
var formName = Blockly.mainWorkspace.formName;
225+
var formName = Blockly.common.getMainWorkspace().formName;
226226
var screenName = formName.substring(formName.indexOf("_") + 1);
227227
var subsetJsonString = "";
228228
if (window.parent.BlocklyPanel_getComponentInstancePropertyValue) {

0 commit comments

Comments
 (0)