Misc compiler warnings. (#3172)

* Fix misc compiler warnings. Use ws.getToolbox() instead of ws.toolbox_
This commit is contained in:
Sam El-Husseini
2019-10-07 11:06:56 -07:00
committed by GitHub
parent 608ce7b93c
commit 2ac4149d98
18 changed files with 62 additions and 59 deletions

View File

@@ -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;

View File

@@ -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();
}
}
};

View File

@@ -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
*/

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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());

View File

@@ -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;
};
/**

View File

@@ -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.

View File

@@ -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.
}
};

View File

@@ -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());
}

View File

@@ -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;
}
</script>

View File

@@ -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();
}

View File

@@ -142,7 +142,7 @@ function test_domToWorkspace_BackwardCompatibility() {
' </block>' +
'</xml>');
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() {
' </block>' +
'</xml>');
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() {
'</xml>');
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;

View File

@@ -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() {

View File

@@ -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');

View File

@@ -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);

View File

@@ -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() {
' </block>' +
'</xml>');
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() {
'</xml>');
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');