Open History to see the last commit
1import type { EnvironmentId } from "@t3tools/contracts";
2import { splitFilePathPosition } from "@t3tools/shared/fileLinks";
3
4import type { MarkdownFileLinkMeta } from "../../markdown-links";
5import type { RemoteOpenMode } from "../../remoteOpen";
6
7export function canUseMarkdownFileShellActions(
8 environmentId: EnvironmentId | null,
9 remoteOpenMode: RemoteOpenMode,
10 isRemoteOpenResolved: boolean,
11): boolean {
12 return environmentId !== null && isRemoteOpenResolved && remoteOpenMode === "local-exec";
13}
14
15export function hasMarkdownFilePrimaryAction(input: {
16 canOpenInEditor: boolean;
17 canOpenInBrowser: boolean;
18 canOpenInPanel: boolean;
19 canOpenMedia?: boolean;
20}): boolean {
21 return (
22 input.canOpenInEditor ||
23 input.canOpenInBrowser ||
24 input.canOpenInPanel ||
25 input.canOpenMedia === true
26 );
27}
28
29export function markdownFileCopyMenuItems({
30 targetPath,
31 workspaceRelativePath,
32}: Pick<MarkdownFileLinkMeta, "targetPath" | "workspaceRelativePath">) {
33 const items = [
34 { id: "copy-full", label: "Copy full path", value: targetPath, title: "Full path" },
35 ];
36 if (workspaceRelativePath !== null) {
37 const position = targetPath.slice(splitFilePathPosition(targetPath).path.length);
38 items.unshift({
39 id: "copy-relative",
40 label: "Copy relative path",
41 value: `${workspaceRelativePath}${position}`,
42 title: "Relative path",
43 });
44 }
45 return items;
46}
47
48export function shouldUseMarkdownFileBrowserPrimaryAction(input: {
49 canOpenInEditor: boolean;
50 canOpenInBrowser: boolean;
51 canOpenInPanel: boolean;
52}): boolean {
53 return input.canOpenInBrowser && !input.canOpenInEditor && !input.canOpenInPanel;
54}