Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/common/lightDarkSwitch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { injectable } from "inversify";
import { injectable, multiInject } from "inversify";
import "./lightDarkSwitch.css";
import { AbstractUIExtension } from "sprotty";

export const SWITCHABLE = Symbol("Switchable");

export interface Switchable {
switchTheme(useDark: boolean): void;
}

@injectable()
export class LightDarkSwitch extends AbstractUIExtension {
static readonly ID = "light-dark-switch";
static useDarkMode = false;

constructor(@multiInject(SWITCHABLE) protected switchables: Switchable[]) {
super();
}

id(): string {
return LightDarkSwitch.ID;
}
Expand Down Expand Up @@ -41,5 +51,6 @@ export class LightDarkSwitch extends AbstractUIExtension {
const value = useDark ? "dark" : "light";
rootElement.setAttribute("data-theme", value);
sprottyElement.setAttribute("data-theme", value);
this.switchables.forEach((s) => s.switchTheme(useDark));
}
}
7 changes: 6 additions & 1 deletion src/features/dfdElements/di.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { DfdNodeAnnotationUI, DfdNodeAnnotationUIMouseListener } from "./nodeAnn
import { DFDBehaviorRefactorer, RefactorInputNameInDFDBehaviorCommand } from "./behaviorRefactorer";

import "./elementStyles.css";
import { SWITCHABLE } from "../../common/lightDarkSwitch";

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

bind(PortBehaviorValidator).toSelf().inSingletonScope();
bind(TYPES.IUIExtension).to(OutputPortEditUI).inSingletonScope();

bind(OutputPortEditUI).toSelf().inSingletonScope();
bind(TYPES.IUIExtension).toService(OutputPortEditUI);
bind(SWITCHABLE).toService(OutputPortEditUI);

bind(TYPES.MouseListener).to(OutputPortEditUIMouseListener).inSingletonScope();
configureCommand(context, SetDfdOutputPortBehaviorCommand);

Expand Down
9 changes: 7 additions & 2 deletions src/features/dfdElements/outputPortEditUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import "monaco-editor/esm/vs/editor/contrib/hover/browser/hover";
import "monaco-editor/esm/vs/editor/contrib/inlineCompletions/browser/inlineCompletions.contribution.js";

import "./outputPortEditUi.css";
import { LightDarkSwitch, Switchable } from "../../common/lightDarkSwitch";

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

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

const monacoTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "vs-dark" : "vs";
const monacoTheme = LightDarkSwitch?.useDarkMode ?? true ? "vs-dark" : "vs";
this.editor = monaco.editor.create(this.editorContainer, {
minimap: {
// takes too much space, not useful for our use case
Expand Down Expand Up @@ -656,6 +657,10 @@ export class OutputPortEditUI extends AbstractUIExtension {
public getCurrentEditingPort(): DfdOutputPortImpl | undefined {
return this.port;
}

switchTheme(useDark: boolean): void {
this.editor?.updateOptions({ theme: useDark ? "vs-dark" : "vs" });
}
}

/**
Expand Down
Loading