mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
Update mutator workspace delete areas when bubble is moved. (#3355)
* Update mutator workspace delete areas when its moved
This commit is contained in:
@@ -1291,7 +1291,7 @@ Blockly.BlockSvg.prototype.setMutator = function(mutator) {
|
||||
this.mutator.dispose();
|
||||
}
|
||||
if (mutator) {
|
||||
mutator.block_ = this;
|
||||
mutator.setBlock(this);
|
||||
this.mutator = mutator;
|
||||
mutator.createIcon();
|
||||
}
|
||||
|
||||
@@ -81,6 +81,20 @@ Blockly.Bubble = function(workspace, content, shape, anchorXY,
|
||||
this.resizeGroup_, 'mousedown', this, this.resizeMouseDown_);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to call on resize of bubble.
|
||||
* @type {?function()}
|
||||
* @private
|
||||
*/
|
||||
this.resizeCallback_ = null;
|
||||
|
||||
/**
|
||||
* Method to call on move of bubble.
|
||||
* @type {?function()}
|
||||
* @private
|
||||
*/
|
||||
this.moveCallback_ = null;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -123,13 +137,6 @@ Blockly.Bubble.onMouseUpWrapper_ = null;
|
||||
*/
|
||||
Blockly.Bubble.onMouseMoveWrapper_ = null;
|
||||
|
||||
/**
|
||||
* Function to call on resize of bubble.
|
||||
* @type {Function}
|
||||
* @private
|
||||
*/
|
||||
Blockly.Bubble.prototype.resizeCallback_ = null;
|
||||
|
||||
/**
|
||||
* Stop binding to the global mouseup and mousemove events.
|
||||
* @private
|
||||
@@ -371,6 +378,14 @@ Blockly.Bubble.prototype.registerResizeEvent = function(callback) {
|
||||
this.resizeCallback_ = callback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a function as a callback event for when the bubble is moved.
|
||||
* @param {!Function} callback The function to call on move.
|
||||
*/
|
||||
Blockly.Bubble.prototype.registerMoveEvent = function(callback) {
|
||||
this.moveCallback_ = callback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Move this bubble to the top of the stack.
|
||||
* @return {boolean} Whether or not the bubble has been moved.
|
||||
@@ -620,6 +635,17 @@ Blockly.Bubble.prototype.moveTo = function(x, y) {
|
||||
this.bubbleGroup_.setAttribute('transform', 'translate(' + x + ',' + y + ')');
|
||||
};
|
||||
|
||||
/**
|
||||
* Triggers a move callback if one exists at the end of a drag.
|
||||
* @param {boolean} adding True if adding, false if removing.
|
||||
* @package
|
||||
*/
|
||||
Blockly.Bubble.prototype.setDragging = function(adding) {
|
||||
if (!adding && this.moveCallback_) {
|
||||
this.moveCallback_();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the dimensions of this bubble.
|
||||
* @return {!Blockly.utils.Size} The height and width of the bubble.
|
||||
|
||||
@@ -267,6 +267,7 @@ Blockly.BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) {
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Move the bubble onto the drag surface at the beginning of a drag. Move the
|
||||
* drag surface to preserve the apparent location of the bubble.
|
||||
|
||||
@@ -62,6 +62,15 @@ Blockly.Mutator.prototype.workspaceWidth_ = 0;
|
||||
*/
|
||||
Blockly.Mutator.prototype.workspaceHeight_ = 0;
|
||||
|
||||
/**
|
||||
* Set the block this mutator is associated with.
|
||||
* @param {Blockly.BlockSvg} block The block associated with this mutator.
|
||||
* @package
|
||||
*/
|
||||
Blockly.Mutator.prototype.setBlock = function(block) {
|
||||
this.block_ = block;
|
||||
};
|
||||
|
||||
/**
|
||||
* Draw the mutator icon.
|
||||
* @param {!Element} group The icon group.
|
||||
@@ -242,6 +251,16 @@ Blockly.Mutator.prototype.resizeBubble_ = function() {
|
||||
this.workspace_.resize();
|
||||
};
|
||||
|
||||
/**
|
||||
* A method handler for when the bubble is moved.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Mutator.prototype.onBubbleMove_ = function() {
|
||||
if (this.workspace_) {
|
||||
this.workspace_.recordDeleteAreas();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Show or hide the mutator bubble.
|
||||
* @param {boolean} visible True if the bubble should be visible.
|
||||
@@ -261,6 +280,7 @@ Blockly.Mutator.prototype.setVisible = function(visible) {
|
||||
/** @type {!Blockly.utils.Coordinate} */ (this.iconXY_), null, null);
|
||||
// Expose this mutator's block's ID on its top-level SVG group.
|
||||
this.bubble_.setSvgId(this.block_.id);
|
||||
this.bubble_.registerMoveEvent(this.onBubbleMove_.bind(this));
|
||||
var tree = this.workspace_.options.languageTree;
|
||||
var flyout = this.workspace_.getFlyout();
|
||||
if (tree) {
|
||||
|
||||
Reference in New Issue
Block a user