CmdSetScriptName.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Created by Daniel on 21.07.15.
  3. */
  4. CmdSetScriptName = function ( object, script, name ) {
  5. Cmd.call( this );
  6. this.type = 'CmdSetScriptName';
  7. this.object = object;
  8. this.script = script;
  9. this.oldName = script !== undefined ? script.name : undefined;
  10. this.newName = name;
  11. this.objectUuid = object !== undefined ? object.uuid : undefined;
  12. };
  13. CmdSetScriptName.prototype = {
  14. execute: function () {
  15. this.index = this.editor.scripts[ this.objectUuid ].indexOf( this.script );
  16. this.script.name = this.newName;
  17. this.editor.signals.scriptChanged.dispatch();
  18. this.editor.signals.refreshScriptEditor.dispatch( this.object, this.script );
  19. },
  20. undo: function () {
  21. this.script.name = this.oldName;
  22. this.editor.signals.scriptChanged.dispatch();
  23. this.editor.signals.refreshScriptEditor.dispatch( this.object, this.script );
  24. },
  25. toJSON: function () {
  26. var output = Cmd.prototype.toJSON.call( this );
  27. output.objectUuid = this.objectUuid;
  28. output.index = this.index;
  29. output.oldName = this.oldName;
  30. output.newName = this.newName;
  31. return output;
  32. },
  33. fromJSON: function ( json ) {
  34. Cmd.prototype.fromJSON.call( this, json );
  35. this.objectUuid = json.objectUuid;
  36. this.index = json.index;
  37. this.oldName = json.oldName;
  38. this.newName = json.newName;
  39. this.object = this.editor.objectByUuid( json.objectUuid );
  40. this.script = this.editor.scripts[ json.objectUuid ][ json.index ];
  41. }
  42. };