mirror of
https://github.com/google/blockly.git
synced 2026-01-11 02:47:09 +01:00
Changed setConnectionsHidden to waitToTrackConnections and startTrackingConnections.
This commit is contained in:
@@ -141,6 +141,7 @@ Blockly.utils.object.inherits(Blockly.BlockSvg, Blockly.Block);
|
||||
* Height is in workspace units.
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.height = 0;
|
||||
|
||||
/**
|
||||
* Width of this block, including any connected value blocks.
|
||||
* Width is in workspace units.
|
||||
@@ -162,6 +163,15 @@ Blockly.BlockSvg.prototype.dragStartXY_ = null;
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.warningTextDb_ = null;
|
||||
|
||||
/**
|
||||
* Should the block tell its connections to start tracking inside the render
|
||||
* method? Or it should it wait for startTrackingConnections to be called
|
||||
* separately?
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.waitToTrackConnections_ = false;
|
||||
|
||||
/**
|
||||
* Constant for identifying rows that are to be rendered inline.
|
||||
* Don't collide with Blockly.INPUT_VALUE and friends.
|
||||
@@ -1437,35 +1447,41 @@ Blockly.BlockSvg.prototype.appendInput_ = function(type, name) {
|
||||
return input;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set whether the connections are hidden (not tracked in a database) or not.
|
||||
* Recursively walk down all child blocks (except collapsed blocks).
|
||||
* @param {boolean} hidden True if connections are hidden.
|
||||
* @package
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.setConnectionsHidden = function(hidden) {
|
||||
if (!hidden && this.isCollapsed()) {
|
||||
if (this.outputConnection) {
|
||||
this.outputConnection.setHidden(hidden);
|
||||
Blockly.BlockSvg.prototype.waitToTrackConnections = function() {
|
||||
this.waitToTrackConnections_ = true;
|
||||
var children = this.getChildren();
|
||||
for (var i = 0, child; child = children[i]; i++) {
|
||||
child.waitToTrackConnections();
|
||||
}
|
||||
};
|
||||
|
||||
Blockly.BlockSvg.prototype.startTrackingConnections = function() {
|
||||
if (this.previousConnection) {
|
||||
this.previousConnection.setHidden(false);
|
||||
}
|
||||
if (this.outputConnection) {
|
||||
this.outputConnection.setHidden(false);
|
||||
}
|
||||
if (this.nextConnection) {
|
||||
this.nextConnection.setHidden(false);
|
||||
var child = this.nextConnection.targetBlock();
|
||||
if (child) {
|
||||
child.startTrackingConnections();
|
||||
}
|
||||
if (this.previousConnection) {
|
||||
this.previousConnection.setHidden(hidden);
|
||||
}
|
||||
if (this.nextConnection) {
|
||||
this.nextConnection.setHidden(hidden);
|
||||
var child = this.nextConnection.targetBlock();
|
||||
if (child) {
|
||||
child.setConnectionsHidden(hidden);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var myConnections = this.getConnections_(true);
|
||||
for (var i = 0, connection; connection = myConnections[i]; i++) {
|
||||
connection.setHidden(hidden);
|
||||
if (connection.isSuperior()) {
|
||||
var child = connection.targetBlock();
|
||||
if (child) {
|
||||
child.setConnectionsHidden(hidden);
|
||||
}
|
||||
|
||||
// If we're collapsed we want the invisible inputs' connections
|
||||
// to remain untracked.
|
||||
if (!this.collapsed_) {
|
||||
for (var i = 0; i < this.inputList.length; i++) {
|
||||
var conn = this.inputList[i].connection;
|
||||
if (conn) {
|
||||
conn.setHidden(false);
|
||||
|
||||
// Pass tracking on down the chain.
|
||||
var block = conn.targetBlock();
|
||||
if (block) {
|
||||
block.startTrackingConnections();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1616,6 +1632,9 @@ Blockly.BlockSvg.prototype.render = function(opt_bubble) {
|
||||
(/** @type {!Blockly.WorkspaceSvg} */ (this.workspace)).getRenderer().render(this);
|
||||
// No matter how we rendered, connection locations should now be correct.
|
||||
this.updateConnectionLocations_();
|
||||
if (!this.waitToTrackConnections_) {
|
||||
this.startTrackingConnections();
|
||||
}
|
||||
if (opt_bubble !== false) {
|
||||
// Render all blocks above this one (propagate a reflow).
|
||||
var parentBlock = this.getParent();
|
||||
|
||||
@@ -550,8 +550,8 @@ Blockly.Xml.domToBlock = function(xmlBlock, workspace) {
|
||||
// Generate list of all blocks.
|
||||
var blocks = topBlock.getDescendants(false);
|
||||
if (workspace.rendered) {
|
||||
// Hide connections to speed up assembly.
|
||||
topBlock.setConnectionsHidden(true);
|
||||
// Wait to track connections to speed up assembly.
|
||||
topBlock.waitToTrackConnections();
|
||||
// Render each block.
|
||||
for (var i = blocks.length - 1; i >= 0; i--) {
|
||||
blocks[i].initSvg();
|
||||
@@ -562,8 +562,8 @@ Blockly.Xml.domToBlock = function(xmlBlock, workspace) {
|
||||
// Populating the connection database may be deferred until after the
|
||||
// blocks have rendered.
|
||||
setTimeout(function() {
|
||||
if (topBlock.workspace) { // Check that the block hasn't been deleted.
|
||||
topBlock.setConnectionsHidden(false);
|
||||
if (!topBlock.disposed) { // Check that the block hasn't been deleted.
|
||||
topBlock.startTrackingConnections();
|
||||
}
|
||||
}, 1);
|
||||
topBlock.updateDisabled();
|
||||
|
||||
Reference in New Issue
Block a user