From 999a204dbdaf3e3106a79e1e41624c90a52e72ce Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 28 Jan 2019 16:26:21 -0800 Subject: [PATCH] Added the ability to drag disabled blocks out of the trashcan flyout. --- core/flyout_base.js | 12 ++++++++++++ core/gesture.js | 3 +-- core/trashcan.js | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 5be9802b7..4c5d467e1 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -595,6 +595,18 @@ Blockly.Flyout.prototype.onMouseDown_ = function(e) { } }; +/** + * Does this flyout allow you to create a new instance of the given block? + * Used for deciding if a block can be "dragged out of" the flyout. + * @param {!Blockly.BlockSvg} block The block to copy from the flyout. + * @return {!boolean} True if you can create a new instance of the block, false + * otherwise. + * @package + */ +Blockly.Flyout.prototype.isBlockCreatable_ = function(block) { + return !block.disabled; +}; + /** * Create a copy of this block on the workspace. * @param {!Blockly.BlockSvg} originalBlock The block to copy from the flyout. diff --git a/core/gesture.js b/core/gesture.js index 0f8c67820..3df739569 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -327,8 +327,7 @@ Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { * @private */ Blockly.Gesture.prototype.updateIsDraggingFromFlyout_ = function() { - // Disabled blocks may not be dragged from the flyout. - if (this.targetBlock_.disabled) { + if (!this.flyout_.isBlockCreatable_(this.targetBlock_)) { return false; } if (!this.flyout_.isScrollable() || diff --git a/core/trashcan.js b/core/trashcan.js index 2041b1991..2c14a1366 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -281,6 +281,11 @@ Blockly.Trashcan.prototype.init = function(verticalSpacing) { Blockly.utils.insertAfter(this.flyout_.createDom('svg'), this.workspace_.getParentSvg()); this.flyout_.init(this.workspace_); + this.flyout_.isBlockCreatable_ = function() { + // All blocks, including disabled ones, can be dragged from the + // trashcan flyout. + return true; + }; } this.verticalSpacing_ = this.MARGIN_BOTTOM_ + verticalSpacing;