Merge pull request #2176 from BeksOmega/fixes/2175

Changed Warnings to Interact Properly with Collapsing/Expanding.
This commit is contained in:
Rachel Fenichel
2018-12-18 11:09:49 -08:00
committed by GitHub
2 changed files with 37 additions and 2 deletions

View File

@@ -140,6 +140,15 @@ Blockly.BlockSvg.prototype.warningTextDb_ = null;
*/
Blockly.BlockSvg.INLINE = -1;
/**
* ID to give the "collapsed warnings" warning. Allows us to remove the
* "collapsed warnings" warning without removing any warnings that belong to
* the block.
* @type {string}
* @const
*/
Blockly.BlockSvg.COLLAPSED_WARNING_ID = 'TEMP_COLLAPSED_WARNING_';
/**
* Create and initialize the SVG representation of the block.
* May be called more than once.
@@ -509,10 +518,30 @@ Blockly.BlockSvg.prototype.setCollapsed = function(collapsed) {
}
var text = this.toString(Blockly.COLLAPSE_CHARS);
this.appendDummyInput(COLLAPSED_INPUT_NAME).appendField(text).init();
// Add any warnings on enclosed blocks to this block.
var descendants = this.getDescendants(true);
var nextBlock = this.getNextBlock();
if (nextBlock) {
var index = descendants.indexOf(nextBlock);
descendants.splice(index, descendants.length - index);
}
for (var i = 1, block; block = descendants[i]; i++) {
if (block.warning) {
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.
this.setWarningText(null);
if (this.warning) {
this.warning.setText('', Blockly.BlockSvg.COLLAPSED_WARNING_ID);
if (!Object.keys(this.warning.text_).length) {
this.setWarningText(null);
}
}
}
Blockly.BlockSvg.superClass_.setCollapsed.call(this, collapsed);
@@ -1035,7 +1064,8 @@ Blockly.BlockSvg.prototype.setWarningText = function(text, opt_id) {
parent = parent.getSurroundParent();
}
if (collapsedParent) {
collapsedParent.setWarningText(text, 'collapsed ' + 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.';