Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions frontend/src/components/panels/editor/FileEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,22 +312,22 @@ function HeadlessFileTree({
setContextMenu(null);
}, [contextMenu, sessionId]);

// Delete handler
const handleDelete = useCallback(async (file: FileItem) => {
const handleDelete = useCallback(async (file: FileItem, options: { skipConfirm?: boolean } = {}) => {
const files = getSelectedFilesForAction(file);
const confirmMessage = files.length > 1
? `Move ${files.length} items to trash?`
: files[0]?.isDirectory
? `Move folder "${files[0].name}" and all its contents to trash?`
: `Move file "${files[0]?.name}" to trash?`;
if (!confirm(confirmMessage)) return;
if (!options.skipConfirm && !confirm(confirmMessage)) return;

try {
for (const target of files) {
const result = await window.electronAPI.invoke('file:delete', {
sessionId,
filePath: target.path,
useTrash: true,
allowPermanentFallback: !options.skipConfirm,
});

if (!result.success) {
Expand Down Expand Up @@ -725,7 +725,7 @@ function HeadlessFileTree({
const item = tree.getItemInstance(selectedItems[0])?.getItemData();
if (item) {
e.preventDefault();
handleDelete(item);
handleDelete(item, { skipConfirm: isMac() && e.metaKey });
}
}
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'c' && selectedItems.length > 0) {
Expand Down
7 changes: 7 additions & 0 deletions main/src/ipc/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface FileDeleteRequest {
sessionId: string;
filePath: string;
useTrash?: boolean;
allowPermanentFallback?: boolean;
}

interface FileRenameRequest {
Expand Down Expand Up @@ -722,6 +723,12 @@ export function registerFileHandlers(ipcMain: IpcMain, services: AppServices): v
await shell.trashItem(fullPath);
return { success: true };
} catch (trashError) {
if (request.allowPermanentFallback === false) {
return {
success: false,
error: trashError instanceof Error ? trashError.message : 'Failed to move item to trash'
};
}
console.warn('Failed to move item to trash, permanently deleting instead:', trashError);
}
}
Expand Down
Loading