您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

93 行
2.6KB

  1. /** Modified from original Node-Red source, for audio system visualization
  2. * vim: set ts=4:
  3. * Copyright 2013 IBM Corp.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. **/
  17. RED.history = (function() {
  18. var undo_history = [];
  19. return {
  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;
  24. }
  25. },
  26. depth: function() {
  27. return undo_history.length;
  28. },
  29. push: function(ev) {
  30. undo_history.push(ev);
  31. },
  32. pop: function() {
  33. var ev = undo_history.pop();
  34. var i;
  35. if (ev) {
  36. if (ev.t == 'add') {
  37. for (i=0;i<ev.nodes.length;i++) {
  38. RED.nodes.remove(ev.nodes[i]);
  39. }
  40. for (i=0;i<ev.links.length;i++) {
  41. RED.nodes.removeLink(ev.links[i]);
  42. }
  43. for (i=0;i<ev.workspaces.length;i++) {
  44. RED.nodes.removeWorkspace(ev.workspaces[i].id);
  45. RED.view.removeWorkspace(ev.workspaces[i]);
  46. }
  47. } else if (ev.t == "delete") {
  48. for (i=0;i<ev.workspaces.length;i++) {
  49. RED.nodes.addWorkspace(ev.workspaces[i]);
  50. RED.view.addWorkspace(ev.workspaces[i]);
  51. }
  52. for (i=0;i<ev.nodes.length;i++) {
  53. RED.nodes.add(ev.nodes[i]);
  54. }
  55. for (i=0;i<ev.links.length;i++) {
  56. RED.nodes.addLink(ev.links[i]);
  57. }
  58. } else if (ev.t == "move") {
  59. for (i=0;i<ev.nodes.length;i++) {
  60. var n = ev.nodes[i];
  61. n.n.x = n.ox;
  62. n.n.y = n.oy;
  63. n.n.dirty = true;
  64. }
  65. } else if (ev.t == "edit") {
  66. for (i in ev.changes) {
  67. if (ev.changes.hasOwnProperty(i)) {
  68. ev.node[i] = ev.changes[i];
  69. }
  70. }
  71. RED.editor.updateNodeProperties(ev.node);
  72. for (i=0;i<ev.links.length;i++) {
  73. RED.nodes.addLink(ev.links[i]);
  74. }
  75. RED.editor.validateNode(ev.node);
  76. ev.node.dirty = true;
  77. ev.node.changed = ev.changed;
  78. }
  79. RED.view.dirty(ev.dirty);
  80. RED.view.redraw();
  81. }
  82. }
  83. }
  84. })();
  85. RED.validators = {
  86. number: function(){return function(v) { return v!=='' && !isNaN(v);}},
  87. regex: function(re){return function(v) { return re.test(v);}}
  88. };