From ace59ce8a0c51c98664649f5e08bdbd3739f52c7 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sat, 11 Apr 2026 13:25:29 +0200 Subject: [PATCH] Add set project name command --- src/commands/set-project-name-command.ts | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/commands/set-project-name-command.ts diff --git a/src/commands/set-project-name-command.ts b/src/commands/set-project-name-command.ts new file mode 100644 index 00000000..5b59e791 --- /dev/null +++ b/src/commands/set-project-name-command.ts @@ -0,0 +1,37 @@ +import { createOpaqueId } from "../core/ids"; +import { DEFAULT_PROJECT_NAME } from "../document/scene-document"; + +import type { EditorCommand } from "./command"; + +export function createSetProjectNameCommand(nextName: string): EditorCommand { + const normalizedName = nextName.trim() || DEFAULT_PROJECT_NAME; + let previousName: string | null = null; + + return { + id: createOpaqueId("command"), + label: `Rename project to ${normalizedName}`, + execute(context) { + const currentProjectDocument = context.getProjectDocument(); + + if (previousName === null) { + previousName = currentProjectDocument.name; + } + + context.setProjectDocument({ + ...currentProjectDocument, + name: normalizedName + }); + }, + undo(context) { + if (previousName === null) { + return; + } + + const currentProjectDocument = context.getProjectDocument(); + context.setProjectDocument({ + ...currentProjectDocument, + name: previousName + }); + } + }; +}