Forráskód Böngészése

implementation of trash

Victor Luiz Domingues 3 éve
szülő
commit
4723620b62

+ 19 - 0
src/app/component-registry/trash-component.js

@@ -0,0 +1,19 @@
+import { TrashDrawer } from "../components/trash-component/drawers/trash-drawer";
+import { Component } from "../core/models/components/component";
+import { ComponentOptions } from "../core/models/components/component-options";
+class TrashComponent extends Component {
+  constructor() {
+    const options = new ComponentOptions(
+      "2e0a8b90-2ef0-4c71-893f-cf2b55303589",
+      "trash",
+      "trash"
+    );
+    super(new TrashDrawer(), options);
+    document.addEventListener('keyup', (event) => {
+      if (event.key === "Delete")
+        this.draw(event);
+    });
+  }
+}
+
+export const trashComponent = new TrashComponent();

+ 36 - 0
src/app/components/trash-component/drawers/trash-drawer.js

@@ -0,0 +1,36 @@
+import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
+import { SelectableDrawer } from "../../../core/drawers/selectable-drawer";
+import { objects as Objects } from "../../../core/application/objects";
+
+export class TrashDrawer extends SelectableDrawer {
+  constructor() {
+    super();
+
+    this.setElementClass(ELEMENTS_CLASS.NONE);
+  }
+
+  draw(e) {
+    const objects = Objects.getSelectedObjects();
+    objects.forEach(aggregator => {
+      this.delete(aggregator);
+    });
+    super.batchDraw();
+    return;
+  }
+
+  delete(aggregator) {
+
+    Objects.removeAggregator(aggregator);
+    aggregator.aggregators.forEach(dependenceAggregator => {
+      this.delete(dependenceAggregator);
+
+    });
+    aggregator.visible = false;
+
+  }
+
+  update(aggregator, e) {
+
+    return;
+  }
+}