Merge pull request #3125 from BeksOmega/fixes/MoveDbToRendered

Connection Tracking Pt 2: Moved all database related code out of headless
This commit is contained in:
Rachel Fenichel
2019-10-01 14:05:12 -07:00
committed by GitHub
5 changed files with 76 additions and 76 deletions

View File

@@ -819,40 +819,6 @@ Blockly.Block.prototype.setEditable = function(editable) {
}
};
/**
* 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.
*/
Blockly.Block.prototype.setConnectionsHidden = function(hidden) {
if (!hidden && this.isCollapsed()) {
if (this.outputConnection) {
this.outputConnection.setHidden(hidden);
}
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);
}
}
}
}
};
/**
* Find the connection on this block that corresponds to the given connection
* on the other block.

View File

@@ -1437,6 +1437,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);
}
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);
}
}
}
}
};
/**
* Returns connections originating from this block.
* @param {boolean} all If true, return all connections even hidden ones.

View File

@@ -45,13 +45,6 @@ Blockly.Connection = function(source, type) {
this.sourceBlock_ = source;
/** @type {number} */
this.type = type;
// Shortcut for the databases for this connection's workspace.
if (source.workspace.connectionDBList) {
this.db_ = source.workspace.connectionDBList[type];
this.dbOpposite_ =
source.workspace.connectionDBList[Blockly.OPPOSITE_TYPE[type]];
this.hidden_ = !this.db_;
}
};
/**
@@ -106,35 +99,6 @@ Blockly.Connection.prototype.x_ = 0;
*/
Blockly.Connection.prototype.y_ = 0;
/**
* Has this connection been added to the connection database?
* @type {boolean}
* @protected
*/
Blockly.Connection.prototype.inDB_ = false;
/**
* Connection database for connections of this type on the current workspace.
* @type {Blockly.ConnectionDB}
* @protected
*/
Blockly.Connection.prototype.db_ = null;
/**
* Connection database for connections compatible with this type on the
* current workspace.
* @type {Blockly.ConnectionDB}
* @protected
*/
Blockly.Connection.prototype.dbOpposite_ = null;
/**
* Whether this connections is hidden (not tracked in a database) or not.
* @type {boolean}
* @protected
*/
Blockly.Connection.prototype.hidden_ = null;
/**
* Connect two connections together. This is the connection on the superior
* block.
@@ -259,10 +223,6 @@ Blockly.Connection.prototype.dispose = function() {
}
}
if (this.inDB_) {
this.db_.removeConnection_(this);
}
this.disposed = true;
};

View File

@@ -44,15 +44,55 @@ goog.require('Blockly.utils.object');
Blockly.RenderedConnection = function(source, type) {
Blockly.RenderedConnection.superClass_.constructor.call(this, source, type);
/**
* Connection database for connections of this type on the current workspace.
* @const {!Blockly.ConnectionDB}
* @private
*/
this.db_ = source.workspace.connectionDBList[type];
/**
* Connection database for connections compatible with this type on the
* current workspace.
* @const {!Blockly.ConnectionDB}
* @private
*/
this.dbOpposite_ = source.workspace
.connectionDBList[Blockly.OPPOSITE_TYPE[type]];
/**
* Workspace units, (0, 0) is top left of block.
* @type {!Blockly.utils.Coordinate}
* @private
*/
this.offsetInBlock_ = new Blockly.utils.Coordinate(0, 0);
/**
* Has this connection been added to the connection database?
* @type {boolean}
* @private
*/
this.inDB_ = false;
/**
* Whether this connections is hidden (not tracked in a database) or not.
* @type {boolean}
* @private
*/
this.hidden_ = !this.db_;
};
Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection);
/**
* @override
*/
Blockly.RenderedConnection.prototype.dispose = function() {
if (this.inDB_) {
this.db_.removeConnection_(this);
}
Blockly.RenderedConnection.superClass_.dispose.call(this);
};
/**
* Returns the distance between this connection and another connection in
* workspace units.

View File

@@ -18,8 +18,7 @@
* limitations under the License.
*/
// TODO: Re-enable once headless connections ignore databases.
suite.skip('Connections', function() {
suite('Connections', function() {
suite('Can Connect With Reason', function() {
test('Target Null', function() {
var connection = new Blockly.Connection({}, Blockly.INPUT_VALUE);