From 5aaab251a36779a3e6f010d87b24df783b387fc9 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 19 Aug 2019 12:28:51 -0700 Subject: [PATCH] Changed all other known 'hiding' references to 'tracking'. --- core/block_svg.js | 8 +-- core/input.js | 4 +- core/keyboard_nav/navigation.js | 2 +- core/rendered_connection.js | 122 ++++++++++++++++---------------- 4 files changed, 68 insertions(+), 68 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index f2004b684..dcab41b85 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -1457,13 +1457,13 @@ Blockly.BlockSvg.prototype.waitToTrackConnections = function() { Blockly.BlockSvg.prototype.startTrackingConnections = function() { if (this.previousConnection) { - this.previousConnection.setHidden(false); + this.previousConnection.setTracking(true); } if (this.outputConnection) { - this.outputConnection.setHidden(false); + this.outputConnection.setTracking(true); } if (this.nextConnection) { - this.nextConnection.setHidden(false); + this.nextConnection.setTracking(true); var child = this.nextConnection.targetBlock(); if (child) { child.startTrackingConnections(); @@ -1476,7 +1476,7 @@ Blockly.BlockSvg.prototype.startTrackingConnections = function() { for (var i = 0; i < this.inputList.length; i++) { var conn = this.inputList[i].connection; if (conn) { - conn.setHidden(false); + conn.setTracking(true); // Pass tracking on down the chain. var block = conn.targetBlock(); diff --git a/core/input.js b/core/input.js index 2ad195d94..6d290ca70 100644 --- a/core/input.js +++ b/core/input.js @@ -194,9 +194,9 @@ Blockly.Input.prototype.setVisible = function(visible) { if (this.connection) { // Has a connection. if (visible) { - renderList = this.connection.unhideAll(); + renderList = this.connection.startTrackingAll(); } else { - this.connection.hideAll(); + this.connection.stopTrackingAll(); } var child = this.connection.targetBlock(); if (child) { diff --git a/core/keyboard_nav/navigation.js b/core/keyboard_nav/navigation.js index 11e6f9503..6fba4eefd 100644 --- a/core/keyboard_nav/navigation.js +++ b/core/keyboard_nav/navigation.js @@ -208,7 +208,7 @@ Blockly.navigation.insertFromFlyout = function() { // 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.setConnectionsHidden(false); + newBlock.startTrackingConnections(); workspace.getCursor().setCurNode( Blockly.ASTNode.createBlockNode(newBlock)); if (!Blockly.navigation.modify_()) { diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 0ff9aecad..2018849d8 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -274,17 +274,68 @@ Blockly.RenderedConnection.prototype.highlight = function() { }; /** - * Unhide this connection, as well as all down-stream connections on any block - * attached to this connection. This happens when a block is expanded. - * Also unhides down-stream comments. + * Remove the highlighting around this connection. + */ +Blockly.RenderedConnection.prototype.unhighlight = function() { + Blockly.utils.dom.removeNode(Blockly.Connection.highlightedPath_); + delete Blockly.Connection.highlightedPath_; +}; + +/** + * Set whether this connections is tracked in the database or not. + * @param {boolean} doTracking If true, start tracking. If false, stop tracking. + */ +Blockly.RenderedConnection.prototype.setTracking = function(doTracking) { + if (doTracking == this.tracked_) { + return; + } + if (doTracking) { + this.db_.addConnection(this, this.y_); + } else { + this.db_.removeConnection(this, this.y_); + } + this.tracked_ = doTracking; +}; + +/** + * Stop tracking this connection, as well as all down-stream connections on + * any block attached to this connection. This happens when a block is + * collapsed. + * + * Also closes down-stream icons/bubbles. + * @package + */ +Blockly.RenderedConnection.prototype.stopTrackingAll = function() { + this.setTracking(false); + if (this.targetConnection) { + var blocks = this.targetBlock().getDescendants(false); + for (var i = 0; i < blocks.length; i++) { + var block = blocks[i]; + // Stop tracking connections of all children. + var connections = block.getConnections_(true); + for (var j = 0; j < connections.length; j++) { + connections[j].setTracking(false); + } + // Close all bubbles of all children. + var icons = block.getIcons(); + for (var j = 0; j < icons.length; j++) { + icons[j].setVisible(false); + } + } + } +}; + +/** + * Start tracking this connection, as well as all down-stream connections on + * any block attached to this connection. This happens when a block is expanded. * @return {!Array.} List of blocks to render. */ -Blockly.RenderedConnection.prototype.unhideAll = function() { - this.setHidden(false); - // All blocks that need unhiding must be unhidden before any rendering takes - // place, since rendering requires knowing the dimensions of lower blocks. - // Also, since rendering a block renders all its parents, we only need to - // render the leaf nodes. +Blockly.RenderedConnection.prototype.startTrackingAll = function() { + this.setTracking(true); + // All blocks that are not tracked must start tracking before any + // rendering takes place, since rendering requires knowing the dimensions + // of lower blocks. Also, since rendering a block renders all its parents, + // we only need to render the leaf nodes. var renderList = []; if (this.type != Blockly.INPUT_VALUE && this.type != Blockly.NEXT_STATEMENT) { // Only spider down. @@ -304,7 +355,7 @@ Blockly.RenderedConnection.prototype.unhideAll = function() { connections = block.getConnections_(true); } for (var i = 0; i < connections.length; i++) { - renderList.push.apply(renderList, connections[i].unhideAll()); + renderList.push.apply(renderList, connections[i].startTrackingAll()); } if (!renderList.length) { // Leaf block. @@ -314,57 +365,6 @@ Blockly.RenderedConnection.prototype.unhideAll = function() { return renderList; }; -/** - * Remove the highlighting around this connection. - */ -Blockly.RenderedConnection.prototype.unhighlight = function() { - Blockly.utils.dom.removeNode(Blockly.Connection.highlightedPath_); - delete Blockly.Connection.highlightedPath_; -}; - -/** - * Set whether this connections is hidden (not tracked in a database) or not. - * @param {boolean} hidden True if connection is hidden. - */ -Blockly.RenderedConnection.prototype.setHidden = function(hidden) { - // Temporary: if we're setting hidden to true we want to set tracked to false. - var track = !hidden; - if (track == this.tracked_) { - return; - } - if (track) { - this.db_.addConnection(this, this.y_); - } else { - this.db_.removeConnection(this, this.y_); - } - this.tracked_ = track; -}; - -/** - * Hide this connection, as well as all down-stream connections on any block - * attached to this connection. This happens when a block is collapsed. - * Also hides down-stream comments. - */ -Blockly.RenderedConnection.prototype.hideAll = function() { - this.setHidden(true); - if (this.targetConnection) { - var blocks = this.targetBlock().getDescendants(false); - for (var i = 0; i < blocks.length; i++) { - var block = blocks[i]; - // Hide all connections of all children. - var connections = block.getConnections_(true); - for (var j = 0; j < connections.length; j++) { - connections[j].setHidden(true); - } - // Close all bubbles of all children. - var icons = block.getIcons(); - for (var j = 0; j < icons.length; j++) { - icons[j].setVisible(false); - } - } - } -}; - /** * Check if the two connections can be dragged to connect to each other. * @param {!Blockly.Connection} candidate A nearby connection to check.