mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-13 06:29:31 -04:00
Merge branch 'feature/variable_management' of https://github.com/google/blockly into feature/variable_management
This commit is contained in:
commit
4b5d4d4c26
31 changed files with 1765 additions and 501 deletions
core
|
@ -151,11 +151,12 @@ Blockly.Toolbox.prototype.lastCategory_ = null;
|
|||
*/
|
||||
Blockly.Toolbox.prototype.init = function() {
|
||||
var workspace = this.workspace_;
|
||||
var svg = this.workspace_.getParentSvg();
|
||||
|
||||
// Create an HTML container for the Toolbox menu.
|
||||
this.HtmlDiv = goog.dom.createDom('div', 'blocklyToolboxDiv');
|
||||
this.HtmlDiv.setAttribute('dir', workspace.RTL ? 'RTL' : 'LTR');
|
||||
document.body.appendChild(this.HtmlDiv);
|
||||
svg.parentNode.insertBefore(this.HtmlDiv, svg);
|
||||
|
||||
// Clicking on toolbox closes popups.
|
||||
Blockly.bindEvent_(this.HtmlDiv, 'mousedown', this,
|
||||
|
@ -241,30 +242,23 @@ Blockly.Toolbox.prototype.position = function() {
|
|||
var svgPosition = goog.style.getPageOffset(svg);
|
||||
var svgSize = Blockly.svgSize(svg);
|
||||
if (this.horizontalLayout_) {
|
||||
treeDiv.style.left = svgPosition.x + 'px';
|
||||
treeDiv.style.left = '0';
|
||||
treeDiv.style.height = 'auto';
|
||||
treeDiv.style.width = svgSize.width + 'px';
|
||||
this.height = treeDiv.offsetHeight;
|
||||
if (this.toolboxPosition == Blockly.TOOLBOX_AT_TOP) { // Top
|
||||
treeDiv.style.top = svgPosition.y + 'px';
|
||||
treeDiv.style.top = '0';
|
||||
} else { // Bottom
|
||||
var topOfToolbox = svgPosition.y + svgSize.height - treeDiv.offsetHeight;
|
||||
treeDiv.style.top = topOfToolbox + 'px';
|
||||
treeDiv.style.bottom = '0';
|
||||
}
|
||||
} else {
|
||||
if (this.toolboxPosition == Blockly.TOOLBOX_AT_RIGHT) { // Right
|
||||
treeDiv.style.left =
|
||||
(svgPosition.x + svgSize.width - treeDiv.offsetWidth) + 'px';
|
||||
treeDiv.style.right = '0';
|
||||
} else { // Left
|
||||
treeDiv.style.left = svgPosition.x + 'px';
|
||||
treeDiv.style.left = '0';
|
||||
}
|
||||
treeDiv.style.height = svgSize.height + 'px';
|
||||
treeDiv.style.top = svgPosition.y + 'px';
|
||||
this.width = treeDiv.offsetWidth;
|
||||
if (this.toolboxPosition == Blockly.TOOLBOX_AT_LEFT) {
|
||||
// For some reason the LTR toolbox now reports as 1px too wide.
|
||||
this.width -= 1;
|
||||
}
|
||||
}
|
||||
this.flyout_.position();
|
||||
};
|
||||
|
@ -357,10 +351,8 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, iconic,
|
|||
// Note that a deprecated method is to add a gap to a block.
|
||||
// <block type="math_arithmetic" gap="8"></block>
|
||||
var newGap = parseFloat(childIn.getAttribute('gap'));
|
||||
if (!isNaN(newGap)) {
|
||||
var oldGap = parseFloat(lastElement.getAttribute('gap'));
|
||||
var gap = isNaN(oldGap) ? newGap : oldGap + newGap;
|
||||
lastElement.setAttribute('gap', gap);
|
||||
if (!isNaN(newGap) && lastElement) {
|
||||
lastElement.setAttribute('gap', newGap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -577,6 +569,7 @@ Blockly.Toolbox.TreeControl.prototype.setSelectedItem = function(node) {
|
|||
Blockly.Toolbox.TreeNode = function(toolbox, html, opt_config, opt_domHelper) {
|
||||
goog.ui.tree.TreeNode.call(this, html, opt_config, opt_domHelper);
|
||||
if (toolbox) {
|
||||
this.horizontalLayout_ = toolbox.horizontalLayout_;
|
||||
var resize = function() {
|
||||
// Even though the div hasn't changed size, the visible workspace
|
||||
// surface of the workspace has, so we may need to reposition everything.
|
||||
|
@ -630,6 +623,28 @@ Blockly.Toolbox.TreeNode.prototype.onDoubleClick_ = function(e) {
|
|||
// NOP.
|
||||
};
|
||||
|
||||
/**
|
||||
* Remap event.keyCode in horizontalLayout so that arrow
|
||||
* keys work properly and call original onKeyDown handler.
|
||||
* @param {!goog.events.BrowserEvent} e The browser event.
|
||||
* @return {boolean} The handled value.
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
Blockly.Toolbox.TreeNode.prototype.onKeyDown = function(e) {
|
||||
if (this.horizontalLayout_) {
|
||||
var map = {};
|
||||
map[goog.events.KeyCodes.RIGHT] = goog.events.KeyCodes.DOWN;
|
||||
map[goog.events.KeyCodes.LEFT] = goog.events.KeyCodes.UP;
|
||||
map[goog.events.KeyCodes.UP] = goog.events.KeyCodes.LEFT;
|
||||
map[goog.events.KeyCodes.DOWN] = goog.events.KeyCodes.RIGHT;
|
||||
|
||||
var newKeyCode = map[e.keyCode];
|
||||
e.keyCode = newKeyCode || e.keyCode;
|
||||
}
|
||||
return Blockly.Toolbox.TreeNode.superClass_.onKeyDown.call(this, e);
|
||||
};
|
||||
|
||||
/**
|
||||
* A blank separator node in the tree.
|
||||
* @param {Object=} config The configuration for the tree. See
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue