Open New Block and Delete Files (#76)

This implements the behavior for the context menu recently added to the
directories. Open New Block simply opens the file in a preview in a new
block.

Delete files will delete the selected file, but it does not trigger a
rerender at this time. To see the change, you must navigate to a
different directory and then return. This will be fixed in a future
update.
This commit is contained in:
Sylvie Crowe 2024-06-25 13:53:55 -07:00 committed by GitHub
parent a012de8413
commit 182c5f6e3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 7 deletions

View File

@ -51,6 +51,9 @@ class FileServiceType {
AddWidget(arg1: WidgetsConfigType): Promise<void> { AddWidget(arg1: WidgetsConfigType): Promise<void> {
return WOS.callBackendService("file", "AddWidget", Array.from(arguments)) return WOS.callBackendService("file", "AddWidget", Array.from(arguments))
} }
DeleteFile(arg1: string): Promise<void> {
return WOS.callBackendService("file", "DeleteFile", Array.from(arguments))
}
GetSettingsConfig(): Promise<any> { GetSettingsConfig(): Promise<any> {
return WOS.callBackendService("file", "GetSettingsConfig", Array.from(arguments)) return WOS.callBackendService("file", "GetSettingsConfig", Array.from(arguments))
} }

View File

@ -1,6 +1,7 @@
// Copyright 2024, Command Line Inc. // Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import * as services from "@/store/services";
import * as util from "@/util/util"; import * as util from "@/util/util";
import { import {
Table, Table,
@ -14,7 +15,7 @@ import clsx from "clsx";
import * as jotai from "jotai"; import * as jotai from "jotai";
import React from "react"; import React from "react";
import { ContextMenuModel } from "../store/contextmenu"; import { ContextMenuModel } from "../store/contextmenu";
import { atoms } from "../store/global"; import { atoms, createBlock } from "../store/global";
import "./directorypreview.less"; import "./directorypreview.less";
@ -121,14 +122,18 @@ function handleFileContextMenu(e: React.MouseEvent<HTMLDivElement>, path: string
let menu: ContextMenuItem[] = []; let menu: ContextMenuItem[] = [];
menu.push({ menu.push({
label: "Open in New Block", label: "Open in New Block",
click: () => { click: async () => {
alert("Not Implemented"); const blockDef = {
view: "preview",
meta: { file: path },
};
await createBlock(blockDef);
}, },
}); });
menu.push({ menu.push({
label: "Delete File", label: "Delete File",
click: () => { click: async () => {
alert("Not Implemented"); await services.FileService.DeleteFile(path).catch((e) => console.log(e)); //todo these errors need a popup
}, },
}); });
ContextMenuModel.showContextMenu(menu, e); ContextMenuModel.showContextMenu(menu, e);
@ -262,6 +267,8 @@ interface TableBodyProps {
} }
function TableBody({ table, cwd, setFileName }: TableBodyProps) { function TableBody({ table, cwd, setFileName }: TableBodyProps) {
let [refresh, setRefresh] = React.useState(false);
return ( return (
<div className="dir-table-body"> <div className="dir-table-body">
{table.getRowModel().rows.map((row) => ( {table.getRowModel().rows.map((row) => (

View File

@ -288,8 +288,8 @@ declare global {
data64: string; data64: string;
}; };
// eventbus.WSLayoutAction // eventbus.WSLayoutActionData
type WSLayoutAction = { type WSLayoutActionData = {
tabid: string; tabid: string;
actiontype: string; actiontype: string;
blockid: string; blockid: string;

View File

@ -131,6 +131,11 @@ func (fs *FileService) GetWaveFile(id string, path string) (any, error) {
return file, nil return file, nil
} }
func (fs *FileService) DeleteFile(path string) error {
cleanedPath := filepath.Clean(wavebase.ExpandHomeDir(path))
return os.Remove(cleanedPath)
}
func (fs *FileService) GetSettingsConfig() interface{} { func (fs *FileService) GetSettingsConfig() interface{} {
watcher := wconfig.GetWatcher() watcher := wconfig.GetWatcher()
return watcher.GetSettingsConfig() return watcher.GetSettingsConfig()