From 877aa7522d4e1cead6cff8b0006bc10c18ec0c4f Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 19 Jul 2016 16:34:48 -0700 Subject: [PATCH] Fix mutator/warning/comment icons to highlight on mouse over only if they are usable. --- core/block_svg.js | 8 +++----- core/icon.js | 11 ++++------- core/mutator.js | 24 +++++++++++++++--------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index af19bb4a1..7369235d5 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -945,11 +945,9 @@ Blockly.BlockSvg.prototype.setMovable = function(movable) { */ Blockly.BlockSvg.prototype.setEditable = function(editable) { Blockly.BlockSvg.superClass_.setEditable.call(this, editable); - if (this.rendered) { - var icons = this.getIcons(); - for (var i = 0; i < icons.length; i++) { - icons[i].updateEditable(); - } + var icons = this.getIcons(); + for (var i = 0; i < icons.length; i++) { + icons[i].updateEditable(); } }; diff --git a/core/icon.js b/core/icon.js index 395c98544..b10e18148 100644 --- a/core/icon.js +++ b/core/icon.js @@ -78,6 +78,10 @@ Blockly.Icon.prototype.createIcon = function() { */ this.iconGroup_ = Blockly.createSvgElement('g', {'class': 'blocklyIconGroup'}, null); + if (this.block_.isInFlyout) { + Blockly.addClass_(/** @type {!Element} */ (this.iconGroup_), + 'blocklyIconGroupReadonly'); + } this.drawIcon_(this.iconGroup_); this.block_.getSvgRoot().appendChild(this.iconGroup_); @@ -101,13 +105,6 @@ Blockly.Icon.prototype.dispose = function() { * Add or remove the UI indicating if this icon may be clicked or not. */ Blockly.Icon.prototype.updateEditable = function() { - if (this.block_.isInFlyout || !this.block_.isEditable()) { - Blockly.addClass_(/** @type {!Element} */ (this.iconGroup_), - 'blocklyIconGroupReadonly'); - } else { - Blockly.removeClass_(/** @type {!Element} */ (this.iconGroup_), - 'blocklyIconGroupReadonly'); - } }; /** diff --git a/core/mutator.js b/core/mutator.js index d28beb49f..8a8500cda 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -139,17 +139,23 @@ Blockly.Mutator.prototype.createEditor_ = function() { * Add or remove the UI indicating if this icon may be clicked or not. */ Blockly.Mutator.prototype.updateEditable = function() { - if (this.block_.isEditable()) { - // Default behaviour for an icon. - Blockly.Icon.prototype.updateEditable.call(this); - } else { - // Close any mutator bubble. Icon is not clickable. - this.setVisible(false); - if (this.iconGroup_) { - Blockly.addClass_(/** @type {!Element} */ (this.iconGroup_), - 'blocklyIconGroupReadonly'); + if (!this.block_.isInFlyout) { + if (this.block_.isEditable()) { + if (this.iconGroup_) { + Blockly.removeClass_(/** @type {!Element} */ (this.iconGroup_), + 'blocklyIconGroupReadonly'); + } + } else { + // Close any mutator bubble. Icon is not clickable. + this.setVisible(false); + if (this.iconGroup_) { + Blockly.addClass_(/** @type {!Element} */ (this.iconGroup_), + 'blocklyIconGroupReadonly'); + } } } + // Default behaviour for an icon. + Blockly.Icon.prototype.updateEditable.call(this); }; /**