mirror of
https://github.com/google/blockly.git
synced 2026-01-21 07:47:09 +01:00
Allow flights to be initially expanded in toolbox.
This commit is contained in:
@@ -195,9 +195,6 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) {
|
||||
case 'CATEGORY':
|
||||
var childOut = rootOut.createNode(childIn.getAttribute('name'));
|
||||
childOut.blocks = [];
|
||||
if (childIn.getAttribute('expanded') == 'true') {
|
||||
childOut.setExpanded(true);
|
||||
}
|
||||
treeOut.add(childOut);
|
||||
var custom = childIn.getAttribute('custom');
|
||||
if (custom) {
|
||||
@@ -206,6 +203,12 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) {
|
||||
} else {
|
||||
syncTrees(childIn, childOut);
|
||||
}
|
||||
if (childIn.getAttribute('expanded') == 'true') {
|
||||
if (childOut.blocks.length) {
|
||||
rootOut.setSelectedItem(childOut);
|
||||
}
|
||||
childOut.setExpanded(true);
|
||||
}
|
||||
break;
|
||||
case 'SEP':
|
||||
treeOut.add(new Blockly.Toolbox.TreeSeparator());
|
||||
|
||||
@@ -184,36 +184,5 @@ Blockly.Workspace.prototype.fireChangeEvent = function() {
|
||||
// NOP.
|
||||
};
|
||||
|
||||
/**
|
||||
* Modify the block tree on the existing toolbox.
|
||||
* @param {Node|string} tree DOM tree of blocks, or text representation of same.
|
||||
*/
|
||||
Blockly.Workspace.prototype.updateToolbox = function(tree) {
|
||||
tree = Blockly.parseToolboxTree_(tree);
|
||||
if (!tree) {
|
||||
if (this.options.languageTree) {
|
||||
throw 'Can\'t nullify an existing toolbox.';
|
||||
}
|
||||
// No change (null to null).
|
||||
return;
|
||||
}
|
||||
if (!this.options.languageTree) {
|
||||
throw 'Existing toolbox is null. Can\'t create new toolbox.';
|
||||
}
|
||||
if (this.options.hasCategories) {
|
||||
if (!this.toolbox_) {
|
||||
throw 'Existing toolbox has no categories. Can\'t change mode.';
|
||||
}
|
||||
this.options.languageTree = tree;
|
||||
this.toolbox_.populate_(tree);
|
||||
} else {
|
||||
if (!this.flyout_) {
|
||||
throw 'Existing toolbox has categories. Can\'t change mode.';
|
||||
}
|
||||
this.options.languageTree = tree;
|
||||
this.flyout_.show(tree.childNodes);
|
||||
}
|
||||
};
|
||||
|
||||
// Export symbols that would otherwise be renamed by Closure compiler.
|
||||
Blockly.Workspace.prototype['clear'] = Blockly.Workspace.prototype.clear;
|
||||
|
||||
@@ -655,6 +655,37 @@ Blockly.WorkspaceSvg.prototype.playAudio = function(name, opt_volume) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Modify the block tree on the existing toolbox.
|
||||
* @param {Node|string} tree DOM tree of blocks, or text representation of same.
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.updateToolbox = function(tree) {
|
||||
tree = Blockly.parseToolboxTree_(tree);
|
||||
if (!tree) {
|
||||
if (this.options.languageTree) {
|
||||
throw 'Can\'t nullify an existing toolbox.';
|
||||
}
|
||||
// No change (null to null).
|
||||
return;
|
||||
}
|
||||
if (!this.options.languageTree) {
|
||||
throw 'Existing toolbox is null. Can\'t create new toolbox.';
|
||||
}
|
||||
if (this.options.hasCategories) {
|
||||
if (!this.toolbox_) {
|
||||
throw 'Existing toolbox has no categories. Can\'t change mode.';
|
||||
}
|
||||
this.options.languageTree = tree;
|
||||
this.toolbox_.populate_(tree);
|
||||
} else {
|
||||
if (!this.flyout_) {
|
||||
throw 'Existing toolbox has categories. Can\'t change mode.';
|
||||
}
|
||||
this.options.languageTree = tree;
|
||||
this.flyout_.show(tree.childNodes);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* When something in this workspace changes, call a function.
|
||||
* @param {!Function} func Function to call.
|
||||
|
||||
Reference in New Issue
Block a user