Changed buttons and labels to respect <sep> elements in toolbox. (#2395)

This commit is contained in:
Beka Westberg
2019-04-22 12:23:04 -07:00
committed by RoboErikG
parent bc49f29015
commit 9a9c6612f8
2 changed files with 25 additions and 30 deletions

View File

@@ -447,11 +447,13 @@ Blockly.Flyout.prototype.show = function(xmlList) {
var contents = [];
var gaps = [];
this.permanentlyDisabled_.length = 0;
var default_gap = this.horizontalLayout_ ? this.GAP_X : this.GAP_Y;
for (var i = 0, xml; xml = xmlList[i]; i++) {
if (xml.tagName) {
var tagName = xml.tagName.toUpperCase();
var default_gap = this.horizontalLayout_ ? this.GAP_X : this.GAP_Y;
if (tagName == 'BLOCK') {
if (!xml.tagName) {
continue;
}
switch (xml.tagName.toUpperCase()) {
case 'BLOCK':
var curBlock = Blockly.Xml.domToBlock(xml, this.workspace_);
if (curBlock.disabled) {
// Record blocks that were initially disabled.
@@ -459,15 +461,16 @@ Blockly.Flyout.prototype.show = function(xmlList) {
this.permanentlyDisabled_.push(curBlock);
}
contents.push({type: 'block', block: curBlock});
// This is a deprecated method for adding gap to a block.
// <block type="math_arithmetic" gap="8"></block>
var gap = parseInt(xml.getAttribute('gap'), 10);
gaps.push(isNaN(gap) ? default_gap : gap);
} else if (xml.tagName.toUpperCase() == 'SEP') {
// Change the gap between two blocks.
break;
case 'SEP':
// Change the gap between two toolbox elements.
// <sep gap="36"></sep>
// The default gap is 24, can be set larger or smaller.
// This overwrites the gap attribute on the previous block.
// Note that a deprecated method is to add a gap to a block.
// <block type="math_arithmetic" gap="8"></block>
// This overwrites the gap attribute on the previous element.
var newGap = parseInt(xml.getAttribute('gap'), 10);
// Ignore gaps before the first block.
if (!isNaN(newGap) && gaps.length > 0) {
@@ -475,14 +478,17 @@ Blockly.Flyout.prototype.show = function(xmlList) {
} else {
gaps.push(default_gap);
}
} else if (tagName == 'BUTTON' || tagName == 'LABEL') {
break;
case 'LABEL':
// Labels behave the same as buttons, but are styled differently.
var isLabel = tagName == 'LABEL';
var isLabel = true;
// Falls through.
case 'BUTTON':
var curButton = new Blockly.FlyoutButton(this.workspace_,
this.targetWorkspace_, xml, isLabel);
contents.push({type: 'button', button: curButton});
gaps.push(default_gap);
}
break;
}
}

View File

@@ -359,25 +359,14 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) {
lastElement = childIn;
break;
case 'SEP':
if (lastElement) {
if (lastElement.tagName.toUpperCase() == 'CATEGORY') {
// Separator between two categories.
// <sep></sep>
treeOut.add(new Blockly.Toolbox.TreeSeparator(
this.treeSeparatorConfig_));
} else {
// Change the gap between two blocks.
// <sep gap="36"></sep>
// The default gap is 24, can be set larger or smaller.
// Note that a deprecated method is to add a gap to a block.
// <block type="math_arithmetic" gap="8"></block>
var newGap = parseFloat(childIn.getAttribute('gap'));
if (!isNaN(newGap) && lastElement) {
lastElement.setAttribute('gap', newGap);
}
}
if (lastElement && lastElement.tagName.toUpperCase() == 'CATEGORY') {
// Separator between two categories.
// <sep></sep>
treeOut.add(new Blockly.Toolbox.TreeSeparator(
this.treeSeparatorConfig_));
break;
}
break;
// Otherwise falls through.
case 'BLOCK':
case 'SHADOW':
case 'LABEL':