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