(menu: ContextMenuItem[], conn: string, finfo: FileInfo)
| 4 | import { formatRemoteUri } from "./waveutil"; |
| 5 | |
| 6 | export function addOpenMenuItems(menu: ContextMenuItem[], conn: string, finfo: FileInfo): ContextMenuItem[] { |
| 7 | if (!finfo) { |
| 8 | return menu; |
| 9 | } |
| 10 | menu.push({ |
| 11 | type: "separator", |
| 12 | }); |
| 13 | if (!conn) { |
| 14 | // TODO: resolve correct host path if connection is WSL |
| 15 | // if the entry is a directory, reveal it in the file manager, if the entry is a file, reveal its parent directory |
| 16 | menu.push({ |
| 17 | label: makeNativeLabel(true), |
| 18 | click: () => { |
| 19 | getApi().openNativePath(finfo.isdir ? finfo.path : finfo.dir); |
| 20 | }, |
| 21 | }); |
| 22 | // if the entry is a file, open it in the default application |
| 23 | if (!finfo.isdir) { |
| 24 | menu.push({ |
| 25 | label: makeNativeLabel(false), |
| 26 | click: () => { |
| 27 | getApi().openNativePath(finfo.path); |
| 28 | }, |
| 29 | }); |
| 30 | } |
| 31 | } else { |
| 32 | menu.push({ |
| 33 | label: "Download File", |
| 34 | click: () => { |
| 35 | const remoteUri = formatRemoteUri(finfo.path, conn); |
| 36 | getApi().downloadFile(remoteUri); |
| 37 | }, |
| 38 | }); |
| 39 | } |
| 40 | menu.push({ |
| 41 | type: "separator", |
| 42 | }); |
| 43 | if (!finfo.isdir) { |
| 44 | menu.push({ |
| 45 | label: "Open Preview in New Block", |
| 46 | click: () => |
| 47 | fireAndForget(async () => { |
| 48 | const blockDef: BlockDef = { |
| 49 | meta: { |
| 50 | view: "preview", |
| 51 | file: finfo.path, |
| 52 | connection: conn, |
| 53 | }, |
| 54 | }; |
| 55 | await createBlock(blockDef); |
| 56 | }), |
| 57 | }); |
| 58 | } |
| 59 | menu.push({ |
| 60 | label: "Open Terminal Here", |
| 61 | click: () => { |
| 62 | const termBlockDef: BlockDef = { |
| 63 | meta: { |
no test coverage detected