Use onadd in link nodes to ensure imported links are updated

This commit is contained in:
Nick O'Leary 2016-05-18 16:48:16 +01:00
parent 3e9be9eed3
commit 5ad46106f4
3 changed files with 19 additions and 8 deletions

View File

@ -195,9 +195,6 @@ RED.nodes = (function() {
}
nodes.push(n);
}
if (n._def.onadd) {
n._def.onadd.call(n);
}
}
function addLink(l) {
links.push(l);

View File

@ -2208,6 +2208,14 @@ RED.view = (function() {
node.n.y -= minY;
node.dx -= minX;
node.dy -= minY;
if (node.n._def.onadd) {
try {
node.n._def.onadd.call(node.n);
} catch(err) {
console.log("onadd:",err);
}
}
}
if (!touchImport) {
mouse_mode = RED.state.IMPORT_DRAGGING;
@ -2218,7 +2226,6 @@ RED.view = (function() {
node.n._def.outputs > 0;
}
}
RED.keyboard.add("*",/* ESCAPE */ 27,function(){
RED.keyboard.remove(/* ESCAPE */ 27);
clearSelection();

View File

@ -236,16 +236,12 @@
i = n.links.indexOf(node.id);
if (i > -1) {
n.links.splice(i,1);
n.changed = true;
n.dirty = true;
}
} else if (!nodeMap[id].old && nodeMap[id].new){
// Added id
i = n.links.indexOf(id);
if (i === -1) {
n.links.push(node.id);
n.changed = true;
n.dirty = true;
}
}
}
@ -253,6 +249,15 @@
}
}
function onAdd() {
for (var i=0;i<this.links.length;i++) {
var n = RED.nodes.node(this.links[i]);
if (n.links.indexOf(this.id) === -1) {
n.links.push(this.id);
}
}
}
RED.nodes.registerType('link in',{
category: 'input',
color:"#ddd",//"#87D8CF",
@ -275,6 +280,7 @@
oneditsave: function() {
onEditSave(this);
},
onadd: onAdd,
oneditresize: resizeNodeList
});
@ -301,6 +307,7 @@
oneditsave: function() {
onEditSave(this);
},
onadd: onAdd,
oneditresize: resizeNodeList
});
})();