|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
goog.provide('Blockly.BubbleDragger');
|
|
|
|
|
|
goog.require('Blockly.Bubble');
|
|
|
goog.require('Blockly.Events.CommentMove');
|
|
|
goog.require('Blockly.WorkspaceCommentSvg');
|
|
|
|
|
|
goog.require('goog.math.Coordinate');
|
|
|
goog.require('goog.asserts');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BubbleDragger = function(bubble, workspace) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.draggingBubble_ = bubble;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.workspace_ = workspace;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.deleteArea_ = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.wouldDeleteBubble_ = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.startXY_ = this.draggingBubble_.getRelativeToSurfaceXY();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.dragSurface_ =
|
|
|
Blockly.utils.is3dSupported() && !!workspace.getBlockDragSurface() ?
|
|
|
workspace.getBlockDragSurface() : null;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BubbleDragger.prototype.dispose = function() {
|
|
|
this.draggingBubble_ = null;
|
|
|
this.workspace_ = null;
|
|
|
this.dragSurface_ = null;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BubbleDragger.prototype.startBubbleDrag = function() {
|
|
|
if (!Blockly.Events.getGroup()) {
|
|
|
Blockly.Events.setGroup(true);
|
|
|
}
|
|
|
|
|
|
this.workspace_.setResizesEnabled(false);
|
|
|
this.draggingBubble_.setAutoLayout(false);
|
|
|
if (this.dragSurface_) {
|
|
|
this.moveToDragSurface_();
|
|
|
}
|
|
|
|
|
|
this.draggingBubble_.setDragging && this.draggingBubble_.setDragging(true);
|
|
|
|
|
|
var toolbox = this.workspace_.getToolbox();
|
|
|
if (toolbox) {
|
|
|
var style = this.draggingBubble_.isDeletable() ? 'blocklyToolboxDelete' :
|
|
|
'blocklyToolboxGrab';
|
|
|
toolbox.addStyle(style);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) {
|
|
|
var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
|
|
|
var newLoc = goog.math.Coordinate.sum(this.startXY_, delta);
|
|
|
|
|
|
this.draggingBubble_.moveDuringDrag(this.dragSurface_, newLoc);
|
|
|
|
|
|
if (this.draggingBubble_.isDeletable()) {
|
|
|
this.deleteArea_ = this.workspace_.isDeleteArea(e);
|
|
|
this.updateCursorDuringBubbleDrag_();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BubbleDragger.prototype.maybeDeleteBubble_ = function() {
|
|
|
var trashcan = this.workspace_.trashcan;
|
|
|
|
|
|
if (this.wouldDeleteBubble_) {
|
|
|
if (trashcan) {
|
|
|
setTimeout(trashcan.close.bind(trashcan), 100);
|
|
|
}
|
|
|
|
|
|
this.fireMoveEvent_();
|
|
|
this.draggingBubble_.dispose(false, true);
|
|
|
} else if (trashcan) {
|
|
|
|
|
|
trashcan.close();
|
|
|
}
|
|
|
return this.wouldDeleteBubble_;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() {
|
|
|
this.wouldDeleteBubble_ = this.deleteArea_ != Blockly.DELETE_AREA_NONE;
|
|
|
var trashcan = this.workspace_.trashcan;
|
|
|
if (this.wouldDeleteBubble_) {
|
|
|
this.draggingBubble_.setDeleteStyle(true);
|
|
|
if (this.deleteArea_ == Blockly.DELETE_AREA_TRASH && trashcan) {
|
|
|
trashcan.setOpen_(true);
|
|
|
}
|
|
|
} else {
|
|
|
this.draggingBubble_.setDeleteStyle(false);
|
|
|
if (trashcan) {
|
|
|
trashcan.setOpen_(false);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BubbleDragger.prototype.endBubbleDrag = function(
|
|
|
e, currentDragDeltaXY) {
|
|
|
|
|
|
this.dragBubble(e, currentDragDeltaXY);
|
|
|
|
|
|
var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
|
|
|
var newLoc = goog.math.Coordinate.sum(this.startXY_, delta);
|
|
|
|
|
|
|
|
|
this.draggingBubble_.moveTo(newLoc.x, newLoc.y);
|
|
|
var deleted = this.maybeDeleteBubble_();
|
|
|
|
|
|
if (!deleted) {
|
|
|
|
|
|
if (this.dragSurface_) {
|
|
|
this.dragSurface_.clearAndHide(this.workspace_.getBubbleCanvas());
|
|
|
}
|
|
|
|
|
|
this.draggingBubble_.setDragging && this.draggingBubble_.setDragging(false);
|
|
|
this.fireMoveEvent_();
|
|
|
}
|
|
|
this.workspace_.setResizesEnabled(true);
|
|
|
|
|
|
if (this.workspace_.toolbox_) {
|
|
|
var style = this.draggingBubble_.isDeletable() ? 'blocklyToolboxDelete' :
|
|
|
'blocklyToolboxGrab';
|
|
|
this.workspace_.toolbox_.removeStyle(style);
|
|
|
}
|
|
|
Blockly.Events.setGroup(false);
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BubbleDragger.prototype.fireMoveEvent_ = function() {
|
|
|
var event = null;
|
|
|
if (this.draggingBubble_.isComment) {
|
|
|
event = new Blockly.Events.CommentMove(this.draggingBubble_);
|
|
|
} else if (this.draggingBubble_ instanceof Blockly.ScratchBubble) {
|
|
|
event = new Blockly.Events.CommentMove(this.draggingBubble_.comment);
|
|
|
} else {
|
|
|
return;
|
|
|
}
|
|
|
event.setOldCoordinate(this.startXY_);
|
|
|
event.recordNew();
|
|
|
Blockly.Events.fire(event);
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) {
|
|
|
var result = new goog.math.Coordinate(pixelCoord.x / this.workspace_.scale,
|
|
|
pixelCoord.y / this.workspace_.scale);
|
|
|
if (this.workspace_.isMutator) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var mainScale = this.workspace_.options.parentWorkspace.scale;
|
|
|
result = result.scale(1 / mainScale);
|
|
|
}
|
|
|
return result;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.BubbleDragger.prototype.moveToDragSurface_ = function() {
|
|
|
this.draggingBubble_.moveTo(0, 0);
|
|
|
this.dragSurface_.translateSurface(this.startXY_.x, this.startXY_.y);
|
|
|
|
|
|
this.dragSurface_.setBlocksAndShow(this.draggingBubble_.getSvgRoot());
|
|
|
};
|
|
|
|