diff --git a/blocks/procedures.js b/blocks/procedures.js index ff0a4e3cb..761e4877d 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -496,7 +496,7 @@ Blockly.Blocks['procedures_mutatorcontainer'] = { (event.type != Blockly.Events.BLOCK_DELETE && event.type != Blockly.Events.BLOCK_CREATE)) { return; } - var blocks = this.workspace.getAllBlocks(); + var blocks = this.workspace.getAllBlocks(false); var allVariables = this.workspace.getAllVariables(); if (event.type == Blockly.Events.BLOCK_DELETE) { var variableNamesToKeep = []; @@ -602,7 +602,7 @@ Blockly.Blocks['procedures_mutatorarg'] = { } // Prevents duplicate parameter names in functions - var blocks = sourceBlock.workspace.getAllBlocks(); + var blocks = sourceBlock.workspace.getAllBlocks(false); for (var i = 0; i < blocks.length; i++) { if (blocks[i].id == this.getSourceBlock().id) { continue; diff --git a/core/blockly.js b/core/blockly.js index 6b5abf6fa..e4e8203c0 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -339,10 +339,11 @@ Blockly.hideChaff = function(opt_allowToolbox) { workspace.trashcan.flyout_) { workspace.trashcan.flyout_.hide(); } - if (workspace.toolbox_ && - workspace.toolbox_.flyout_ && - workspace.toolbox_.flyout_.autoClose) { - workspace.toolbox_.clearSelection(); + var toolbox = workspace.getToolbox(); + if (toolbox && + toolbox.flyout_ && + toolbox.flyout_.autoClose) { + toolbox.clearSelection(); } } }; diff --git a/core/bubble.js b/core/bubble.js index 8c245631b..53cbe5755 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -455,12 +455,10 @@ Blockly.Bubble.prototype.layoutBubble_ = function() { /** * Calculate the what percentage of the bubble overlaps with the visible * workspace (what percentage of the bubble is visible). - * @param {!Object} relativeMin The position of the top-left corner of the - * bubble relative to the anchor point. - * @param {number} relativeMin.x The x-position of the relativeMin. - * @param {number} relativeMin.y The y-position of the relativeMin. + * @param {!{x: number, y: number}} relativeMin The position of the top-left + * corner of the bubble relative to the anchor point. * @param {!Object} metrics The metrics of the workspace the bubble will - * appear in. + * appear in. * @return {number} The percentage of the bubble that is visible. * @private */ diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 65136e91c..c4cc6910d 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -218,10 +218,10 @@ Blockly.BubbleDragger.prototype.endBubbleDrag = function( } this.workspace_.setResizesEnabled(true); - if (this.workspace_.toolbox_) { + if (this.workspace_.getToolbox()) { var style = this.draggingBubble_.isDeletable() ? 'blocklyToolboxDelete' : 'blocklyToolboxGrab'; - this.workspace_.toolbox_.removeStyle(style); + this.workspace_.getToolbox().removeStyle(style); } Blockly.Events.setGroup(false); }; @@ -232,7 +232,8 @@ Blockly.BubbleDragger.prototype.endBubbleDrag = function( */ Blockly.BubbleDragger.prototype.fireMoveEvent_ = function() { if (this.draggingBubble_.isComment) { - var event = new Blockly.Events.CommentMove(this.draggingBubble_); + var event = new Blockly.Events.CommentMove( + /** @type {!Blockly.WorkspaceCommentSvg} */ (this.draggingBubble_)); event.setOldCoordinate(this.startXY_); event.recordNew(); Blockly.Events.fire(event); diff --git a/core/comment.js b/core/comment.js index ce2b7b642..fe9494630 100644 --- a/core/comment.js +++ b/core/comment.js @@ -255,7 +255,8 @@ Blockly.Comment.prototype.createEditableBubble_ = function() { */ Blockly.Comment.prototype.createNonEditableBubble_ = function() { // TODO (#2917): It would be great if the comment could support line breaks. - Blockly.Warning.prototype.createBubble.call(this); + Blockly.Warning.prototype.createBubble.call( + /** @type {Blockly.Warning} */ (this)); }; /** @@ -265,7 +266,8 @@ Blockly.Comment.prototype.createNonEditableBubble_ = function() { Blockly.Comment.prototype.disposeBubble_ = function() { if (this.paragraphElement_) { // We're using the warning UI so we have to let it dispose. - Blockly.Warning.prototype.disposeBubble.call(this); + Blockly.Warning.prototype.disposeBubble.call( + /** @type {Blockly.Warning} */ (this)); return; } diff --git a/core/inject.js b/core/inject.js index 74c755fa2..2019bc1d9 100644 --- a/core/inject.js +++ b/core/inject.js @@ -411,8 +411,8 @@ Blockly.init_ = function(mainWorkspace) { Blockly.inject.bindDocumentEvents_(); if (options.languageTree) { - if (mainWorkspace.toolbox_) { - mainWorkspace.toolbox_.init(mainWorkspace); + if (mainWorkspace.getToolbox()) { + mainWorkspace.getToolbox().init(mainWorkspace); } else if (mainWorkspace.flyout_) { // Build a fixed flyout with the root blocks. mainWorkspace.flyout_.init(mainWorkspace); diff --git a/core/mutator.js b/core/mutator.js index 0f35789f3..72d8e77df 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -420,14 +420,14 @@ Blockly.Mutator.prototype.dispose = function() { Blockly.Mutator.prototype.updateBlockStyle = function() { var ws = this.workspace_; - if (ws && ws.getAllBlocks()) { - var workspaceBlocks = ws.getAllBlocks(); + if (ws && ws.getAllBlocks(false)) { + var workspaceBlocks = ws.getAllBlocks(false); for (var i = 0; i < workspaceBlocks.length; i++) { var block = workspaceBlocks[i]; block.setStyle(block.getStyleName()); } - var flyoutBlocks = ws.flyout_.workspace_.getAllBlocks(); + var flyoutBlocks = ws.flyout_.workspace_.getAllBlocks(false); for (var i = 0; i < flyoutBlocks.length; i++) { var block = flyoutBlocks[i]; block.setStyle(block.getStyleName()); diff --git a/core/workspace.js b/core/workspace.js index 1d615dbae..cd1514bc5 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -226,7 +226,7 @@ Blockly.Workspace.prototype.setTheme = function(theme) { */ Blockly.Workspace.prototype.refreshTheme = function() { // Update all blocks in workspace that have a style name. - this.updateBlockStyles_(this.getAllBlocks().filter( + this.updateBlockStyles_(this.getAllBlocks(false).filter( function(block) { return block.getStyleName() !== undefined; } @@ -651,7 +651,7 @@ Blockly.Workspace.prototype.remainingCapacity = function() { return Infinity; } - return this.options.maxBlocks - this.getAllBlocks().length; + return this.options.maxBlocks - this.getAllBlocks(false).length; }; /** diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 8cc431587..f318c4364 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -90,7 +90,8 @@ Blockly.WorkspaceSvg = function(options, * @type {!Blockly.WorkspaceAudio} * @private */ - this.audioManager_ = new Blockly.WorkspaceAudio(options.parentWorkspace); + this.audioManager_ = new Blockly.WorkspaceAudio( + /** @type {Blockly.WorkspaceSvg} */ (options.parentWorkspace)); /** * This workspace's grid object or null. diff --git a/demos/code/code.js b/demos/code/code.js index 67cace73c..2e8426bf7 100644 --- a/demos/code/code.js +++ b/demos/code/code.js @@ -379,9 +379,9 @@ Code.init = function() { el.style.width = (2 * bBox.width - el.offsetWidth) + 'px'; } // Make the 'Blocks' tab line up with the toolbox. - if (Code.workspace && Code.workspace.toolbox_.width) { + if (Code.workspace && Code.workspace.getToolbox().width) { document.getElementById('tab_blocks').style.minWidth = - (Code.workspace.toolbox_.width - 38) + 'px'; + (Code.workspace.getToolbox().width - 38) + 'px'; // Account for the 19 pixel margin and on each side. } }; diff --git a/demos/custom-fields/turtle/index.html b/demos/custom-fields/turtle/index.html index 682eb8aa8..484fc2b3e 100644 --- a/demos/custom-fields/turtle/index.html +++ b/demos/custom-fields/turtle/index.html @@ -89,7 +89,7 @@ } function setRandomStyle() { - var blocks = workspace.getAllBlocks(); + var blocks = workspace.getAllBlocks(false); var styles = Object.keys(workspace.getTheme().getAllBlockStyles()); styles.splice(styles.indexOf(blocks[0].getStyleName()), 1); var style = styles[Math.floor(Math.random() * styles.length)]; @@ -99,14 +99,14 @@ } function toggleShadow() { - var blocks = workspace.getAllBlocks(); + var blocks = workspace.getAllBlocks(false); for(var i = 0, block; block = blocks[i]; i++) { block.setShadow(!block.isShadow()); } } function toggleEnabled() { - var blocks = workspace.getAllBlocks(); + var blocks = workspace.getAllBlocks(false); for(var i = 0, block; block = blocks[i]; i++) { block.setEnabled(!block.isEnabled()); } @@ -114,7 +114,7 @@ function toggleEditable() { Blockly.hideChaff(); - var blocks = workspace.getAllBlocks(); + var blocks = workspace.getAllBlocks(false); for(var i = 0, block; block = blocks[i]; i++) { block.setEditable(!block.isEditable()); } @@ -122,7 +122,7 @@ function toggleCollapsed() { Blockly.hideChaff(); - var blocks = workspace.getAllBlocks(); + var blocks = workspace.getAllBlocks(false); for(var i = 0, block; block = blocks[i]; i++) { block.setCollapsed(!block.isCollapsed()); } diff --git a/tests/generators/index.html b/tests/generators/index.html index 6b5eb4d67..e1f88f22a 100644 --- a/tests/generators/index.html +++ b/tests/generators/index.html @@ -257,7 +257,7 @@ function toDart() { function changeIndex() { var oneBasedIndex = document.getElementById('indexing').checked; demoWorkspace.options.oneBasedIndex = oneBasedIndex; - demoWorkspace.toolbox_.flyout_.workspace_.options.oneBasedIndex = oneBasedIndex; + demoWorkspace.getToolbox().flyout_.workspace_.options.oneBasedIndex = oneBasedIndex; } diff --git a/tests/jsunit/workspace_test.js b/tests/jsunit/workspace_test.js index ff85e7f3d..916cbeead 100644 --- a/tests/jsunit/workspace_test.js +++ b/tests/jsunit/workspace_test.js @@ -38,11 +38,11 @@ function test_emptyWorkspace() { try { assertEquals('Empty workspace (1).', 0, workspace.getTopBlocks(true).length); assertEquals('Empty workspace (2).', 0, workspace.getTopBlocks(false).length); - assertEquals('Empty workspace (3).', 0, workspace.getAllBlocks().length); + assertEquals('Empty workspace (3).', 0, workspace.getAllBlocks(false).length); workspace.clear(); assertEquals('Empty workspace (4).', 0, workspace.getTopBlocks(true).length); assertEquals('Empty workspace (5).', 0, workspace.getTopBlocks(false).length); - assertEquals('Empty workspace (6).', 0, workspace.getAllBlocks().length); + assertEquals('Empty workspace (6).', 0, workspace.getAllBlocks(false).length); } finally { workspaceTest_tearDown(); } @@ -54,19 +54,19 @@ function test_flatWorkspace() { var blockA = workspace.newBlock(''); assertEquals('One block workspace (1).', 1, workspace.getTopBlocks(true).length); assertEquals('One block workspace (2).', 1, workspace.getTopBlocks(false).length); - assertEquals('One block workspace (3).', 1, workspace.getAllBlocks().length); + assertEquals('One block workspace (3).', 1, workspace.getAllBlocks(false).length); var blockB = workspace.newBlock(''); assertEquals('Two block workspace (1).', 2, workspace.getTopBlocks(true).length); assertEquals('Two block workspace (2).', 2, workspace.getTopBlocks(false).length); - assertEquals('Two block workspace (3).', 2, workspace.getAllBlocks().length); + assertEquals('Two block workspace (3).', 2, workspace.getAllBlocks(false).length); blockA.dispose(); assertEquals('One block workspace (4).', 1, workspace.getTopBlocks(true).length); assertEquals('One block workspace (5).', 1, workspace.getTopBlocks(false).length); - assertEquals('One block workspace (6).', 1, workspace.getAllBlocks().length); + assertEquals('One block workspace (6).', 1, workspace.getAllBlocks(false).length); workspace.clear(); assertEquals('Cleared workspace (1).', 0, workspace.getTopBlocks(true).length); assertEquals('Cleared workspace (2).', 0, workspace.getTopBlocks(false).length); - assertEquals('Cleared workspace (3).', 0, workspace.getAllBlocks().length); + assertEquals('Cleared workspace (3).', 0, workspace.getAllBlocks(false).length); } finally { workspaceTest_tearDown(); } diff --git a/tests/jsunit/xml_test.js b/tests/jsunit/xml_test.js index c2c6ec741..afd3dc9c7 100644 --- a/tests/jsunit/xml_test.js +++ b/tests/jsunit/xml_test.js @@ -142,7 +142,7 @@ function test_domToWorkspace_BackwardCompatibility() { ' ' + ''); Blockly.Xml.domToWorkspace(dom, workspace); - assertEquals('Block count', 1, workspace.getAllBlocks().length); + assertEquals('Block count', 1, workspace.getAllBlocks(false).length); checkVariableValues(workspace, 'name1', '', '1'); } finally { xmlTest_tearDownWithMockBlocks(); @@ -165,7 +165,7 @@ function test_domToWorkspace_VariablesAtTop() { ' ' + ''); Blockly.Xml.domToWorkspace(dom, workspace); - assertEquals('Block count', 1, workspace.getAllBlocks().length); + assertEquals('Block count', 1, workspace.getAllBlocks(false).length); checkVariableValues(workspace, 'name1', 'type1', 'id1'); checkVariableValues(workspace, 'name2', 'type2', 'id2'); checkVariableValues(workspace, 'name3', '', 'id3'); @@ -268,9 +268,9 @@ function test_appendDomToWorkspace() { ''); workspace = new Blockly.Workspace(); Blockly.Xml.appendDomToWorkspace(dom, workspace); - assertEquals('Block count', 1, workspace.getAllBlocks().length); + assertEquals('Block count', 1, workspace.getAllBlocks(false).length); var newBlockIds = Blockly.Xml.appendDomToWorkspace(dom, workspace); - assertEquals('Block count', 2, workspace.getAllBlocks().length); + assertEquals('Block count', 2, workspace.getAllBlocks(false).length); assertEquals('Number of new block ids',1,newBlockIds.length); } finally { delete Blockly.Blocks.test_block; diff --git a/tests/mocha/xml_procedures_test.js b/tests/mocha/xml_procedures_test.js index 7af53e635..5af798c9e 100644 --- a/tests/mocha/xml_procedures_test.js +++ b/tests/mocha/xml_procedures_test.js @@ -238,7 +238,7 @@ suite('Procedures XML', function() { // defined for call_noreturn. Make it defined for both. /* chai.assert.isArray(block.argumentVarModels_); chai.assert.isEmpty(block.argumentVarModels_); */ - chai.assert.equal(this.workspace.getAllBlocks().count, 2); + chai.assert.equal(this.workspace.getAllBlocks(false).count, 2); }); }); test('Caller W/ Params', function() { diff --git a/tests/playground.html b/tests/playground.html index d8d67fc25..be4b9b29d 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -192,7 +192,7 @@ function addToolboxButtonCallbacks() { } }; var setRandomStyle = function(button) { - var blocks = button.workspace_.getAllBlocks(); + var blocks = button.workspace_.getAllBlocks(false); var styles = Object.keys(workspace.getTheme().getAllBlockStyles()); styles.splice(styles.indexOf(blocks[0].getStyleName()), 1); var style = styles[Math.floor(Math.random() * styles.length)]; @@ -201,26 +201,26 @@ function addToolboxButtonCallbacks() { } }; var toggleEnabled = function(button) { - var blocks = button.workspace_.getAllBlocks(); + var blocks = button.workspace_.getAllBlocks(false); for(var i = 0, block; block = blocks[i]; i++) { block.setEnabled(!block.isEnabled()); } }; var toggleShadow = function(button) { - var blocks = button.workspace_.getAllBlocks(); + var blocks = button.workspace_.getAllBlocks(false); for(var i = 0, block; block = blocks[i]; i++) { block.setShadow(!block.isShadow()); } }; var toggleCollapsed = function(button) { - var blocks = button.workspace_.getAllBlocks(); + var blocks = button.workspace_.getAllBlocks(false); for(var i = 0, block; block = blocks[i]; i++) { block.setCollapsed(!block.isCollapsed()); } }; var setInput = function(button) { Blockly.prompt('Input text to set.', 'ab', function(input) { - var blocks = button.getTargetWorkspace().getAllBlocks(); + var blocks = button.getTargetWorkspace().getAllBlocks(false); for(var i = 0, block; block = blocks[i]; i++) { if (block.getField('INPUT')) { block.setFieldValue(input, 'INPUT'); diff --git a/tests/screenshot/gen_screenshots.js b/tests/screenshot/gen_screenshots.js index cd49443dc..fc938ea60 100644 --- a/tests/screenshot/gen_screenshots.js +++ b/tests/screenshot/gen_screenshots.js @@ -167,7 +167,7 @@ async function genSingleScreenshot(browser, dir, test_name, isCollapsed, isInser var xml = Blockly.Xml.textToDom(xml_text); Blockly.Xml.domToWorkspace(xml, workspace); if (isCollapsed || isInsertionMarker || inlineInputs || externalInputs) { - var blocks = workspace.getAllBlocks(); + var blocks = workspace.getAllBlocks(false); for (var i = 0, block; block = blocks[i]; i++) { block.setCollapsed(isCollapsed); block.setInsertionMarker(isInsertionMarker); diff --git a/tests/workspace_svg/workspace_svg_test.js b/tests/workspace_svg/workspace_svg_test.js index 696805df8..56eccb64a 100644 --- a/tests/workspace_svg/workspace_svg_test.js +++ b/tests/workspace_svg/workspace_svg_test.js @@ -73,11 +73,11 @@ function test_emptyWorkspace() { try { assertEquals('Empty workspace (1).', 0, workspace.getTopBlocks(true).length); assertEquals('Empty workspace (2).', 0, workspace.getTopBlocks(false).length); - assertEquals('Empty workspace (3).', 0, workspace.getAllBlocks().length); + assertEquals('Empty workspace (3).', 0, workspace.getAllBlocks(false).length); workspace.clear(); assertEquals('Empty workspace (4).', 0, workspace.getTopBlocks(true).length); assertEquals('Empty workspace (5).', 0, workspace.getTopBlocks(false).length); - assertEquals('Empty workspace (6).', 0, workspace.getAllBlocks().length); + assertEquals('Empty workspace (6).', 0, workspace.getAllBlocks(false).length); } finally { workspace.dispose(); } @@ -90,11 +90,11 @@ function test_flatWorkspace() { blockA = helper_createNewBlock(workspace, ''); assertEquals('One block workspace (1).', 1, workspace.getTopBlocks(true).length); assertEquals('One block workspace (2).', 1, workspace.getTopBlocks(false).length); - assertEquals('One block workspace (3).', 1, workspace.getAllBlocks().length); + assertEquals('One block workspace (3).', 1, workspace.getAllBlocks(false).length); blockB = helper_createNewBlock(workspace, ''); assertEquals('Two block workspace (1).', 2, workspace.getTopBlocks(true).length); assertEquals('Two block workspace (2).', 2, workspace.getTopBlocks(false).length); - assertEquals('Two block workspace (3).', 2, workspace.getAllBlocks().length); + assertEquals('Two block workspace (3).', 2, workspace.getAllBlocks(false).length); try { blockA.dispose(); } catch (e) { @@ -103,11 +103,11 @@ function test_flatWorkspace() { assertEquals('One block workspace (4).', 1, workspace.getTopBlocks(true).length); assertEquals('One block workspace (5).', 1, workspace.getTopBlocks(false).length); - assertEquals('One block workspace (6).', 1, workspace.getAllBlocks().length); + assertEquals('One block workspace (6).', 1, workspace.getAllBlocks(false).length); workspace.clear(); assertEquals('Cleared workspace (1).', 0, workspace.getTopBlocks(true).length); assertEquals('Cleared workspace (2).', 0, workspace.getTopBlocks(false).length); - assertEquals('Cleared workspace (3).', 0, workspace.getAllBlocks().length); + assertEquals('Cleared workspace (3).', 0, workspace.getAllBlocks(false).length); } finally { blockB && blockB.dispose(); blockA && blockA.dispose(); @@ -125,10 +125,10 @@ function test_appendDomToWorkspace() { ' ' + ''); Blockly.Xml.appendDomToWorkspace(dom, workspace); - assertEquals('Block count', 1, workspace.getAllBlocks().length); + assertEquals('Block count', 1, workspace.getAllBlocks(false).length); Blockly.Xml.appendDomToWorkspace(dom, workspace); - assertEquals('Block count', 2, workspace.getAllBlocks().length); - var blocks = workspace.getAllBlocks(); + assertEquals('Block count', 2, workspace.getAllBlocks(false).length); + var blocks = workspace.getAllBlocks(false); assertEquals('Block 1 position x',21,blocks[0].getRelativeToSurfaceXY().x); assertEquals('Block 1 position y',23,blocks[0].getRelativeToSurfaceXY().y); assertEquals('Block 2 position x',21,blocks[1].getRelativeToSurfaceXY().x); @@ -153,7 +153,7 @@ function test_svgDisposeWithShadow() { ''); Blockly.Xml.appendDomToWorkspace(dom, workspace); - assertEquals('Block count', 2, workspace.getAllBlocks().length); + assertEquals('Block count', 2, workspace.getAllBlocks(false).length); var inputConnection = workspace.getTopBlocks()[0].getInput('NAME').connection; blockNew = helper_createNewBlock(workspace, 'simple_test_block');