diff --git a/core/block_dragger.js b/core/block_dragger.js index c9c4774309f..06460b5fb6e 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -205,21 +205,20 @@ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { Blockly.BlockDragger.prototype.dragBlock = function(e, currentDragDeltaXY) { var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); - this.draggingBlock_.moveDuringDrag(newLoc); this.dragIcons_(delta); var oldDragTarget = this.dragTarget_; this.dragTarget_ = this.workspace_.getDragTarget(e); - if (this.dragTarget_ !== oldDragTarget) { - oldDragTarget && oldDragTarget.onDragExit(); - this.dragTarget_ && this.dragTarget_.onDragEnter(); - } this.draggedConnectionManager_.update(delta, this.dragTarget_); this.wouldDeleteBlock_ = this.draggedConnectionManager_.wouldDeleteBlock(); - this.updateCursorDuringBlockDrag_(); + + if (this.dragTarget_ !== oldDragTarget) { + oldDragTarget && oldDragTarget.onDragExit(); + this.dragTarget_ && this.dragTarget_.onDragEnter(); + } }; /** diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 38c33915805..2af80371254 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -131,18 +131,18 @@ Blockly.BubbleDragger.prototype.startBubbleDrag = function() { Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); - this.draggingBubble_.moveDuringDrag(this.dragSurface_, newLoc); var oldDragTarget = this.dragTarget_; this.dragTarget_ = this.workspace_.getDragTarget(e); + + this.wouldDeleteBubble_ = this.shouldDelete_(this.dragTarget_); + this.updateCursorDuringBubbleDrag_(); + if (this.dragTarget_ !== oldDragTarget) { oldDragTarget && oldDragTarget.onDragExit(); this.dragTarget_ && this.dragTarget_.onDragEnter(); } - this.wouldDeleteBubble_ = this.shouldDelete_(this.dragTarget_); - - this.updateCursorDuringBubbleDrag_(); }; /** diff --git a/core/delete_area.js b/core/delete_area.js index 92edf36f561..af7d9df1a00 100644 --- a/core/delete_area.js +++ b/core/delete_area.js @@ -27,6 +27,14 @@ goog.require('Blockly.IDeleteArea'); */ Blockly.DeleteArea = function() { Blockly.DeleteArea.superClass_.constructor.call(this); + + /** + * Whether the current block or bubble dragged over this delete area would be + * deleted if dropped on this component. + * @type {boolean} + * @protected + */ + this.wouldDelete_ = false; }; Blockly.utils.object.inherits(Blockly.DeleteArea, Blockly.DragTarget); @@ -39,7 +47,8 @@ Blockly.utils.object.inherits(Blockly.DeleteArea, Blockly.DragTarget); * this area. */ Blockly.DeleteArea.prototype.wouldDeleteBlock = function(_block, couldConnect) { - return !couldConnect; + this.wouldDelete_ = !couldConnect; + return this.wouldDelete_; }; /** @@ -49,5 +58,58 @@ Blockly.DeleteArea.prototype.wouldDeleteBlock = function(_block, couldConnect) { * this area. */ Blockly.DeleteArea.prototype.wouldDeleteBubble = function(_bubble) { + this.wouldDelete_ = true; return true; }; + +/** + * Returns whether the provided block should not be moved after being dropped + * on this component. If true, block will return to where it was when the drag + * started. + * @param {!Blockly.BlockSvg} _block The block. + * @return {boolean} Whether the block provided should be returned to drag + * start. + */ +Blockly.DeleteArea.prototype.shouldPreventBlockMove = function(_block) { + return false; +}; + +/** + * Returns whether the provided bubble should not be moved after being dropped + * on this component. If true, bubble will return to where it was when the drag + * started. + * @param {!Blockly.IBubble} _bubble The bubble. + * @return {boolean} Whether the bubble provided should be returned to drag + * start. + */ +Blockly.DeleteArea.prototype.shouldPreventBubbleMove = function(_bubble) { + return false; +}; + +/** + * Handles when a cursor with a block or bubble exits this drag target. + * @override + */ +Blockly.DeleteArea.prototype.onDragExit = function() { + this.wouldDelete_ = false; +}; + +/** + * Handles when a block is dropped on this component. Should not handle delete + * here. + * @param {!Blockly.BlockSvg} _block The block. + * @override + */ +Blockly.DeleteArea.prototype.onBlockDrop = function(_block) { + this.wouldDelete_ = false; +}; + +/** + * Handles when a bubble is dropped on this component. Should not handle delete + * here. + * @param {!Blockly.IBubble} _bubble The bubble. + * @override + */ +Blockly.DeleteArea.prototype.onBubbleDrop = function(_bubble) { + this.wouldDelete_ = false; +}; diff --git a/core/toolbox/toolbox.js b/core/toolbox/toolbox.js index 64a1a51dbc9..1a49c463c81 100644 --- a/core/toolbox/toolbox.js +++ b/core/toolbox/toolbox.js @@ -540,10 +540,12 @@ Blockly.Toolbox.prototype.getClientRect = function() { * another. * @return {boolean} Whether the block provided would be deleted if dropped on * this area. + * @override */ Blockly.Toolbox.prototype.wouldDeleteBlock = function(_block, _couldConnect) { // Prefer dragging to the toolbox over connecting to other blocks. - return true; + this.wouldDelete_ = true; + return this.wouldDelete_; }; /** diff --git a/core/trashcan.js b/core/trashcan.js index 7781a79bd93..4b498e9f3f1 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -529,7 +529,10 @@ Blockly.Trashcan.prototype.getClientRect = function() { * @override */ Blockly.Trashcan.prototype.onDragEnter = function() { - this.setLidOpen(true); + Blockly.Trashcan.superClass_.onDragEnter.call(this); + if (this.wouldDelete_) { + this.setLidOpen(true); + } }; /** @@ -537,27 +540,29 @@ Blockly.Trashcan.prototype.onDragEnter = function() { * @override */ Blockly.Trashcan.prototype.onDragExit = function() { + Blockly.Trashcan.superClass_.onDragExit.call(this); this.setLidOpen(false); }; - /** * Handles when a block is dropped on this component. Should not handle delete * here. - * @param {!Blockly.BlockSvg} _block The block. + * @param {!Blockly.BlockSvg} block The block. * @override */ -Blockly.Trashcan.prototype.onBlockDrop = function(_block) { +Blockly.Trashcan.prototype.onBlockDrop = function(block) { + Blockly.Trashcan.superClass_.onBlockDrop.call(this, block); this.onDrop_(); }; /** * Handles when a bubble is dropped on this component. Should not handle delete * here. - * @param {!Blockly.IBubble} _bubble The bubble. + * @param {!Blockly.IBubble} bubble The bubble. * @override */ -Blockly.Trashcan.prototype.onBubbleDrop = function(_bubble) { +Blockly.Trashcan.prototype.onBubbleDrop = function(bubble) { + Blockly.Trashcan.superClass_.onBubbleDrop.call(this, bubble); this.onDrop_(); }; @@ -566,7 +571,7 @@ Blockly.Trashcan.prototype.onBubbleDrop = function(_bubble) { * @private */ Blockly.Trashcan.prototype.onDrop_ = function() { - setTimeout(this.closeLid.bind(this), 100); + setTimeout(this.setLidOpen.bind(this, false), 100); }; /**