Commit e8ab929b authored by Neil Fraser's avatar Neil Fraser

Fix visibility changes with toolbox.

parent 37eff10f
This diff is collapsed.
...@@ -180,30 +180,28 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) { ...@@ -180,30 +180,28 @@ Blockly.Toolbox.prototype.populate_ = function(newTree) {
// Skip over text. // Skip over text.
continue; continue;
} }
var name = childIn.tagName.toUpperCase(); switch (childIn.tagName.toUpperCase()) {
if (name == 'CATEGORY') { case 'CATEGORY':
var childOut = rootOut.createNode(childIn.getAttribute('name')); var childOut = rootOut.createNode(childIn.getAttribute('name'));
childOut.blocks = []; childOut.blocks = [];
if (childIn.getAttribute('expanded') == 'true') { if (childIn.getAttribute('expanded') == 'true') {
childOut.setExpanded(true); childOut.setExpanded(true);
} }
treeOut.add(childOut); treeOut.add(childOut);
var custom = childIn.getAttribute('custom'); var custom = childIn.getAttribute('custom');
if (custom) { if (custom) {
// Variables and procedures have special categories that are dynamic. // Variables and procedures are special dynamic categories.
childOut.blocks = custom; childOut.blocks = custom;
} else { } else {
syncTrees(childIn, childOut); syncTrees(childIn, childOut);
} }
} else if (name == 'HR') { break;
// <hr> tag is deprecated, use <sep></sep> instead. case 'SEP':
// https://github.com/google/blockly/issues/50 treeOut.add(new Blockly.Toolbox.TreeSeparator());
console.warn('The <hr> separator tag in the toolbox XML needs to be ' + break;
'changed to <sep></sep> (due to a bug in IE).'); case 'BLOCK':
} else if (name == 'SEP') { treeOut.blocks.push(childIn);
treeOut.add(new Blockly.Toolbox.TreeSeparator()); break;
} else if (name == 'BLOCK') {
treeOut.blocks.push(childIn);
} }
} }
} }
......
...@@ -214,3 +214,6 @@ Blockly.Workspace.prototype.updateToolbox = function(tree) { ...@@ -214,3 +214,6 @@ Blockly.Workspace.prototype.updateToolbox = function(tree) {
this.flyout_.show(tree.childNodes); this.flyout_.show(tree.childNodes);
} }
}; };
// Export symbols that would otherwise be renamed by Closure compiler.
Blockly.Workspace.prototype['clear'] = Blockly.Workspace.prototype.clear;
...@@ -278,6 +278,27 @@ Blockly.WorkspaceSvg.prototype.getWidth = function() { ...@@ -278,6 +278,27 @@ Blockly.WorkspaceSvg.prototype.getWidth = function() {
return this.getMetrics().viewWidth; return this.getMetrics().viewWidth;
}; };
/**
* Toggles the visibility of the workspace.
* Currently only intended for main workspace.
* @param {boolean} isVisible True if workspace should be visible.
*/
Blockly.WorkspaceSvg.prototype.setVisible = function(isVisible) {
this.options.svg.style.display = isVisible ? 'block' : 'none';
if (this.toolbox_) {
// Currently does not support toolboxes in mutators.
this.toolbox_.HtmlDiv.style.display = isVisible ? 'block' : 'none';
}
if (isVisible) {
this.render();
if (this.toolbox_) {
this.toolbox_.position();
}
} else {
Blockly.hideChaff(true);
}
};
/** /**
* Render all blocks in workspace. * Render all blocks in workspace.
*/ */
...@@ -657,7 +678,8 @@ Blockly.WorkspaceSvg.prototype.markFocused = function() { ...@@ -657,7 +678,8 @@ Blockly.WorkspaceSvg.prototype.markFocused = function() {
}; };
// Export symbols that would otherwise be renamed by Closure compiler. // Export symbols that would otherwise be renamed by Closure compiler.
Blockly.WorkspaceSvg.prototype['clear'] = Blockly.WorkspaceSvg.prototype.clear; Blockly.WorkspaceSvg.prototype['setVisible'] =
Blockly.WorkspaceSvg.prototype.setVisible;
Blockly.WorkspaceSvg.prototype['addChangeListener'] = Blockly.WorkspaceSvg.prototype['addChangeListener'] =
Blockly.WorkspaceSvg.prototype.addChangeListener; Blockly.WorkspaceSvg.prototype.addChangeListener;
Blockly.WorkspaceSvg.prototype['removeChangeListener'] = Blockly.WorkspaceSvg.prototype['removeChangeListener'] =
......
...@@ -273,6 +273,9 @@ Code.tabClick = function(clickedName) { ...@@ -273,6 +273,9 @@ Code.tabClick = function(clickedName) {
} }
} }
if (document.getElementById('tab_blocks').className == 'tabon') {
Code.workspace.setVisible(false);
}
// Deselect all tabs and hide all panes. // Deselect all tabs and hide all panes.
for (var i = 0; i < Code.TABS_.length; i++) { for (var i = 0; i < Code.TABS_.length; i++) {
var name = Code.TABS_[i]; var name = Code.TABS_[i];
...@@ -287,6 +290,9 @@ Code.tabClick = function(clickedName) { ...@@ -287,6 +290,9 @@ Code.tabClick = function(clickedName) {
document.getElementById('content_' + clickedName).style.visibility = document.getElementById('content_' + clickedName).style.visibility =
'visible'; 'visible';
Code.renderContent(); Code.renderContent();
if (clickedName == 'blocks') {
Code.workspace.setVisible(true);
}
Blockly.fireUiEvent(window, 'resize'); Blockly.fireUiEvent(window, 'resize');
}; };
...@@ -417,7 +423,7 @@ Code.init = function() { ...@@ -417,7 +423,7 @@ Code.init = function() {
Code.initLanguage = function() { Code.initLanguage = function() {
// Set the HTML's language and direction. // Set the HTML's language and direction.
var rtl = Code.isRtl(); var rtl = Code.isRtl();
document.head.parentElement.setAttribute('dir', rtl ? 'rtl' : 'ltr'); document.dir = rtl ? 'rtl' : 'ltr';
document.head.parentElement.setAttribute('lang', Code.LANG); document.head.parentElement.setAttribute('lang', Code.LANG);
// Sort languages alphabetically. // Sort languages alphabetically.
......
...@@ -418,8 +418,8 @@ h1 { ...@@ -418,8 +418,8 @@ h1 {
<h1>Blockly Playground</h1> <h1>Blockly Playground</h1>
<p><a href="javascript:void([document.getElementById('blocklyDiv').style.display = 'block', workspace.render()])">Show</a> <p><a href="javascript:void(workspace.setVisible(true))">Show</a>
- <a href="javascript:void(document.getElementById('blocklyDiv').style.display = 'none')">Hide</a></p> - <a href="javascript:void(workspace.setVisible(false))">Hide</a></p>
<script> <script>
if (rtl) { if (rtl) {
......
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