1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add undo support for config-node delete

This commit is contained in:
Nick O'Leary 2015-09-25 21:49:53 +01:00
parent f2b73187d8
commit a9a0b263dc
2 changed files with 29 additions and 3 deletions

View File

@ -145,6 +145,20 @@ RED.history = (function() {
RED.nodes.addLink(ev.links[i]); RED.nodes.addLink(ev.links[i]);
} }
} }
if (ev.changes) {
for (i in ev.changes) {
if (ev.changes.hasOwnProperty(i)) {
node = RED.nodes.node(i);
for (var d in ev.changes[i]) {
if (ev.changes[i].hasOwnProperty(d)) {
node[d] = ev.changes[i][d];
}
}
node.dirty = true;
}
}
}
} else if (ev.t == "move") { } else if (ev.t == "move") {
for (i=0;i<ev.nodes.length;i++) { for (i=0;i<ev.nodes.length;i++) {
var n = ev.nodes[i]; var n = ev.nodes[i];
@ -191,9 +205,6 @@ RED.history = (function() {
if (ev.node.type === 'subflow') { if (ev.node.type === 'subflow') {
$("#menu-item-flow-menu-"+ev.node.id.replace(".","-")).text(ev.node.name); $("#menu-item-flow-menu-"+ev.node.id.replace(".","-")).text(ev.node.name);
} }
RED.palette.refresh();
RED.workspaces.refresh();
} else { } else {
RED.editor.updateNodeProperties(ev.node); RED.editor.updateNodeProperties(ev.node);
RED.editor.validateNode(ev.node); RED.editor.validateNode(ev.node);
@ -240,6 +251,7 @@ RED.history = (function() {
RED.nodes.dirty(ev.dirty); RED.nodes.dirty(ev.dirty);
RED.view.redraw(true); RED.view.redraw(true);
RED.palette.refresh(); RED.palette.refresh();
RED.workspaces.refresh();
} }
} }
} }

View File

@ -735,12 +735,25 @@ RED.editor = (function() {
if (configTypeDef.oneditdelete) { if (configTypeDef.oneditdelete) {
configTypeDef.oneditdelete.call(RED.nodes.node(configId)); configTypeDef.oneditdelete.call(RED.nodes.node(configId));
} }
var historyEvent = {
t:'delete',
nodes:[configNode],
changes: {},
dirty: RED.nodes.dirty()
}
RED.nodes.remove(configId); RED.nodes.remove(configId);
for (var i=0;i<configNode.users.length;i++) { for (var i=0;i<configNode.users.length;i++) {
var user = configNode.users[i]; var user = configNode.users[i];
historyEvent.changes[user.id] = {
changed: user.changed,
valid: user.valid
};
for (var d in user._def.defaults) { for (var d in user._def.defaults) {
if (user._def.defaults.hasOwnProperty(d) && user[d] == configId) { if (user._def.defaults.hasOwnProperty(d) && user[d] == configId) {
historyEvent.changes[user.id][d] = configId
user[d] = ""; user[d] = "";
user.changed = true;
user.dirty = true;
} }
} }
validateNode(user); validateNode(user);
@ -749,6 +762,7 @@ RED.editor = (function() {
RED.nodes.dirty(true); RED.nodes.dirty(true);
$( this ).dialog( "close" ); $( this ).dialog( "close" );
RED.view.redraw(); RED.view.redraw();
RED.history.push(historyEvent);
} }
}); });
} }