Commit 383ca825 authored by Neil Fraser's avatar Neil Fraser

Fix toolbar with both colours and subcategories.

Also fix updating of toolbar after loading Blockly.
parent e5dfdf46
This diff is collapsed.
...@@ -136,12 +136,9 @@ Blockly.Toolbox.prototype.init = function() { ...@@ -136,12 +136,9 @@ Blockly.Toolbox.prototype.init = function() {
tree.setShowLines(false); tree.setShowLines(false);
tree.setShowExpandIcons(false); tree.setShowExpandIcons(false);
tree.setSelectedItem(null); tree.setSelectedItem(null);
this.hasColours_ = false;
this.populate_(workspace.options.languageTree); this.populate_(workspace.options.languageTree);
tree.render(this.HtmlDiv); tree.render(this.HtmlDiv);
if (this.hasColours_) { this.addColour_();
this.addColour_(tree);
}
this.position(); this.position();
}; };
...@@ -224,12 +221,15 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) { ...@@ -224,12 +221,15 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) {
rootOut.setSelectedItem(childOut); rootOut.setSelectedItem(childOut);
} }
childOut.setExpanded(true); childOut.setExpanded(true);
} else {
childOut.setExpanded(false);
} }
break; break;
case 'SEP': case 'SEP':
treeOut.add(new Blockly.Toolbox.TreeSeparator()); treeOut.add(new Blockly.Toolbox.TreeSeparator());
break; break;
case 'BLOCK': case 'BLOCK':
case 'SHADOW':
treeOut.blocks.push(childIn); treeOut.blocks.push(childIn);
break; break;
} }
...@@ -248,15 +248,21 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) { ...@@ -248,15 +248,21 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) {
/** /**
* Recursively add colours to this toolbox. * Recursively add colours to this toolbox.
* @param {!Blockly.Toolbox.TreeNode} * @param {Blockly.Toolbox.TreeNode} opt_tree Starting point of tree.
* Defaults to the root node.
* @private * @private
*/ */
Blockly.Toolbox.prototype.addColour_ = function(tree) { Blockly.Toolbox.prototype.addColour_ = function(opt_tree) {
var tree = opt_tree || this.tree_;
var children = tree.getChildren(); var children = tree.getChildren();
for (var i = 0, child; child = children[i]; i++) { for (var i = 0, child; child = children[i]; i++) {
var element = child.getRowElement(); var element = child.getRowElement();
if (element) { if (element) {
var border = '8px solid ' + (child.hexColour || '#ddd'); if (this.hasColours_) {
var border = '8px solid ' + (child.hexColour || '#ddd');
} else {
var border = 'none';
}
if (this.workspace_.RTL) { if (this.workspace_.RTL) {
element.style.borderRight = border; element.style.borderRight = border;
} else { } else {
......
...@@ -854,6 +854,7 @@ Blockly.WorkspaceSvg.prototype.updateToolbox = function(tree) { ...@@ -854,6 +854,7 @@ Blockly.WorkspaceSvg.prototype.updateToolbox = function(tree) {
} }
this.options.languageTree = tree; this.options.languageTree = tree;
this.toolbox_.populate_(tree); this.toolbox_.populate_(tree);
this.toolbox_.addColour_();
} else { } else {
if (!this.flyout_) { if (!this.flyout_) {
throw 'Existing toolbox has categories. Can\'t change mode.'; throw 'Existing toolbox has categories. Can\'t change mode.';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment