mirror of
https://github.com/google/blockly.git
synced 2026-01-11 02:47:09 +01:00
Fix toolbar with both colours and subcategories.
Also fix updating of toolbar after loading Blockly.
This commit is contained in:
@@ -136,12 +136,9 @@ Blockly.Toolbox.prototype.init = function() {
|
||||
tree.setShowLines(false);
|
||||
tree.setShowExpandIcons(false);
|
||||
tree.setSelectedItem(null);
|
||||
this.hasColours_ = false;
|
||||
this.populate_(workspace.options.languageTree);
|
||||
tree.render(this.HtmlDiv);
|
||||
if (this.hasColours_) {
|
||||
this.addColour_(tree);
|
||||
}
|
||||
this.addColour_();
|
||||
this.position();
|
||||
};
|
||||
|
||||
@@ -224,12 +221,15 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) {
|
||||
rootOut.setSelectedItem(childOut);
|
||||
}
|
||||
childOut.setExpanded(true);
|
||||
} else {
|
||||
childOut.setExpanded(false);
|
||||
}
|
||||
break;
|
||||
case 'SEP':
|
||||
treeOut.add(new Blockly.Toolbox.TreeSeparator());
|
||||
break;
|
||||
case 'BLOCK':
|
||||
case 'SHADOW':
|
||||
treeOut.blocks.push(childIn);
|
||||
break;
|
||||
}
|
||||
@@ -248,15 +248,21 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
Blockly.Toolbox.prototype.addColour_ = function(tree) {
|
||||
Blockly.Toolbox.prototype.addColour_ = function(opt_tree) {
|
||||
var tree = opt_tree || this.tree_;
|
||||
var children = tree.getChildren();
|
||||
for (var i = 0, child; child = children[i]; i++) {
|
||||
var element = child.getRowElement();
|
||||
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) {
|
||||
element.style.borderRight = border;
|
||||
} else {
|
||||
|
||||
@@ -854,6 +854,7 @@ Blockly.WorkspaceSvg.prototype.updateToolbox = function(tree) {
|
||||
}
|
||||
this.options.languageTree = tree;
|
||||
this.toolbox_.populate_(tree);
|
||||
this.toolbox_.addColour_();
|
||||
} else {
|
||||
if (!this.flyout_) {
|
||||
throw 'Existing toolbox has categories. Can\'t change mode.';
|
||||
|
||||
Reference in New Issue
Block a user