CmdSetValue.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Created by Daniel on 21.07.15.
  3. */
  4. CmdSetValue = function ( object, attributeName, newValue ) {
  5. Cmd.call( this );
  6. this.type = 'CmdSetValue';
  7. this.name = 'Set ' + attributeName;
  8. this.updatable = true;
  9. this.object = object;
  10. this.attributeName = attributeName;
  11. this.oldValue = ( object !== undefined ) ? object[ attributeName ] : undefined;
  12. this.newValue = newValue;
  13. this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
  14. };
  15. CmdSetValue.prototype = {
  16. init: function () {
  17. if ( this.object === undefined ) {
  18. this.object = this.editor.objectByUuid( this.objectUuid );
  19. }
  20. },
  21. execute: function () {
  22. this.init();
  23. this.object[ this.attributeName ] = this.newValue;
  24. this.editor.signals.objectChanged.dispatch( this.object );
  25. this.editor.signals.sceneGraphChanged.dispatch();
  26. this.editor.signals.updateSidebar.dispatch();
  27. },
  28. undo: function () {
  29. this.init();
  30. this.object[ this.attributeName ] = this.oldValue;
  31. this.editor.signals.objectChanged.dispatch( this.object );
  32. this.editor.signals.sceneGraphChanged.dispatch();
  33. this.editor.signals.updateSidebar.dispatch();
  34. },
  35. update: function ( cmd ) {
  36. this.newValue = cmd.newValue;
  37. },
  38. toJSON: function () {
  39. var output = Cmd.prototype.toJSON.call( this );
  40. output.objectUuid = this.objectUuid;
  41. output.attributeName = this.attributeName;
  42. output.oldValue = this.oldValue;
  43. output.newValue = this.newValue;
  44. return output;
  45. },
  46. fromJSON: function ( json ) {
  47. Cmd.prototype.fromJSON.call( this, json );
  48. this.objectUuid = json.objectUuid;
  49. this.attributeName = json.attributeName;
  50. this.oldValue = json.oldValue;
  51. this.newValue = json.newValue;
  52. }
  53. };