2 * Copyright 2013 IBM Corp.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 RED.history = (function() {
17 var undo_history = [];
20 //TODO: this function is a placeholder until there is a 'save' event that can be listened to
21 markAllDirty: function() {
22 for (var i=0;i<undo_history.length;i++) {
23 undo_history[i].dirty = true;
27 return undo_history.length;
30 undo_history.push(ev);
33 var ev = undo_history.pop();
38 for (i=0;i<ev.nodes.length;i++) {
39 RED.nodes.remove(ev.nodes[i]);
43 for (i=0;i<ev.links.length;i++) {
44 RED.nodes.removeLink(ev.links[i]);
48 for (i=0;i<ev.workspaces.length;i++) {
49 RED.nodes.removeWorkspace(ev.workspaces[i].id);
50 RED.view.removeWorkspace(ev.workspaces[i]);
53 } else if (ev.t == "delete") {
55 for (i=0;i<ev.workspaces.length;i++) {
56 RED.nodes.addWorkspace(ev.workspaces[i]);
57 RED.view.addWorkspace(ev.workspaces[i]);
61 for (i=0;i<ev.nodes.length;i++) {
62 RED.nodes.add(ev.nodes[i]);
66 for (i=0;i<ev.links.length;i++) {
67 RED.nodes.addLink(ev.links[i]);
70 } else if (ev.t == "move") {
71 for (i=0;i<ev.nodes.length;i++) {
77 } else if (ev.t == "edit") {
78 for (i in ev.changes) {
79 if (ev.changes.hasOwnProperty(i)) {
80 ev.node[i] = ev.changes[i];
83 RED.editor.updateNodeProperties(ev.node);
85 for (i=0;i<ev.links.length;i++) {
86 RED.nodes.addLink(ev.links[i]);
89 RED.editor.validateNode(ev.node);
91 ev.node.changed = ev.changed;
93 RED.view.dirty(ev.dirty);