Skip to content
Snippets Groups Projects
Commit b4a0b5f8 authored by Eric Rosenbaum's avatar Eric Rosenbaum
Browse files

Use a more public way of set selected category

parent 158e9119
No related branches found
No related tags found
No related merge requests found
...@@ -76,14 +76,11 @@ class Blocks extends React.Component { ...@@ -76,14 +76,11 @@ class Blocks extends React.Component {
if (prevProps.toolboxXML !== this.props.toolboxXML) { if (prevProps.toolboxXML !== this.props.toolboxXML) {
const selectedCategoryName = this.workspace.toolbox_.getSelectedItem().name_; const selectedCategoryName = this.workspace.toolbox_.getSelectedItem().name_;
this.workspace.updateToolbox(this.props.toolboxXML); this.workspace.updateToolbox(this.props.toolboxXML);
// Blockly throws if we don't select a category after updating the toolbox. this.workspace.toolbox_.setSelectedCategoryByName(selectedCategoryName);
/** @TODO Find a way to avoid the exception without accessing private properties. */
this.setToolboxSelectedItemByName(selectedCategoryName);
} }
if (this.props.isVisible === prevProps.isVisible) { if (this.props.isVisible === prevProps.isVisible) {
return; return;
} }
// @todo hack to resize blockly manually in case resize happened while hidden // @todo hack to resize blockly manually in case resize happened while hidden
// @todo hack to reload the workspace due to gui bug #413 // @todo hack to reload the workspace due to gui bug #413
if (this.props.isVisible) { // Scripts tab if (this.props.isVisible) { // Scripts tab
...@@ -99,20 +96,6 @@ class Blocks extends React.Component { ...@@ -99,20 +96,6 @@ class Blocks extends React.Component {
this.detachVM(); this.detachVM();
this.workspace.dispose(); this.workspace.dispose();
} }
/**
* Select a particular category in the toolbox by specifying the category name.
* This is a workaround for a bug: @see {@link componentDidUpdate} above.
* @TODO Remove this or reimplement using only public APIs.
* @param {string} name - the name of the category to select.
*/
setToolboxSelectedItemByName (name) {
const categories = this.workspace.toolbox_.categoryMenu_.categories_;
for (let i = 0; i < categories.length; i++) {
if (categories[i].name_ === name) {
this.workspace.toolbox_.setSelectedItem(categories[i]);
}
}
}
attachVM () { attachVM () {
this.workspace.addChangeListener(this.props.vm.blockListener); this.workspace.addChangeListener(this.props.vm.blockListener);
this.flyoutWorkspace = this.workspace this.flyoutWorkspace = this.workspace
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment