CmdSetUuid.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Created by Daniel on 21.07.15.
  3. */
  4. CmdSetUuid = function ( object, newUuid ) {
  5. Cmd.call( this );
  6. this.type = 'CmdSetUuid';
  7. this.object = object;
  8. this.oldUuid = object !== undefined ? object.uuid : undefined;
  9. this.newUuid = newUuid;
  10. };
  11. CmdSetUuid.prototype = {
  12. execute: function () {
  13. this.object.uuid = this.newUuid;
  14. this.editor.signals.objectChanged.dispatch( this.object );
  15. this.editor.signals.sceneGraphChanged.dispatch();
  16. this.editor.signals.updateSidebar.dispatch();
  17. },
  18. undo: function () {
  19. this.object.uuid = this.oldUuid;
  20. this.editor.signals.objectChanged.dispatch( this.object );
  21. this.editor.signals.sceneGraphChanged.dispatch();
  22. this.editor.signals.updateSidebar.dispatch();
  23. },
  24. toJSON: function () {
  25. var output = Cmd.prototype.toJSON.call( this );
  26. output.oldUuid = this.oldUuid;
  27. output.newUuid = this.newUuid;
  28. return output;
  29. },
  30. fromJSON: function ( json ) {
  31. Cmd.prototype.fromJSON.call( this, json );
  32. this.oldUuid = json.oldUuid;
  33. this.newUuid = json.newUuid;
  34. this.object = this.editor.objectByUuid( json.oldUuid );
  35. if ( this.object === undefined ) {
  36. this.object = this.editor.objectByUuid( json.newUuid );
  37. }
  38. }
  39. };