mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
@@ -551,6 +551,7 @@ Blockly.tree.BaseNode.prototype.toDom = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates correct padding for each row. Nested categories are indented more.
|
||||
* @return {number} The pixel indent of the row.
|
||||
* @private
|
||||
*/
|
||||
@@ -559,6 +560,7 @@ Blockly.tree.BaseNode.prototype.getPixelIndent_ = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates row with icon and label dom.
|
||||
* @return {!Element} The HTML element for the row.
|
||||
* @protected
|
||||
*/
|
||||
@@ -575,6 +577,8 @@ Blockly.tree.BaseNode.prototype.getRowDom = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the selected class name to the default row class name if node is
|
||||
* selected.
|
||||
* @return {string} The class name for the row.
|
||||
* @protected
|
||||
*/
|
||||
@@ -617,6 +621,7 @@ Blockly.tree.BaseNode.prototype.getCalculatedIconClass = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a string containing the x and y position of the node's background.
|
||||
* @return {string} The background position style value.
|
||||
* @protected
|
||||
*/
|
||||
@@ -707,26 +712,6 @@ Blockly.tree.BaseNode.prototype.updateIcon_ = function() {
|
||||
this.getIconElement().className = this.getCalculatedIconClass();
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles mouse down event.
|
||||
* @param {!Event} e The browser event.
|
||||
* @protected
|
||||
*/
|
||||
Blockly.tree.BaseNode.prototype.onMouseDown = function(e) {
|
||||
var el = e.target;
|
||||
// expand icon
|
||||
var type = el.getAttribute('type');
|
||||
if (type == 'expand' && this.hasChildren()) {
|
||||
if (this.isUserCollapsible_) {
|
||||
this.toggle();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.select();
|
||||
this.updateRow();
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles a click event.
|
||||
* @param {!Event} e The browser event.
|
||||
|
||||
@@ -320,9 +320,6 @@ Blockly.tree.TreeControl.prototype.handleMouseEvent_ = function(e) {
|
||||
var node = this.getNodeFromEvent_(e);
|
||||
if (node) {
|
||||
switch (e.type) {
|
||||
case 'mousedown':
|
||||
node.onMouseDown(e);
|
||||
break;
|
||||
case 'click':
|
||||
node.onClick_(e);
|
||||
break;
|
||||
|
||||
@@ -104,15 +104,6 @@ Blockly.tree.TreeNode.prototype.onClick_ = function(_e) {
|
||||
this.updateRow();
|
||||
};
|
||||
|
||||
/**
|
||||
* Suppress the inherited mouse down behaviour.
|
||||
* @param {!Event} _e The browser event.
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
Blockly.tree.TreeNode.prototype.onMouseDown = function(_e) {
|
||||
// NOP
|
||||
};
|
||||
|
||||
/**
|
||||
* Remap event.keyCode in horizontalLayout so that arrow
|
||||
|
||||
@@ -106,34 +106,35 @@ Blockly.Toolbox = function(workspace) {
|
||||
* @private
|
||||
*/
|
||||
this.flyout_ = null;
|
||||
|
||||
/**
|
||||
* Width of the toolbox, which changes only in vertical layout.
|
||||
* @type {number}
|
||||
*/
|
||||
this.width = 0;
|
||||
|
||||
/**
|
||||
* Height of the toolbox, which changes only in horizontal layout.
|
||||
* @type {number}
|
||||
*/
|
||||
this.height = 0;
|
||||
|
||||
/**
|
||||
* The SVG group currently selected.
|
||||
* @type {SVGGElement}
|
||||
* @private
|
||||
*/
|
||||
this.selectedOption_ = null;
|
||||
|
||||
/**
|
||||
* The tree node most recently selected.
|
||||
* @type {Blockly.tree.BaseNode}
|
||||
* @private
|
||||
*/
|
||||
this.lastCategory_ = null;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Width of the toolbox, which changes only in vertical layout.
|
||||
* @type {number}
|
||||
*/
|
||||
Blockly.Toolbox.prototype.width = 0;
|
||||
|
||||
/**
|
||||
* Height of the toolbox, which changes only in horizontal layout.
|
||||
* @type {number}
|
||||
*/
|
||||
Blockly.Toolbox.prototype.height = 0;
|
||||
|
||||
/**
|
||||
* The SVG group currently selected.
|
||||
* @type {SVGGElement}
|
||||
* @private
|
||||
*/
|
||||
Blockly.Toolbox.prototype.selectedOption_ = null;
|
||||
|
||||
/**
|
||||
* The tree node most recently selected.
|
||||
* @type {Blockly.tree.BaseNode}
|
||||
* @private
|
||||
*/
|
||||
Blockly.Toolbox.prototype.lastCategory_ = null;
|
||||
|
||||
/**
|
||||
* Initializes the toolbox.
|
||||
* @throws {Error} If missing a require for both `Blockly.HorizontalFlyout` and
|
||||
@@ -200,7 +201,6 @@ Blockly.Toolbox.prototype.init = function() {
|
||||
Blockly.utils.dom.insertAfter(this.flyout_.createDom('svg'), svg);
|
||||
this.flyout_.init(workspace);
|
||||
|
||||
this.config_['cleardotPath'] = workspace.options.pathToMedia + '1x1.gif';
|
||||
this.config_['cssCollapsedFolderIcon'] =
|
||||
'blocklyTreeIconClosed' + (workspace.RTL ? 'Rtl' : 'Ltr');
|
||||
this.renderTree(workspace.options.languageTree);
|
||||
@@ -224,12 +224,12 @@ Blockly.Toolbox.prototype.renderTree = function(languageTree) {
|
||||
tree.onAfterSelected(this.handleAfterTreeSelected_);
|
||||
var openNode = null;
|
||||
if (languageTree) {
|
||||
this.tree_.blocks = [];
|
||||
this.tree_.contents = [];
|
||||
this.hasColours_ = false;
|
||||
openNode = this.syncTrees_(
|
||||
languageTree, this.tree_, this.workspace_.options.pathToMedia);
|
||||
|
||||
if (this.tree_.blocks.length) {
|
||||
if (this.tree_.contents.length) {
|
||||
throw Error('Toolbox cannot have both blocks and categories ' +
|
||||
'in the root level.');
|
||||
}
|
||||
@@ -283,22 +283,17 @@ Blockly.Toolbox.prototype.handleBeforeTreeSelected_ = function(node) {
|
||||
*/
|
||||
Blockly.Toolbox.prototype.handleAfterTreeSelected_ = function(
|
||||
oldNode, newNode) {
|
||||
if (newNode && newNode.blocks && newNode.blocks.length) {
|
||||
this.flyout_.show(newNode.blocks);
|
||||
if (newNode && newNode.contents && newNode.contents.length) {
|
||||
this.flyout_.show(newNode.contents);
|
||||
// Scroll the flyout to the top if the category has changed.
|
||||
if (this.lastCategory_ != newNode) {
|
||||
this.flyout_.scrollToStart();
|
||||
}
|
||||
if (this.workspace_.keyboardAccessibilityMode) {
|
||||
Blockly.navigation.setState(Blockly.navigation.STATE_TOOLBOX);
|
||||
}
|
||||
} else if (newNode instanceof Blockly.Toolbox.TreeSeparator){
|
||||
// Do nothing
|
||||
} else {
|
||||
// Hide the flyout.
|
||||
this.flyout_.hide();
|
||||
if (this.workspace_.keyboardAccessibilityMode &&
|
||||
!(newNode instanceof Blockly.Toolbox.TreeSeparator)) {
|
||||
Blockly.navigation.setState(Blockly.navigation.STATE_WS);
|
||||
}
|
||||
}
|
||||
if (oldNode != newNode && oldNode != this) {
|
||||
var event = new Blockly.Events.Ui(null, 'category',
|
||||
@@ -439,12 +434,12 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) {
|
||||
childIn.getAttribute('name'));
|
||||
var childOut = this.tree_.createNode(categoryName);
|
||||
childOut.onSizeChanged(this.handleNodeSizeChanged_);
|
||||
childOut.blocks = [];
|
||||
childOut.contents = [];
|
||||
treeOut.add(childOut);
|
||||
var custom = childIn.getAttribute('custom');
|
||||
if (custom) {
|
||||
// Variables and procedures are special dynamic categories.
|
||||
childOut.blocks = custom;
|
||||
childOut.contents = custom;
|
||||
} else {
|
||||
var newOpenNode = this.syncTrees_(childIn, childOut, pathToMedia);
|
||||
if (newOpenNode) {
|
||||
@@ -466,7 +461,7 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) {
|
||||
}
|
||||
|
||||
if (childIn.getAttribute('expanded') == 'true') {
|
||||
if (childOut.blocks.length) {
|
||||
if (childOut.contents.length) {
|
||||
// This is a category that directly contains blocks.
|
||||
// After the tree is rendered, open this category and show flyout.
|
||||
openNode = childOut;
|
||||
@@ -491,7 +486,7 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) {
|
||||
case 'SHADOW':
|
||||
case 'LABEL':
|
||||
case 'BUTTON':
|
||||
treeOut.blocks.push(childIn);
|
||||
treeOut.contents.push(childIn);
|
||||
lastElement = childIn;
|
||||
break;
|
||||
}
|
||||
@@ -697,8 +692,8 @@ Blockly.Toolbox.prototype.getClientRect = function() {
|
||||
*/
|
||||
Blockly.Toolbox.prototype.refreshSelection = function() {
|
||||
var selectedItem = this.tree_.getSelectedItem();
|
||||
if (selectedItem && selectedItem.blocks) {
|
||||
this.flyout_.show(selectedItem.blocks);
|
||||
if (selectedItem && selectedItem.contents) {
|
||||
this.flyout_.show(selectedItem.contents);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user