From 505e24cbd20e75f4cfc9caaf49c648684da769e3 Mon Sep 17 00:00:00 2001 From: Hikari Date: Wed, 28 Jan 2026 16:49:29 -0800 Subject: [PATCH] feat: add rename functionality to file editor Add ability to rename files and folders through the context menu: - Add rename_path Tauri command in backend - Add renamePath function to editor store that updates open tabs - Add rename option to context menu with pencil icon - Update InputDialog to support initial value for rename operations --- src-tauri/src/commands.rs | 21 ++++++++++ src-tauri/src/lib.rs | 1 + src/lib/components/editor/FileBrowser.svelte | 24 ++++++++++- .../components/editor/FileContextMenu.svelte | 36 +++++++++++++++- src/lib/components/editor/InputDialog.svelte | 9 +++- src/lib/stores/editor.ts | 42 +++++++++++++++++++ 6 files changed, 129 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 62c0a91..f71b265 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -535,6 +535,27 @@ pub async fn delete_directory(path: String) -> Result<(), String> { Ok(()) } +#[tauri::command] +pub async fn rename_path(old_path: String, new_path: String) -> Result<(), String> { + use std::fs; + use std::path::Path; + + let old = Path::new(&old_path); + let new = Path::new(&new_path); + + if !old.exists() { + return Err("Path does not exist".to_string()); + } + + if new.exists() { + return Err("Destination already exists".to_string()); + } + + fs::rename(old, new).map_err(|e| format!("Failed to rename: {}", e))?; + + Ok(()) +} + #[cfg(test)] mod tests { use super::*; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 0d0901e..6db2820 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -158,6 +158,7 @@ pub fn run() { create_directory, delete_file, delete_directory, + rename_path, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src/lib/components/editor/FileBrowser.svelte b/src/lib/components/editor/FileBrowser.svelte index 5c72801..8a5880b 100644 --- a/src/lib/components/editor/FileBrowser.svelte +++ b/src/lib/components/editor/FileBrowser.svelte @@ -39,7 +39,7 @@ // Dialog state let dialog = $state<{ - type: "newFile" | "newFolder" | "delete" | null; + type: "newFile" | "newFolder" | "delete" | "rename" | null; parentPath: string; targetEntry: FileEntry | null; }>({ @@ -81,6 +81,10 @@ dialog = { type: "delete", parentPath: "", targetEntry: entry }; } + function openRenameDialog(entry: FileEntry) { + dialog = { type: "rename", parentPath: "", targetEntry: entry }; + } + function closeDialog() { dialog = { type: null, parentPath: "", targetEntry: null }; } @@ -106,6 +110,12 @@ closeDialog(); } + async function handleRename(newName: string) { + if (!dialog.targetEntry) return; + await editorStore.renamePath(dialog.targetEntry.path, newName); + closeDialog(); + } + function handleNewFile() { openNewFileDialog($currentDirectory); } @@ -211,6 +221,7 @@ currentDirectory={$currentDirectory} onNewFile={openNewFileDialog} onNewFolder={openNewFolderDialog} + onRename={openRenameDialog} onDelete={openDeleteDialog} onClose={closeContextMenu} /> @@ -250,6 +261,17 @@ /> {/if} +{#if dialog.type === "rename" && dialog.targetEntry} + +{/if} +