Changed parent blocks to display "Collapsed blocks contain warnings." instead of having warnings "bubble up" from children. Added message to msg/messages.js .

This commit is contained in:
Beka Westberg
2018-12-17 14:54:56 -08:00
parent f16cdf912d
commit 44df2d4680
2 changed files with 13 additions and 15 deletions

View File

@@ -147,7 +147,7 @@ Blockly.BlockSvg.INLINE = -1;
* @type {string}
* @const
*/
Blockly.BlockSvg.COLLAPSED_WARNING = 'TEMP_COLLAPSED_WARNING_';
Blockly.BlockSvg.COLLAPSED_WARNING_ID = 'TEMP_COLLAPSED_WARNING_';
/**
* Create and initialize the SVG representation of the block.
@@ -528,24 +528,17 @@ Blockly.BlockSvg.prototype.setCollapsed = function(collapsed) {
}
for (var i = 1, block; block = descendants[i]; i++) {
if (block.warning) {
this.setWarningText(block.warning.getText(),
Blockly.BlockSvg.COLLAPSED_WARNING + i);
this.setWarningText(Blockly.Msg['COLLAPSED_WARNINGS_WARNING'],
Blockly.BlockSvg.COLLAPSED_WARNING_ID);
break;
}
}
} else {
this.removeInput(COLLAPSED_INPUT_NAME);
// Clear any warnings inherited from enclosed blocks.
if (this.warning) {
var keys = Object.keys(this.warning.text_);
var warningsDeleted = 0;
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (key.indexOf(Blockly.BlockSvg.COLLAPSED_WARNING) != -1) {
this.warning.setText('', key);
warningsDeleted++;
}
}
if (warningsDeleted == keys.length) {
this.warning.setText('', Blockly.BlockSvg.COLLAPSED_WARNING_ID);
if (!Object.keys(this.warning.text_).length) {
this.setWarningText(null);
}
}
@@ -1071,8 +1064,8 @@ Blockly.BlockSvg.prototype.setWarningText = function(text, opt_id) {
parent = parent.getSurroundParent();
}
if (collapsedParent) {
collapsedParent.setWarningText(text,
Blockly.BlockSvg.COLLAPSED_WARNING + this.id + ' ' + id);
collapsedParent.setWarningText(Blockly.Msg['COLLAPSED_WARNINGS_WARNING'],
Blockly.BlockSvg.COLLAPSED_WARNING_ID);
}
var changedState = false;

View File

@@ -1206,3 +1206,8 @@ Blockly.Msg.PROCEDURES_IFRETURN_WARNING = 'Warning: This block may be used only
/// comment text - This text appears in a new workspace comment, to hint that
/// the user can type here.
Blockly.Msg.WORKSPACE_COMMENT_DEFAULT_TEXT = 'Say something...';
/// warning - This appears if the user collapses a block, and blocks inside
// that block have warnings attached to them. It should inform the user that the
// block they collapsed contains blocks that have warnings.
Blockly.Msg.COLLAPSED_WARNINGS_WARNING = 'Collapsed blocks contain warnings.';