Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

86 lines
3.2KB

  1. /**
  2. * Copyright 2013 IBM Corp.
  3. *
  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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. **/
  16. RED.history = (function() {
  17. var undo_history = [];
  18. return {
  19. //TODO: this function is a placeholder until there is a 'save' event that can be listened to
  20. markAllDirty: function() {
  21. for (var i=0;i<undo_history.length;i++) {
  22. undo_history[i].dirty = true;
  23. }
  24. },
  25. depth: function() {
  26. return undo_history.length;
  27. },
  28. push: function(ev) {
  29. undo_history.push(ev);
  30. },
  31. pop: function() {
  32. var ev = undo_history.pop();
  33. var i;
  34. if (ev) {
  35. if (ev.t == 'add') {
  36. for (i=0;i<ev.nodes.length;i++) {
  37. RED.nodes.remove(ev.nodes[i]);
  38. }
  39. for (i=0;i<ev.links.length;i++) {
  40. RED.nodes.removeLink(ev.links[i]);
  41. }
  42. for (i=0;i<ev.workspaces.length;i++) {
  43. RED.nodes.removeWorkspace(ev.workspaces[i].id);
  44. RED.view.removeWorkspace(ev.workspaces[i]);
  45. }
  46. } else if (ev.t == "delete") {
  47. for (i=0;i<ev.workspaces.length;i++) {
  48. RED.nodes.addWorkspace(ev.workspaces[i]);
  49. RED.view.addWorkspace(ev.workspaces[i]);
  50. }
  51. for (i=0;i<ev.nodes.length;i++) {
  52. RED.nodes.add(ev.nodes[i]);
  53. }
  54. for (i=0;i<ev.links.length;i++) {
  55. RED.nodes.addLink(ev.links[i]);
  56. }
  57. } else if (ev.t == "move") {
  58. for (i=0;i<ev.nodes.length;i++) {
  59. var n = ev.nodes[i];
  60. n.n.x = n.ox;
  61. n.n.y = n.oy;
  62. n.n.dirty = true;
  63. }
  64. } else if (ev.t == "edit") {
  65. for (i in ev.changes) {
  66. if (ev.changes.hasOwnProperty(i)) {
  67. ev.node[i] = ev.changes[i];
  68. }
  69. }
  70. RED.editor.updateNodeProperties(ev.node);
  71. for (i=0;i<ev.links.length;i++) {
  72. RED.nodes.addLink(ev.links[i]);
  73. }
  74. RED.editor.validateNode(ev.node);
  75. ev.node.dirty = true;
  76. ev.node.changed = ev.changed;
  77. }
  78. RED.view.dirty(ev.dirty);
  79. RED.view.redraw();
  80. }
  81. }
  82. }
  83. })();