Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.

Commit f91e553

Browse files
committed
Feat: adjust commands
1 parent 5626595 commit f91e553

2 files changed

Lines changed: 43 additions & 49 deletions

File tree

src/features/constraintMenu/ConstraintMenu.ts

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { inject, injectable, optional } from "inversify";
22
import "./constraintMenu.css";
33
import { AbstractUIExtension, IActionDispatcher, LocalModelSource, TYPES } from "sprotty";
4-
import { Constraint, ConstraintRegistry } from "./constraintRegistry";
4+
import { ConstraintRegistry } from "./constraintRegistry";
55

66
// Enable hover feature that is used to show validation errors.
77
// Inline completions are enabled to allow autocompletion of keywords and inputs/label types/label values.
@@ -19,7 +19,7 @@ import { LabelTypeRegistry } from "../labels/labelTypeRegistry";
1919
import { EditorModeController } from "../editorMode/editorModeController";
2020
import { Switchable, ThemeManager } from "../settingsMenu/themeManager";
2121
import { AnalyzeDiagramAction } from "../serialize/analyze";
22-
import { ChooseConstraintAction } from "./actions";
22+
import { ChooseConstraintAction } from "./actions";
2323

2424
@injectable()
2525
export class ConstraintMenu extends AbstractUIExtension implements Switchable {
@@ -236,7 +236,7 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
236236
const btn = document.createElement("button");
237237
btn.id = "constraint-options-button";
238238
btn.title = "Filter…";
239-
btn.innerHTML = "⋮"; // or insert a font-awesome icon
239+
btn.innerHTML = "⋮"; // or insert a font-awesome icon
240240
btn.onclick = () => this.toggleOptionsMenu();
241241
return btn;
242242
}
@@ -253,46 +253,39 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
253253
this.optionsMenu = document.createElement("div");
254254
this.optionsMenu.id = "constraint-options-menu";
255255

256-
// 2) add the “All constraints” checkbox at the top
257-
const allConstraints = document.createElement("label");
258-
allConstraints.classList.add("options-item");
259-
260-
const allCb = document.createElement("input");
261-
allCb.type = "checkbox";
262-
allCb.value = "ALL";
263-
// initially checked if no specific constraint is selected
264-
allCb.checked = this.constraintRegistry.getSelectedConstraints().includes("ALL");
265-
266-
allCb.onchange = () => {
267-
if (!this.optionsMenu) return;
268-
if (allCb.checked) {
269-
// uncheck every other constraint-checkbox
270-
this.optionsMenu
271-
.querySelectorAll<HTMLInputElement>("input[type=checkbox]")
272-
.forEach(cb => {
273-
if (cb !== allCb) cb.checked = false;
274-
});
275-
// dispatch with empty array to mean “all”
276-
this.dispatcher.dispatch(
277-
ChooseConstraintAction.create(["ALL"])
278-
);
279-
} else {
280-
this.dispatcher.dispatch(
281-
ChooseConstraintAction.create([])
282-
);
283-
}
284-
285-
};
286-
287-
allConstraints.appendChild(allCb);
288-
allConstraints.appendChild(document.createTextNode("All constraints"));
256+
// 2) add the “All constraints” checkbox at the top
257+
const allConstraints = document.createElement("label");
258+
allConstraints.classList.add("options-item");
259+
260+
const allCb = document.createElement("input");
261+
allCb.type = "checkbox";
262+
allCb.value = "ALL";
263+
// initially checked if no specific constraint is selected
264+
allCb.checked = this.constraintRegistry.getSelectedConstraints().includes("ALL");
265+
266+
allCb.onchange = () => {
267+
if (!this.optionsMenu) return;
268+
if (allCb.checked) {
269+
// uncheck every other constraint-checkbox
270+
this.optionsMenu.querySelectorAll<HTMLInputElement>("input[type=checkbox]").forEach((cb) => {
271+
if (cb !== allCb) cb.checked = false;
272+
});
273+
// dispatch with empty array to mean “all”
274+
this.dispatcher.dispatch(ChooseConstraintAction.create(["ALL"]));
275+
} else {
276+
this.dispatcher.dispatch(ChooseConstraintAction.create([]));
277+
}
278+
};
279+
280+
allConstraints.appendChild(allCb);
281+
allConstraints.appendChild(document.createTextNode("All constraints"));
289282
this.optionsMenu.appendChild(allConstraints);
290283

291284
// 2) pull your dynamic items (replace with your real API)
292285
const items = this.constraintRegistry.getConstraintList();
293286

294287
// 3) for each item build a checkbox
295-
items.forEach(item => {
288+
items.forEach((item) => {
296289
const label = document.createElement("label");
297290
label.classList.add("options-item");
298291

@@ -305,14 +298,12 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
305298
if (cb.checked) allCb.checked = false;
306299

307300
const selected = Array.from(
308-
this.optionsMenu!.querySelectorAll<HTMLInputElement>("input[type=checkbox]:checked")
309-
).map(cb => cb.value);
301+
this.optionsMenu!.querySelectorAll<HTMLInputElement>("input[type=checkbox]:checked"),
302+
).map((cb) => cb.value);
310303

311304
// dispatch your action with either an array or
312305
// a comma-joined string—whatever your action expects
313-
this.dispatcher.dispatch(
314-
ChooseConstraintAction.create(selected)
315-
);
306+
this.dispatcher.dispatch(ChooseConstraintAction.create(selected));
316307
};
317308

318309
label.appendChild(cb);
@@ -324,8 +315,11 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
324315

325316
// optional: click-outside handler
326317
const onClickOutside = (e: MouseEvent) => {
327-
if (this.optionsMenu && !this.optionsMenu.contains(e.target as Node)
328-
&& !(e.target as Element).matches("#constraint-options-button")) {
318+
if (
319+
this.optionsMenu &&
320+
!this.optionsMenu.contains(e.target as Node) &&
321+
!(e.target as Element).matches("#constraint-options-button")
322+
) {
329323
this.toggleOptionsMenu();
330324
document.removeEventListener("click", onClickOutside);
331325
}

src/features/editorMode/command.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class ChangeEditorModeCommand extends Command {
2323
static readonly KIND = ChangeEditorModeAction.KIND;
2424

2525
private oldMode?: EditorMode;
26-
private oldNodeAnnotations: Map<string, DfdNodeAnnotation> = new Map();
26+
private oldNodeAnnotations: Map<string, DfdNodeAnnotation[]> = new Map();
2727

2828
@inject(EditorModeController)
2929
private readonly controller?: EditorModeController;
@@ -65,9 +65,9 @@ export class ChangeEditorModeCommand extends Command {
6565

6666
this.oldNodeAnnotations.clear();
6767
context.root.index.all().forEach((element) => {
68-
if (element instanceof DfdNodeImpl && element.annotation) {
69-
this.oldNodeAnnotations.set(element.id, element.annotation);
70-
element.annotation = undefined;
68+
if (element instanceof DfdNodeImpl && element.annotations) {
69+
this.oldNodeAnnotations.set(element.id, element.annotations);
70+
element.annotations = [];
7171
}
7272
});
7373
}
@@ -79,7 +79,7 @@ export class ChangeEditorModeCommand extends Command {
7979
this.oldNodeAnnotations.forEach((annotation, id) => {
8080
const element = context.root.index.getById(id);
8181
if (element instanceof DfdNodeImpl) {
82-
element.annotation = annotation;
82+
element.annotations = annotation;
8383
}
8484
});
8585
}

0 commit comments

Comments
 (0)