| 1 | import type { TabMeta } from "./types"; |
| 2 | import { t } from "./i18n"; |
| 3 | |
| 4 | export function defaultWorkspaceTitle(name?: string): string { |
| 5 | const title = name?.trim(); |
| 6 | return title && title !== "Global" ? title : t("workspace.defaultName"); |
| 7 | } |
| 8 | |
| 9 | export function tabWorkspaceTitle(tab?: TabMeta): string { |
| 10 | if (!tab) return defaultWorkspaceTitle(); |
| 11 | if (tab.scope === "project") return tab.workspaceName || tab.workspaceRoot || "Project"; |
| 12 | if (tab.scope === "global" && !tab.remote) return defaultWorkspaceTitle(tab.workspaceName); |
| 13 | return tab.workspaceName || tab.workspaceRoot || "Global"; |
| 14 | } |
| 15 | |
| 16 | export function topicTitle(tab?: TabMeta): string { |
| 17 | if (!tab) return defaultWorkspaceTitle(); |
| 18 | const workspaceTitle = tabWorkspaceTitle(tab); |
| 19 | const topic = tab.topicTitle || (tab.scope === "global" ? workspaceTitle : "Untitled"); |
| 20 | return topic === workspaceTitle ? workspaceTitle : `${workspaceTitle} / ${topic}`; |
| 21 | } |
| 22 | |
| 23 | export function topicDisplayTitle(tab?: TabMeta): string { |
| 24 | if (!tab) return defaultWorkspaceTitle(); |
| 25 | return tab.topicTitle || (tab.scope === "global" ? tabWorkspaceTitle(tab) : "Untitled"); |
| 26 | } |
| 27 | |
| 28 | export function safeFilename(name: string): string { |
| 29 | const cleaned = name.trim().replace(/[\\/:*?"<>|]+/g, "-").replace(/\s+/g, " ").slice(0, 80); |
| 30 | return cleaned || "reasonix-session"; |
| 31 | } |
| 32 |