| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | |
| | |
| | |
| |
|
| | 'use strict';
|
| |
|
| | goog.provide('Blockly.BlockDragger');
|
| |
|
| | goog.require('Blockly.BlockAnimations');
|
| | goog.require('Blockly.Events.BlockMove');
|
| | goog.require('Blockly.Events.DragBlockOutside');
|
| | goog.require('Blockly.Events.EndBlockDrag');
|
| | goog.require('Blockly.InsertionMarkerManager');
|
| |
|
| | goog.require('goog.math.Coordinate');
|
| | goog.require('goog.asserts');
|
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.BlockDragger = function(block, workspace) {
|
| | |
| | |
| | |
| | |
| |
|
| | this.draggingBlock_ = block;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.workspace_ = workspace;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.draggedConnectionManager_ = new Blockly.InsertionMarkerManager(
|
| | this.draggingBlock_);
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | this.deleteArea_ = null;
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | this.wouldDeleteBlock_ = false;
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | this.wasOutside_ = false;
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | this.startXY_ = this.draggingBlock_.getRelativeToSurfaceXY();
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | this.dragIconData_ = Blockly.BlockDragger.initIconData_(block);
|
| | };
|
| |
|
| | |
| | |
| | |
| |
|
| | Blockly.BlockDragger.prototype.dispose = function() {
|
| | this.draggingBlock_ = null;
|
| | this.workspace_ = null;
|
| | this.startWorkspace_ = null;
|
| | this.dragIconData_.length = 0;
|
| |
|
| | if (this.draggedConnectionManager_) {
|
| | this.draggedConnectionManager_.dispose();
|
| | this.draggedConnectionManager_ = null;
|
| | }
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.BlockDragger.initIconData_ = function(block) {
|
| |
|
| | var dragIconData = [];
|
| | var descendants = block.getDescendants(false);
|
| | for (var i = 0, descendant; descendant = descendants[i]; i++) {
|
| | var icons = descendant.getIcons();
|
| | for (var j = 0; j < icons.length; j++) {
|
| | var data = {
|
| |
|
| | location: icons[j].getIconLocation(),
|
| |
|
| | icon: icons[j]
|
| | };
|
| | dragIconData.push(data);
|
| | }
|
| | }
|
| | return dragIconData;
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY) {
|
| | if (!Blockly.Events.getGroup()) {
|
| | Blockly.Events.setGroup(true);
|
| | }
|
| |
|
| | this.workspace_.setResizesEnabled(false);
|
| | Blockly.BlockAnimations.disconnectUiStop();
|
| |
|
| | if (this.draggingBlock_.getParent()) {
|
| | this.draggingBlock_.unplug();
|
| | var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
|
| | var newLoc = goog.math.Coordinate.sum(this.startXY_, delta);
|
| |
|
| | this.draggingBlock_.translate(newLoc.x, newLoc.y);
|
| | Blockly.BlockAnimations.disconnectUiEffect(this.draggingBlock_);
|
| | }
|
| | this.draggingBlock_.setDragging(true);
|
| |
|
| |
|
| |
|
| | this.draggingBlock_.moveToDragSurface_();
|
| |
|
| | var toolbox = this.workspace_.getToolbox();
|
| | if (toolbox) {
|
| | var style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' :
|
| | 'blocklyToolboxGrab';
|
| | toolbox.addStyle(style);
|
| | }
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.BlockDragger.prototype.dragBlock = function(e, currentDragDeltaXY) {
|
| | var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
|
| | var newLoc = goog.math.Coordinate.sum(this.startXY_, delta);
|
| |
|
| | this.draggingBlock_.moveDuringDrag(newLoc);
|
| | this.dragIcons_(delta);
|
| |
|
| | this.deleteArea_ = this.workspace_.isDeleteArea(e);
|
| | var isOutside = !this.workspace_.isInsideBlocksArea(e);
|
| | this.draggedConnectionManager_.update(delta, this.deleteArea_, isOutside);
|
| | if (isOutside !== this.wasOutside_) {
|
| | this.fireDragOutsideEvent_(isOutside);
|
| | this.wasOutside_ = isOutside;
|
| | }
|
| |
|
| | this.updateCursorDuringBlockDrag_(isOutside);
|
| | return isOutside;
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.BlockDragger.prototype.endBlockDrag = function(e, currentDragDeltaXY) {
|
| |
|
| | this.dragBlock(e, currentDragDeltaXY);
|
| | this.dragIconData_ = [];
|
| | var isOutside = this.wasOutside_;
|
| | this.fireEndDragEvent_(isOutside);
|
| | this.draggingBlock_.setMouseThroughStyle(false);
|
| |
|
| | Blockly.BlockAnimations.disconnectUiStop();
|
| |
|
| | var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
|
| | var newLoc = goog.math.Coordinate.sum(this.startXY_, delta);
|
| | this.draggingBlock_.moveOffDragSurface_(newLoc);
|
| |
|
| |
|
| | var isDeletingProcDef = this.wouldDeleteBlock_ &&
|
| | (this.draggingBlock_.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE ||
|
| | this.draggingBlock_.type == Blockly.PROCEDURES_DEFINITION_BLOCK_TYPE + '_return');
|
| | if (isDeletingProcDef) {
|
| | var procCodeBeingDeleted = this.draggingBlock_.getInput('custom_block').connection.targetBlock().getProcCode();
|
| | }
|
| |
|
| | var deleted = this.maybeDeleteBlock_();
|
| | if (!deleted) {
|
| |
|
| | this.draggingBlock_.moveConnections_(delta.x, delta.y);
|
| | this.draggingBlock_.setDragging(false);
|
| | this.fireMoveEvent_();
|
| | if (this.draggedConnectionManager_.wouldConnectBlock()) {
|
| |
|
| | this.draggedConnectionManager_.applyConnections();
|
| | } else {
|
| | this.draggingBlock_.render();
|
| | }
|
| | this.draggingBlock_.scheduleSnapAndBump();
|
| | }
|
| | this.workspace_.setResizesEnabled(true);
|
| |
|
| | var toolbox = this.workspace_.getToolbox();
|
| | if (toolbox) {
|
| | var style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' :
|
| | 'blocklyToolboxGrab';
|
| | toolbox.removeStyle(style);
|
| | }
|
| | Blockly.Events.setGroup(false);
|
| |
|
| | if (isOutside) {
|
| | var ws = this.workspace_;
|
| |
|
| | setTimeout(function() {
|
| | ws.undo();
|
| | });
|
| | }
|
| |
|
| |
|
| |
|
| |
|
| | if (isDeletingProcDef) {
|
| | var ws = this.workspace_;
|
| | setTimeout(function() {
|
| | var allBlocks = ws.getAllBlocks();
|
| | for (var i = 0; i < allBlocks.length; i++) {
|
| | var block = allBlocks[i];
|
| | if (block.type == Blockly.PROCEDURES_CALL_BLOCK_TYPE) {
|
| | var procCode = block.getProcCode();
|
| |
|
| | if (procCode === procCodeBeingDeleted) {
|
| | alert(Blockly.Msg.PROCEDURE_USED);
|
| | ws.undo();
|
| | return;
|
| | }
|
| | }
|
| | }
|
| |
|
| | ws.refreshToolboxSelection_();
|
| | });
|
| | }
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.BlockDragger.prototype.fireDragOutsideEvent_ = function(isOutside) {
|
| | var event = new Blockly.Events.DragBlockOutside(this.draggingBlock_);
|
| | event.isOutside = isOutside;
|
| | Blockly.Events.fire(event);
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| |
|
| | Blockly.BlockDragger.prototype.fireEndDragEvent_ = function(isOutside) {
|
| | var event = new Blockly.Events.EndBlockDrag(this.draggingBlock_, isOutside);
|
| | Blockly.Events.fire(event);
|
| | };
|
| |
|
| | |
| | |
| | |
| |
|
| | Blockly.BlockDragger.prototype.fireMoveEvent_ = function() {
|
| | var event = new Blockly.Events.BlockMove(this.draggingBlock_);
|
| | event.oldCoordinate = this.startXY_;
|
| | event.recordNew();
|
| | Blockly.Events.fire(event);
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.BlockDragger.prototype.maybeDeleteBlock_ = function() {
|
| | var trashcan = this.workspace_.trashcan;
|
| |
|
| | if (this.wouldDeleteBlock_) {
|
| | if (trashcan) {
|
| | goog.Timer.callOnce(trashcan.close, 100, trashcan);
|
| | }
|
| |
|
| | this.fireMoveEvent_();
|
| | this.draggingBlock_.dispose(false, true);
|
| | } else if (trashcan) {
|
| |
|
| | trashcan.close();
|
| | }
|
| | return this.wouldDeleteBlock_;
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_ = function(isOutside) {
|
| | this.wouldDeleteBlock_ = this.draggedConnectionManager_.wouldDeleteBlock();
|
| | var trashcan = this.workspace_.trashcan;
|
| | if (this.wouldDeleteBlock_) {
|
| | this.draggingBlock_.setDeleteStyle(true);
|
| | if (this.deleteArea_ == Blockly.DELETE_AREA_TRASH && trashcan) {
|
| | trashcan.setOpen_(true);
|
| | }
|
| | } else {
|
| | this.draggingBlock_.setDeleteStyle(false);
|
| | if (trashcan) {
|
| | trashcan.setOpen_(false);
|
| | }
|
| | }
|
| |
|
| | if (isOutside) {
|
| |
|
| | this.draggingBlock_.setMouseThroughStyle(true);
|
| | } else {
|
| | this.draggingBlock_.setMouseThroughStyle(false);
|
| | }
|
| | };
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | Blockly.BlockDragger.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.BlockDragger.prototype.dragIcons_ = function(dxy) {
|
| |
|
| | for (var i = 0; i < this.dragIconData_.length; i++) {
|
| | var data = this.dragIconData_[i];
|
| | data.icon.setIconLocation(goog.math.Coordinate.sum(data.location, dxy));
|
| | }
|
| | };
|
| |
|