CmdMultiCmds.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * Created by Daniel on 20.07.15.
  3. */
  4. CmdMultiCmds = function ( cmdArray ) {
  5. Cmd.call( this );
  6. this.type = 'CmdMultiCmds';
  7. this.name = 'Multiple Changes';
  8. this.cmdArray = cmdArray !== undefined ? cmdArray : [];
  9. };
  10. CmdMultiCmds.prototype = {
  11. execute: function () {
  12. this.editor.signals.sceneGraphChanged.active = false;
  13. for ( var i = 0; i < this.cmdArray.length; i++ ) {
  14. this.cmdArray[ i ].editor = this.editor;
  15. this.cmdArray[ i ].execute();
  16. }
  17. this.editor.signals.sceneGraphChanged.active = true;
  18. this.editor.signals.sceneGraphChanged.dispatch();
  19. },
  20. undo: function () {
  21. this.editor.signals.sceneGraphChanged.active = false;
  22. for ( var i = this.cmdArray.length - 1; i >= 0; i-- ) {
  23. this.cmdArray[ i ].undo();
  24. }
  25. this.editor.signals.sceneGraphChanged.active = true;
  26. this.editor.signals.sceneGraphChanged.dispatch();
  27. },
  28. toJSON: function () {
  29. var output = Cmd.prototype.toJSON.call( this );
  30. var cmds = [];
  31. for ( var i = 0; i < this.cmdArray.length; i++ ) {
  32. cmds.push( this.cmdArray[ i ].toJSON() );
  33. }
  34. output.cmds = cmds;
  35. return output;
  36. },
  37. fromJSON: function ( json ) {
  38. Cmd.prototype.fromJSON.call( this, json );
  39. var cmds = json.cmds;
  40. for ( var i = 0; i < cmds.length; i++ ) {
  41. var cmd = new window[ cmds[ i ].type ](); // creates a new object of type "json.type"
  42. cmd.editor = this.editor;
  43. cmd.fromJSON( cmds[ i ] );
  44. this.cmdArray.push( cmd );
  45. }
  46. }
  47. };