-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimported.js
More file actions
108 lines (104 loc) · 3.89 KB
/
Copy pathimported.js
File metadata and controls
108 lines (104 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* Decode an XML DOM and create blocks on the workspace, clearing out old blocks.
* @param {!Element} xml XML DOM.
* @param {!Blockly.Workspace} workspace The workspace.
*/
Blockly.Xml.domToWorkspaceDestructive = function(xml, workspace, errorXml) {
if (xml instanceof Blockly.Workspace) {
var swap = xml;
xml = workspace;
workspace = swap;
console.warn('Deprecated call to Blockly.Xml.domToWorkspace, ' +
'swap the arguments.');
}
var width; // Not used in LTR.
//console.log("imported, workspace: ", workspace); //CONTROLLOPROVA
//console.log("imported, xml: ", xml); //CONTROLLOPROVA
if (workspace.RTL) {
width = workspace.getWidth();
}
Blockly.Field.startCache();
// Safari 7.1.3 is known to provide node lists with extra references to
// children beyond the lists' length. Trust the length, do not use the
// looping pattern of checking the index for an object.
var childCount = xml.childNodes.length;
var existingGroup = Blockly.Events.getGroup();
if (!existingGroup) {
Blockly.Events.setGroup(true);
}
Blockly.Events.disable();
while (workspace.topBlocks_.length) {
workspace.topBlocks_[0].dispose();
}
workspace.variableList.length = 0;
Blockly.Events.enable();
// Disable workspace resizes as an optimization.
if (workspace.setResizesEnabled) {
workspace.setResizesEnabled(false);
}
for (var i = 0; i < childCount; i++) {
var xmlChild = xml.childNodes[i];
var name = xmlChild.nodeName.toLowerCase();
if (name == 'block' ||
(name == 'shadow' && !Blockly.Events.recordUndo)) {
// Allow top-level shadow blocks if recordUndo is disabled since
// that means an undo is in progress. Such a block is expected
// to be moved to a nested destination in the next operation.
var block = Blockly.Xml.domToBlock(xmlChild, workspace);
//console.log(block);
//console.log("CIAOOOOOOOOOOOOO")
var blockX = parseInt(xmlChild.getAttribute('x'), 10);
var blockY = parseInt(xmlChild.getAttribute('y'), 10);
if (!isNaN(blockX) && !isNaN(blockY)) {
block.moveBy(workspace.RTL ? width - blockX : blockX, blockY);
}
} else if (name == 'shadow') {
goog.asserts.fail('Shadow block cannot be a top-level block.');
}
}
if (!existingGroup) {
Blockly.Events.setGroup(false);
}
Blockly.Field.stopCache();
workspace.updateVariableList(false);
// Re-enable workspace resizing.
if (workspace.setResizesEnabled) {
workspace.setResizesEnabled(true);
}
}
function PLUS_MINUS_updateShape(listItemName, startMessage) {
return function() {
var that = this;
function addField(field, block, e) {
var rect = field.fieldGroup_.getBoundingClientRect();
var yPosition = e.clientY;
if (yPosition < rect.top+rect.height/2) {
var input = that.appendValueInput(listItemName + that.itemCount_);
that.itemCount_ += 1;
} else {
if (that.itemCount_ > 0) {
that.itemCount_ -= 1;
that.removeInput(listItemName + that.itemCount_)
}
}
}
if (!this.getInput('START')) {
var clickablePlusMinus = new Blockly.FieldClickImage("images/plus-minus-button.svg", 12, 24, '+', addField, '-2px');
//clickablePlusMinus.imageElement_.style.y = '-2px';
this.appendDummyInput('START')
.appendField(startMessage)
.appendField(clickablePlusMinus);
}
// Add new inputs.
for (var i = 0; i < this.itemCount_; i++) {
if (!this.getInput(listItemName + i)) {
var input = this.appendValueInput(listItemName + i);
}
}
// Remove deleted inputs.
while (this.getInput(listItemName + i)) {
this.removeInput(listItemName + i);
i++;
}
}
}