From 3162ad2c419a36d4046e6b42b43912c1387ceede Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Fri, 26 Jul 2024 00:48:12 -0700 Subject: [PATCH] Directory Context Menus (#155) This adds the ability to open a directory as a terminal in a new block. it uses the directory table items for child directories and the block header for the current directory. --- frontend/app/view/directorypreview.tsx | 39 ++++++++++++++++++-------- frontend/app/view/preview.tsx | 20 +++++++++++-- frontend/app/view/waveai.tsx | 1 - pkg/blockcontroller/blockcontroller.go | 4 +++ 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/frontend/app/view/directorypreview.tsx b/frontend/app/view/directorypreview.tsx index 44c301a7..a0cd58ee 100644 --- a/frontend/app/view/directorypreview.tsx +++ b/frontend/app/view/directorypreview.tsx @@ -388,20 +388,10 @@ function TableBody({ }, [focusIndex, parentHeight]); const handleFileContextMenu = useCallback( - (e, path) => { + (e: any, path: string, mimetype: string) => { e.preventDefault(); e.stopPropagation(); const menu = [ - { - label: "Open in New Block", - click: async () => { - const blockDef = { - view: "preview", - meta: { file: path }, - }; - await createBlock(blockDef); - }, - }, { label: "Delete File", click: async () => { @@ -415,7 +405,32 @@ function TableBody({ getApi().downloadFile(path); }, }, + { + label: "Open Preview in New Block", + click: async () => { + const blockDef = { + view: "preview", + meta: { file: path }, + }; + await createBlock(blockDef); + }, + }, ]; + if (mimetype == "directory") { + menu.push({ + label: "Open Terminal in New Block", + click: async () => { + const termBlockDef: BlockDef = { + controller: "shell", + view: "term", + meta: { + cwd: path, + }, + }; + await createBlock(termBlockDef); + }, + }); + } ContextMenuModel.showContextMenu(menu, e); }, [setRefreshVersion] @@ -433,7 +448,7 @@ function TableBody({ setSearch(""); }} onClick={() => setFocusIndex(idx)} - onContextMenu={(e) => handleFileContextMenu(e, row.getValue("path"))} + onContextMenu={(e) => handleFileContextMenu(e, row.getValue("path"), row.getValue("mimetype"))} > {row.getVisibleCells().map((cell) => (