SGraphDeleteCommand.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { SGraphCommand } from "@saga-web/graph/lib/commands/SGraphCommand";
  2. import { SGraphItem } from "@saga-web/graph/lib/SGraphItem";
  3. import { SGraphScene } from "@saga-web/graph/lib/SGraphScene";
  4. import { SUndoCommand } from "@saga-web/base/lib";
  5. /**
  6. * 添加item命令
  7. *
  8. * @author hanyaolong
  9. * */
  10. export class SGraphDeleteCommand extends SGraphCommand {
  11. /** 命令item对象 */
  12. item: SGraphItem;
  13. /** 命令item的父类 */
  14. parent: SGraphItem | null;
  15. /**
  16. * 构造函数
  17. *
  18. * @param scene item所在场景
  19. * @param item 命令item对象
  20. * */
  21. constructor(scene: SGraphScene, item: SGraphItem) {
  22. super(scene);
  23. this.item = item;
  24. this.parent = item.parent;
  25. } // Constructor
  26. /**
  27. * 合并命令
  28. *
  29. * @return boolean 是否已执行合并
  30. * */
  31. mergeWith(command: SUndoCommand): boolean {
  32. return false;
  33. } // Function mergeWith()
  34. /**
  35. * 重做
  36. *
  37. * */
  38. undo(): void {
  39. this.item.parent = this.parent;
  40. // @ts-ignore
  41. this.parent.update();
  42. } // Function redo()
  43. /**
  44. * 撤销
  45. *
  46. * */
  47. redo(): void {
  48. this.item.parent = null;
  49. // @ts-ignore
  50. this.parent.update();
  51. } // Function undo()
  52. } // Class SGraphAddCommand