mirror of
https://github.com/google/blockly.git
synced 2026-01-08 09:30:06 +01:00
Fixed programmatically added connections not being added to the connection db (#3318)
* Fixed programmatically added connections not getting added to the connection db.
This commit is contained in:
committed by
Sam El-Husseini
parent
942068314f
commit
c32c835088
@@ -140,14 +140,6 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
|
||||
* @private
|
||||
*/
|
||||
this.markerSvg_ = null;
|
||||
|
||||
/**
|
||||
* Should the block tell its connections to start tracking inside the render
|
||||
* method?
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.callTrackConnections_ = true;
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.BlockSvg, Blockly.Block);
|
||||
|
||||
@@ -1525,58 +1517,45 @@ Blockly.BlockSvg.prototype.appendInput_ = function(type, name) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Tell the block to wait for an outside source to call
|
||||
* startTrackingConnections, rather than starting connection
|
||||
* tracking automatically.
|
||||
* Sets whether this block's connections are tracked in the database or not.
|
||||
*
|
||||
* Also tells children of this block to wait.
|
||||
* Used by the deserializer to be more efficient. Setting a connection's
|
||||
* tracked_ value to false keeps it from adding itself to the db when it
|
||||
* gets its first moveTo call, saving expensive ops for later.
|
||||
* @param {boolean} track If true, start tracking. If false, stop tracking.
|
||||
* @package
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.waitToTrackConnections = function() {
|
||||
this.callTrackConnections_ = false;
|
||||
var children = this.getChildren(false);
|
||||
for (var i = 0, child; child = children[i]; i++) {
|
||||
child.waitToTrackConnections();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Tell this block's connections to add themselves to the connection
|
||||
* database (i.e. start tracking).
|
||||
*
|
||||
* All following/next blocks will be told to start tracking. Inner blocks
|
||||
* (i.e. blocks attached to value/statement inputs) will be told to start
|
||||
* tracking if this block is not collapsed.
|
||||
* @package
|
||||
*/
|
||||
Blockly.BlockSvg.prototype.startTrackingConnections = function() {
|
||||
Blockly.BlockSvg.prototype.setConnectionTracking = function(track) {
|
||||
if (this.previousConnection) {
|
||||
this.previousConnection.setTracking(true);
|
||||
this.previousConnection.setTracking(track);
|
||||
}
|
||||
if (this.outputConnection) {
|
||||
this.outputConnection.setTracking(true);
|
||||
this.outputConnection.setTracking(track);
|
||||
}
|
||||
if (this.nextConnection) {
|
||||
this.nextConnection.setTracking(true);
|
||||
this.nextConnection.setTracking(track);
|
||||
var child = this.nextConnection.targetBlock();
|
||||
if (child) {
|
||||
child.startTrackingConnections();
|
||||
child.setConnectionTracking(track);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.collapsed_) {
|
||||
// When track is true, we don't want to start tracking collapsed
|
||||
// connections. When track is false, we're already not tracking
|
||||
// collapsed connections, so no need to update.
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.inputList.length; i++) {
|
||||
var conn = this.inputList[i].connection;
|
||||
if (conn) {
|
||||
conn.setTracking(true);
|
||||
conn.setTracking(track);
|
||||
|
||||
// Pass tracking on down the chain.
|
||||
var block = conn.targetBlock();
|
||||
if (block) {
|
||||
block.startTrackingConnections();
|
||||
block.setConnectionTracking(track);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1776,13 +1755,6 @@ 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_();
|
||||
// TODO: This should be handled inside a robust init method, because it would
|
||||
// make it a lot cleaner, but for now it's handled here for backwards
|
||||
// compatibility.
|
||||
if (this.callTrackConnections_) {
|
||||
this.startTrackingConnections();
|
||||
this.callTrackConnections_ = false;
|
||||
}
|
||||
if (opt_bubble !== false) {
|
||||
// Render all blocks above this one (propagate a reflow).
|
||||
var parentBlock = this.getParent();
|
||||
|
||||
@@ -202,10 +202,10 @@ Blockly.navigation.insertFromFlyout = function() {
|
||||
var newBlock = flyout.createBlock(curBlock);
|
||||
// Render to get the sizing right.
|
||||
newBlock.render();
|
||||
// Connections are hidden when the block is first created. Normally there's
|
||||
// enough time for them to become unhidden in the user's mouse movements,
|
||||
// but not here.
|
||||
newBlock.startTrackingConnections();
|
||||
// Connections are not tracked when the block is first created. Normally
|
||||
// there's enough time for them to become tracked in the user's mouse
|
||||
// movements, but not here.
|
||||
newBlock.setConnectionTracking(true);
|
||||
workspace.getCursor().setCurNode(
|
||||
Blockly.ASTNode.createBlockNode(newBlock));
|
||||
if (!Blockly.navigation.modify_()) {
|
||||
|
||||
@@ -65,14 +65,32 @@ Blockly.RenderedConnection = function(source, type) {
|
||||
this.offsetInBlock_ = new Blockly.utils.Coordinate(0, 0);
|
||||
|
||||
/**
|
||||
* Whether this connections is tracked in the database or not.
|
||||
* @type {boolean}
|
||||
* Describes the state of this connection's tracked-ness.
|
||||
* @type {Blockly.RenderedConnection.TrackedState}
|
||||
* @private
|
||||
*/
|
||||
this.tracked_ = false;
|
||||
this.trackedState_ = Blockly.RenderedConnection.TrackedState.WILL_TRACK;
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection);
|
||||
|
||||
/**
|
||||
* Enum for different kinds of tracked states.
|
||||
*
|
||||
* WILL_TRACK means that this connection will add itself to
|
||||
* the db on the next moveTo call it receives.
|
||||
*
|
||||
* UNTRACKED means that this connection will not add
|
||||
* itself to the database until setTracking(true) is explicitly called.
|
||||
*
|
||||
* TRACKED means that this connection is currently being tracked.
|
||||
* @enum {number}
|
||||
*/
|
||||
Blockly.RenderedConnection.TrackedState = {
|
||||
WILL_TRACK: -1,
|
||||
UNTRACKED: 0,
|
||||
TRACKED: 1
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispose of this connection. Remove it from the database (if it is
|
||||
* tracked) and call the super-function to deal with connected blocks.
|
||||
@@ -81,7 +99,7 @@ Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection);
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.dispose = function() {
|
||||
Blockly.RenderedConnection.superClass_.dispose.call(this);
|
||||
if (this.tracked_) {
|
||||
if (this.trackedState_ == Blockly.RenderedConnection.TrackedState.TRACKED) {
|
||||
this.db_.removeConnection(this, this.y);
|
||||
}
|
||||
};
|
||||
@@ -174,7 +192,11 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) {
|
||||
* @param {number} y New absolute y coordinate, in workspace coordinates.
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.moveTo = function(x, y) {
|
||||
if (this.tracked_) {
|
||||
if (this.trackedState_ == Blockly.RenderedConnection.TrackedState.WILL_TRACK) {
|
||||
this.db_.addConnection(this, y);
|
||||
this.trackedState_ = Blockly.RenderedConnection.TrackedState.TRACKED;
|
||||
} else if (this.trackedState_ == Blockly.RenderedConnection
|
||||
.TrackedState.TRACKED) {
|
||||
this.db_.removeConnection(this, this.y);
|
||||
this.db_.addConnection(this, y);
|
||||
}
|
||||
@@ -307,7 +329,10 @@ Blockly.RenderedConnection.prototype.unhighlight = function() {
|
||||
* @package
|
||||
*/
|
||||
Blockly.RenderedConnection.prototype.setTracking = function(doTracking) {
|
||||
if (doTracking == this.tracked_) {
|
||||
if ((doTracking && this.trackedState_ ==
|
||||
Blockly.RenderedConnection.TrackedState.TRACKED) ||
|
||||
(!doTracking && this.trackedState_ ==
|
||||
Blockly.RenderedConnection.TrackedState.UNTRACKED)) {
|
||||
return;
|
||||
}
|
||||
if (this.sourceBlock_.isInFlyout) {
|
||||
@@ -316,10 +341,14 @@ Blockly.RenderedConnection.prototype.setTracking = function(doTracking) {
|
||||
}
|
||||
if (doTracking) {
|
||||
this.db_.addConnection(this, this.y);
|
||||
} else {
|
||||
this.trackedState_ = Blockly.RenderedConnection.TrackedState.TRACKED;
|
||||
return;
|
||||
}
|
||||
if (this.trackedState_ == Blockly.RenderedConnection
|
||||
.TrackedState.TRACKED) {
|
||||
this.db_.removeConnection(this, this.y);
|
||||
}
|
||||
this.tracked_ = doTracking;
|
||||
this.trackedState_ = Blockly.RenderedConnection.TrackedState.UNTRACKED;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -545,7 +545,7 @@ Blockly.Xml.domToBlock = function(xmlBlock, workspace) {
|
||||
var blocks = topBlock.getDescendants(false);
|
||||
if (workspace.rendered) {
|
||||
// Wait to track connections to speed up assembly.
|
||||
topBlock.waitToTrackConnections();
|
||||
topBlock.setConnectionTracking(false);
|
||||
// Render each block.
|
||||
for (var i = blocks.length - 1; i >= 0; i--) {
|
||||
blocks[i].initSvg();
|
||||
@@ -557,7 +557,7 @@ Blockly.Xml.domToBlock = function(xmlBlock, workspace) {
|
||||
// blocks have rendered.
|
||||
setTimeout(function() {
|
||||
if (!topBlock.disposed) {
|
||||
topBlock.startTrackingConnections();
|
||||
topBlock.setConnectionTracking(true);
|
||||
}
|
||||
}, 1);
|
||||
topBlock.updateDisabled();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user