mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
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.
This commit is contained in:
parent
2fea8e0a68
commit
3162ad2c41
@ -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) => (
|
||||
<div
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
import { ContextMenuModel } from "@/app/store/contextmenu";
|
||||
import { Markdown } from "@/element/markdown";
|
||||
import { globalStore, useBlockAtom } from "@/store/global";
|
||||
import { createBlock, globalStore, useBlockAtom } from "@/store/global";
|
||||
import * as services from "@/store/services";
|
||||
import * as WOS from "@/store/wos";
|
||||
import { getWebServerEndpoint } from "@/util/endpoints";
|
||||
@ -278,6 +278,22 @@ export class PreviewModel implements ViewModel {
|
||||
navigator.clipboard.writeText(baseName);
|
||||
},
|
||||
});
|
||||
const mimeType = util.jotaiLoadableValue(globalStore.get(this.fileMimeTypeLoadable), "");
|
||||
if (mimeType == "directory") {
|
||||
menuItems.push({
|
||||
label: "Open Terminal in New Block",
|
||||
click: async () => {
|
||||
const termBlockDef: BlockDef = {
|
||||
controller: "shell",
|
||||
view: "term",
|
||||
meta: {
|
||||
cwd: globalStore.get(this.fileName),
|
||||
},
|
||||
};
|
||||
await createBlock(termBlockDef);
|
||||
},
|
||||
});
|
||||
}
|
||||
return menuItems;
|
||||
}
|
||||
|
||||
@ -563,4 +579,4 @@ function PreviewView({ blockId, model }: { blockId: string; model: PreviewModel
|
||||
);
|
||||
}
|
||||
|
||||
export { makePreviewModel, PreviewView };
|
||||
export { PreviewView, makePreviewModel };
|
||||
|
@ -132,7 +132,6 @@ export class WaveAiModel implements ViewModel {
|
||||
name: (metadata?.name as string) || "user",
|
||||
},
|
||||
];
|
||||
console.log("opts.apitoken:", opts.apitoken);
|
||||
const beMsg: OpenAiStreamRequest = {
|
||||
clientid: clientId,
|
||||
opts: opts,
|
||||
|
@ -241,6 +241,10 @@ func (bc *BlockController) DoRunShellCommand(rc *RunShellOpts, blockMeta map[str
|
||||
if bc.ControllerType == BlockController_Shell {
|
||||
cmdOpts.Interactive = true
|
||||
cmdOpts.Login = true
|
||||
cmdOpts.Cwd, _ = blockMeta["cwd"].(string)
|
||||
if cmdOpts.Cwd != "" {
|
||||
cmdOpts.Cwd = wavebase.ExpandHomeDir(cmdOpts.Cwd)
|
||||
}
|
||||
} else if bc.ControllerType == BlockController_Cmd {
|
||||
if _, ok := blockMeta["cmd"].(string); ok {
|
||||
cmdStr = blockMeta["cmd"].(string)
|
||||
|
Loading…
Reference in New Issue
Block a user