From 3998ecec3af164bca19469680c9b748611e26377 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 9 Aug 2016 16:34:59 -0700 Subject: [PATCH 1/2] Parse separators in xml in always-open flyouts --- core/flyout.js | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/core/flyout.js b/core/flyout.js index 0484b53fc..a216e60f5 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -637,18 +637,37 @@ Blockly.Flyout.prototype.show = function(xmlList) { // Create the blocks to be shown in this flyout. var blocks = []; var gaps = []; + var lastBlock = null; this.permanentlyDisabled_.length = 0; for (var i = 0, xml; xml = xmlList[i]; i++) { - if (xml.tagName && xml.tagName.toUpperCase() == 'BLOCK') { - var curBlock = Blockly.Xml.domToBlock(xml, this.workspace_); - if (curBlock.disabled) { - // Record blocks that were initially disabled. - // Do not enable these blocks as a result of capacity filtering. - this.permanentlyDisabled_.push(curBlock); + if (xml.tagName) { + if (xml.tagName.toUpperCase() == 'BLOCK') { + lastBlock = xml; + var curBlock = Blockly.Xml.domToBlock(xml, this.workspace_); + if (curBlock.disabled) { + // Record blocks that were initially disabled. + // Do not enable these blocks as a result of capacity filtering. + this.permanentlyDisabled_.push(curBlock); + } + blocks.push(curBlock); + var gap = parseInt(xml.getAttribute('gap'), 10); + gaps.push(isNaN(gap) ? this.MARGIN * 3 : gap); + } else if (xml.tagName.toUpperCase() == 'SEP') { + // Change the gap between two blocks. + // + // The default gap is 24, can be set larger or smaller. + // Note that a deprecated method is to add a gap to a block. + // + var newGap = parseInt(xml.getAttribute('gap'), 10); + // Ignore gaps before the first block. + if (!isNaN(newGap) && lastBlock) { + var oldGap = parseInt(lastBlock.getAttribute('gap')); + var gap = isNaN(oldGap) ? newGap : oldGap + newGap; + gaps[gaps.length - 1] = gap; + } else { + gaps.push(this.MARGIN * 3); + } } - blocks.push(curBlock); - var gap = parseInt(xml.getAttribute('gap'), 10); - gaps.push(isNaN(gap) ? this.MARGIN * 3 : gap); } } From dc02dfb8ff4a9a45cb2c7a1ecc59f0193922f4c4 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 9 Aug 2016 17:51:50 -0700 Subject: [PATCH 2/2] Separators specified in toolbox XML should replace, not add to, previous gaps. --- core/flyout.js | 9 +++------ core/toolbox.js | 6 ++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/core/flyout.js b/core/flyout.js index a216e60f5..07dfe2ce6 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -637,12 +637,10 @@ Blockly.Flyout.prototype.show = function(xmlList) { // Create the blocks to be shown in this flyout. var blocks = []; var gaps = []; - var lastBlock = null; this.permanentlyDisabled_.length = 0; for (var i = 0, xml; xml = xmlList[i]; i++) { if (xml.tagName) { if (xml.tagName.toUpperCase() == 'BLOCK') { - lastBlock = xml; var curBlock = Blockly.Xml.domToBlock(xml, this.workspace_); if (curBlock.disabled) { // Record blocks that were initially disabled. @@ -656,14 +654,13 @@ Blockly.Flyout.prototype.show = function(xmlList) { // Change the gap between two blocks. // // 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. // var newGap = parseInt(xml.getAttribute('gap'), 10); // Ignore gaps before the first block. - if (!isNaN(newGap) && lastBlock) { - var oldGap = parseInt(lastBlock.getAttribute('gap')); - var gap = isNaN(oldGap) ? newGap : oldGap + newGap; - gaps[gaps.length - 1] = gap; + if (!isNaN(newGap) && gaps.length > 0) { + gaps[gaps.length - 1] = newGap; } else { gaps.push(this.MARGIN * 3); } diff --git a/core/toolbox.js b/core/toolbox.js index 421a1af8e..db3ba63a2 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -333,10 +333,8 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) { // Note that a deprecated method is to add a gap to a block. // var newGap = parseFloat(childIn.getAttribute('gap')); - if (!isNaN(newGap)) { - var oldGap = parseFloat(lastElement.getAttribute('gap')); - var gap = isNaN(oldGap) ? newGap : oldGap + newGap; - lastElement.setAttribute('gap', gap); + if (!isNaN(newGap) && lastElement) { + lastElement.setAttribute('gap', newGap); } } }