Add missing move when unshadowing and missing XY when deleting.

This commit is contained in:
Neil Fraser
2016-02-12 19:34:51 -08:00
parent 62f86658ff
commit 1d44036cf9
4 changed files with 27 additions and 12 deletions

View File

@@ -514,6 +514,13 @@ Blockly.Block.prototype.setShadow = function(shadow) {
// Fire a creation event.
var xmlBlock = Blockly.Xml.blockToDom(this);
Blockly.Events.fire(new Blockly.Events.Create(this.workspace, xmlBlock));
var moveEvent = new Blockly.Events.Move(this);
// Claim that the block was at 0,0 and is being connected.
moveEvent.oldParentId = undefined;
moveEvent.oldInputName = undefined;
moveEvent.oldCoordinate = new goog.math.Coordinate(0, 0);
moveEvent.recordNew();
Blockly.Events.fire(moveEvent);
}
};

View File

@@ -193,15 +193,13 @@ goog.inherits(Blockly.Events.Create, Blockly.Events.Abstract);
* @constructor
*/
Blockly.Events.Delete = function(block) {
if (block.getParent()) {
throw 'Connected blocks cannot be deleted.';
}
this.type = Blockly.Events.DELETE;
this.workspaceId = block.workspace.id;
this.blockId = block.id;
this.oldXml = Blockly.Xml.blockToDom(block);
var parent = block.getParent();
if (parent) {
this.oldParentId = parent.id;
this.oldInput = getInputWithBlock(block).name
}
this.oldXml = Blockly.Xml.blockToDomWithXY(block);
};
goog.inherits(Blockly.Events.Delete, Blockly.Events.Abstract);

View File

@@ -44,15 +44,25 @@ Blockly.Xml.workspaceToDom = function(workspace) {
var xml = goog.dom.createDom('xml');
var blocks = workspace.getTopBlocks(true);
for (var i = 0, block; block = blocks[i]; i++) {
var element = Blockly.Xml.blockToDom(block);
var xy = block.getRelativeToSurfaceXY();
element.setAttribute('x', Math.round(workspace.RTL ? width - xy.x : xy.x));
element.setAttribute('y', Math.round(xy.y));
xml.appendChild(element);
xml.appendChild(Blockly.Xml.blockToDomWithXY(block));
}
return xml;
};
/**
* Encode a block subtree as XML with XY coordinates.
* @param {!Blockly.Block} block The root block to encode.
* @return {!Element} Tree of XML elements.
*/
Blockly.Xml.blockToDomWithXY = function(block) {
var element = Blockly.Xml.blockToDom(block);
var xy = block.getRelativeToSurfaceXY();
element.setAttribute('x',
Math.round(block.workspace.RTL ? width - xy.x : xy.x));
element.setAttribute('y', Math.round(xy.y));
return element;
};
/**
* Encode a block subtree as XML.
* @param {!Blockly.Block} block The root block to encode.

View File

@@ -85,7 +85,7 @@
maxBlocks: 5,
toolbox: document.getElementById('toolbox')});
function onchange() {
function onchange(event) {
document.getElementById('capacity').innerHTML =
workspace.remainingCapacity();
}