(
id: string,
renameRef: React.RefObject<(() => void) | null>,
onClose: (event: React.MouseEvent<HTMLButtonElement, MouseEvent> | null) => void,
env: TabEnv
)
| 37 | } |
| 38 | |
| 39 | export function buildTabContextMenu( |
| 40 | id: string, |
| 41 | renameRef: React.RefObject<(() => void) | null>, |
| 42 | onClose: (event: React.MouseEvent<HTMLButtonElement, MouseEvent> | null) => void, |
| 43 | env: TabEnv |
| 44 | ): ContextMenuItem[] { |
| 45 | const menu: ContextMenuItem[] = []; |
| 46 | menu.push( |
| 47 | { label: "Rename Tab", click: () => renameRef.current?.() }, |
| 48 | { |
| 49 | label: "Copy TabId", |
| 50 | click: () => fireAndForget(() => navigator.clipboard.writeText(id)), |
| 51 | }, |
| 52 | { type: "separator" } |
| 53 | ); |
| 54 | const tabORef = makeORef("tab", id); |
| 55 | const currentFlagColor = globalStore.get(getOrefMetaKeyAtom(tabORef, "tab:flagcolor")) ?? null; |
| 56 | const flagSubmenu: ContextMenuItem[] = [ |
| 57 | { |
| 58 | label: "None", |
| 59 | type: "checkbox", |
| 60 | checked: currentFlagColor == null, |
| 61 | click: () => |
| 62 | fireAndForget(() => |
| 63 | env.rpc.SetMetaCommand(TabRpcClient, { oref: tabORef, meta: { "tab:flagcolor": null } }) |
| 64 | ), |
| 65 | }, |
| 66 | ...FlagColors.map((fc) => ({ |
| 67 | label: fc.label, |
| 68 | type: "checkbox" as const, |
| 69 | checked: currentFlagColor === fc.value, |
| 70 | click: () => |
| 71 | fireAndForget(() => |
| 72 | env.rpc.SetMetaCommand(TabRpcClient, { oref: tabORef, meta: { "tab:flagcolor": fc.value } }) |
| 73 | ), |
| 74 | })), |
| 75 | ]; |
| 76 | menu.push({ label: "Flag Tab", type: "submenu", submenu: flagSubmenu }, { type: "separator" }); |
| 77 | const fullConfig = globalStore.get(env.atoms.fullConfigAtom); |
| 78 | const backgrounds = fullConfig?.backgrounds ?? {}; |
| 79 | const bgKeys = Object.keys(backgrounds).filter((k) => backgrounds[k] != null); |
| 80 | bgKeys.sort((a, b) => { |
| 81 | const aOrder = backgrounds[a]["display:order"] ?? 0; |
| 82 | const bOrder = backgrounds[b]["display:order"] ?? 0; |
| 83 | return aOrder - bOrder; |
| 84 | }); |
| 85 | if (bgKeys.length > 0) { |
| 86 | const submenu: ContextMenuItem[] = []; |
| 87 | const oref = makeORef("tab", id); |
| 88 | submenu.push({ |
| 89 | label: "Default", |
| 90 | click: () => |
| 91 | fireAndForget(async () => { |
| 92 | await env.rpc.SetMetaCommand(TabRpcClient, { |
| 93 | oref, |
| 94 | meta: { "bg:*": true, "tab:background": null }, |
| 95 | }); |
| 96 | env.rpc.ActivityCommand(TabRpcClient, { settabtheme: 1 }, { noresponse: true }); |
no test coverage detected