diff --git a/README.md b/README.md
index 3e87605b..21f11c93 100644
--- a/README.md
+++ b/README.md
@@ -91,7 +91,7 @@ Watch vitest unit tests only:
```shell
cd applications/web
-pnpm test:unit -w
+pnpm test:unit -w
```
### rust
@@ -135,7 +135,6 @@ Github project for tracking progress is [here](https://github.com/orgs/CADmium-C
- [ ] Extrusion
- [ ] Configure an extrusion to create new solid or subtract from existing solid
- [ ] Project
- - [ ] Ability to rename the project
- [ ] Ability to delete steps
- [ ] bind ctrl + s to .cadmium export, and ctrl + o to .cadmium import
- [ ] Units
diff --git a/applications/web/src/routes/(CADmium)/AppBar.svelte b/applications/web/src/routes/(CADmium)/AppBar.svelte
index 2f3ec8f3..002d46d4 100644
--- a/applications/web/src/routes/(CADmium)/AppBar.svelte
+++ b/applications/web/src/routes/(CADmium)/AppBar.svelte
@@ -8,12 +8,15 @@
import type { WithTarget } from "shared/types"
import { isProject } from "shared/typeGuards"
import { base } from "$app/paths"
+ import { renameProject } from "shared/projectUtils"
// prettier-ignore
const log = (function () { const context = "[AppBar.svelte]"; const color="gray"; return Function.prototype.bind.call(console.log, console, `%c${context}`, `font-weight:bold;color:${color};`)})()
export let userName = "mattferraro.dev"
export let project: Project
+ export let renaming: boolean = false
+ export let newProjectName: string = ""
export let newFileContent: string | null = null
@@ -46,7 +49,35 @@
CADmium
- {project.name ?? ""}
+ {#if renaming}
+ {
+ log("Renaming project aborted")
+ renaming = false
+ newProjectName = project.name ?? ""
+ }}
+ on:keydown={(e) => {
+ if (e.key === "Enter") {
+ log("Renaming project")
+ renameProject(newProjectName)
+ project.name = newProjectName
+ renaming = false
+ }
+ }}
+ />
+ {:else}
+ {
+ log("Renaming project")
+ renaming = true
+ newProjectName = project.name ?? ""
+ }}
+ >{project.name ?? ""}
+ {/if}
{
if (value) {
@@ -624,6 +636,13 @@ function checkWasmMessage(message: Message, abort = true, logError = true): bool
}
return true
+ case "RenameProject":
+ if (!isRenameProject(command)) {
+ logOrAbort()
+ return false
+ }
+ return true
+
default:
console.error("[projectUtils.ts] [checkWasmMessage]", "messageType typeGuard not implemented:", key)
return false
diff --git a/packages/shared/typeGuards.ts b/packages/shared/typeGuards.ts
index 7d41f704..168d4a1d 100644
--- a/packages/shared/typeGuards.ts
+++ b/packages/shared/typeGuards.ts
@@ -82,7 +82,8 @@ import type {
RenameStep,
Message,
MessageHistory,
- RenameWorkbench
+ RenameWorkbench,
+ RenameProject
} from "./types"
import { Vector2 } from "three"
import { Vector3 } from "three"
@@ -1118,6 +1119,14 @@ export function isRenameWorkbench(obj: unknown): obj is RenameWorkbench {
)
}
+export function isRenameProject(obj: unknown): obj is RenameProject {
+ const typedObj = obj as RenameProject
+ return (
+ ((typedObj !== null && typeof typedObj === "object") || typeof typedObj === "function") &&
+ typeof typedObj["new_name"] === "string"
+ )
+}
+
export function isMessage(obj: unknown): obj is Message {
const typedObj = obj as Message
return (
@@ -1146,7 +1155,9 @@ export function isMessage(obj: unknown): obj is Message {
(((typedObj !== null && typeof typedObj === "object") || typeof typedObj === "function") &&
(isRenameStep(typedObj["RenameStep"]) as boolean)) ||
(((typedObj !== null && typeof typedObj === "object") || typeof typedObj === "function") &&
- (isRenameWorkbench(typedObj["RenameWorkbench"]) as boolean))
+ (isRenameWorkbench(typedObj["RenameWorkbench"]) as boolean)) ||
+ (((typedObj !== null && typeof typedObj === "object") || typeof typedObj === "function") &&
+ (isRenameProject(typedObj["RenameProject"]) as boolean))
)
}
diff --git a/packages/shared/types.d.ts b/packages/shared/types.d.ts
index b496584a..0d08fa18 100644
--- a/packages/shared/types.d.ts
+++ b/packages/shared/types.d.ts
@@ -312,6 +312,10 @@ interface RenameWorkbench {
new_name: string
}
+interface RenameProject {
+ new_name: string
+}
+
export type Message_GeneratedFromRust =
| { RenameWorkbench: { workbench_id: number; new_name: string } }
| { RenameStep: { workbench_id: number; step_id: number; new_name: string } }
@@ -348,6 +352,7 @@ type Message =
| { NewPointOnSketch2: NewPointOnSketch2 }
| { RenameStep: RenameStep }
| { RenameWorkbench: RenameWorkbench }
+ | { RenameProject: RenameProject }
interface MessageHistory {
message: Message