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

Commit ea2e4e8

Browse files
committed
switch theme on behavior editor
1 parent cdfae92 commit ea2e4e8

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/common/lightDarkSwitch.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
import { injectable } from "inversify";
1+
import { injectable, multiInject } from "inversify";
22
import "./lightDarkSwitch.css";
33
import { AbstractUIExtension } from "sprotty";
44

5+
export const SWITCHABLE = Symbol("Switchable");
6+
7+
export interface Switchable {
8+
switchTheme(useDark: boolean): void;
9+
}
10+
511
@injectable()
612
export class LightDarkSwitch extends AbstractUIExtension {
713
static readonly ID = "light-dark-switch";
814
static useDarkMode = false;
915

16+
constructor(@multiInject(SWITCHABLE) protected switchables: Switchable[]) {
17+
super();
18+
}
19+
1020
id(): string {
1121
return LightDarkSwitch.ID;
1222
}
@@ -41,5 +51,6 @@ export class LightDarkSwitch extends AbstractUIExtension {
4151
const value = useDark ? "dark" : "light";
4252
rootElement.setAttribute("data-theme", value);
4353
sprottyElement.setAttribute("data-theme", value);
54+
this.switchables.forEach((s) => s.switchTheme(useDark));
4455
}
4556
}

src/features/dfdElements/di.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { DfdNodeAnnotationUI, DfdNodeAnnotationUIMouseListener } from "./nodeAnn
2323
import { DFDBehaviorRefactorer, RefactorInputNameInDFDBehaviorCommand } from "./behaviorRefactorer";
2424

2525
import "./elementStyles.css";
26+
import { SWITCHABLE } from "../../common/lightDarkSwitch";
2627

2728
export const dfdElementsModule = new ContainerModule((bind, unbind, isBound, rebind) => {
2829
const context = { bind, unbind, isBound, rebind };
@@ -32,7 +33,11 @@ export const dfdElementsModule = new ContainerModule((bind, unbind, isBound, reb
3233
configureCommand(context, ReSnapPortsAfterLabelChangeCommand);
3334

3435
bind(PortBehaviorValidator).toSelf().inSingletonScope();
35-
bind(TYPES.IUIExtension).to(OutputPortEditUI).inSingletonScope();
36+
37+
bind(OutputPortEditUI).toSelf().inSingletonScope();
38+
bind(TYPES.IUIExtension).toService(OutputPortEditUI);
39+
bind(SWITCHABLE).toService(OutputPortEditUI);
40+
3641
bind(TYPES.MouseListener).to(OutputPortEditUIMouseListener).inSingletonScope();
3742
configureCommand(context, SetDfdOutputPortBehaviorCommand);
3843

src/features/dfdElements/outputPortEditUi.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import "monaco-editor/esm/vs/editor/contrib/hover/browser/hover";
3232
import "monaco-editor/esm/vs/editor/contrib/inlineCompletions/browser/inlineCompletions.contribution.js";
3333

3434
import "./outputPortEditUi.css";
35+
import { LightDarkSwitch, Switchable } from "../../common/lightDarkSwitch";
3536

3637
/**
3738
* Detects when a dfd output port is double clicked and shows the OutputPortEditUI
@@ -354,7 +355,7 @@ class MonacoEditorDfdBehaviorCompletionProvider implements monaco.languages.Comp
354355
* UI that allows editing the behavior text of a dfd output port (DfdOutputPortImpl).
355356
*/
356357
@injectable()
357-
export class OutputPortEditUI extends AbstractUIExtension {
358+
export class OutputPortEditUI extends AbstractUIExtension implements Switchable {
358359
static readonly ID = "output-port-edit-ui";
359360

360361
private unavailableInputsLabel: HTMLDivElement = document.createElement("div") as HTMLDivElement;
@@ -417,7 +418,7 @@ export class OutputPortEditUI extends AbstractUIExtension {
417418
new MonacoEditorDfdBehaviorCompletionProvider(this, this.labelTypeRegistry),
418419
);
419420

420-
const monacoTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "vs-dark" : "vs";
421+
const monacoTheme = LightDarkSwitch?.useDarkMode ?? true ? "vs-dark" : "vs";
421422
this.editor = monaco.editor.create(this.editorContainer, {
422423
minimap: {
423424
// takes too much space, not useful for our use case
@@ -656,6 +657,10 @@ export class OutputPortEditUI extends AbstractUIExtension {
656657
public getCurrentEditingPort(): DfdOutputPortImpl | undefined {
657658
return this.port;
658659
}
660+
661+
switchTheme(useDark: boolean): void {
662+
this.editor?.updateOptions({ theme: useDark ? "vs-dark" : "vs" });
663+
}
659664
}
660665

661666
/**

0 commit comments

Comments
 (0)