mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Add missing move when unshadowing and missing XY when deleting.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
20
core/xml.js
20
core/xml.js
@@ -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.
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
maxBlocks: 5,
|
||||
toolbox: document.getElementById('toolbox')});
|
||||
|
||||
function onchange() {
|
||||
function onchange(event) {
|
||||
document.getElementById('capacity').innerHTML =
|
||||
workspace.remainingCapacity();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user