Skip to content

Agent Zero AI framework

file/dir renaming, file actions dropdown, extend APIs

3clyp507623b5a7a661
diff --git a/python/api/delete_work_dir_file.py b/python/api/delete_work_dir_file.py
index 2808f9106..103027791 100644
--- a/python/api/delete_work_dir_file.py
+++ b/python/api/delete_work_dir_file.py
@@ -8,22 +8,25 @@ from python.api import get_work_dir_files
class DeleteWorkDirFile(ApiHandler):
async def process(self, input: Input, request: Request) -> Output:
- file_path = input.get("path", "")
- if not file_path.startswith("/"):
- file_path = f"/{file_path}"
-
- current_path = input.get("currentPath", "")
-
- # browser = FileBrowser()
- res = await runtime.call_development_function(delete_file, file_path)
-
- if res:
- # Get updated file list
- # result = browser.get_files(current_path)
- result = await runtime.call_development_function(get_work_dir_files.get_files, current_path)
- return {"data": result}
- else:
- raise Exception("File not found or could not be deleted")
+ try:
+ file_path = input.get("path", "")
+ if not file_path.startswith("/"):
+ file_path = f"/{file_path}"
+
+ current_path = input.get("currentPath", "")
+
+ # browser = FileBrowser()
+ res = await runtime.call_development_function(delete_file, file_path)
+
+ if res:
+ # Get updated file list
+ # result = browser.get_files(current_path)
+ result = await runtime.call_development_function(get_work_dir_files.get_files, current_path)
+ return {"data": result}
+ else:
+ return {"error": "File not found or could not be deleted"}
+ except Exception as e:
+ return {"error": str(e)}
async def delete_file(file_path: str):
diff --git a/python/api/edit_work_dir_file.py b/python/api/edit_work_dir_file.py
new file mode 100644
index 000000000..379064295
--- /dev/null
+++ b/python/api/edit_work_dir_file.py
@@ -0,0 +1,84 @@
+import mimetypes
+import os
+
+from python.helpers.api import ApiHandler, Input, Output, Request
+from python.helpers.file_browser import FileBrowser
+from python.helpers import runtime, files
+
+MAX_EDIT_FILE_SIZE = 1024 * 1024
+BINARY_SAMPLE_SIZE = 10 * 1024
+
+
+class EditWorkDirFile(ApiHandler):
+ @classmethod
+ def get_methods(cls):
+ return ["GET", "POST"]
+
+ async def process(self, input: Input, request: Request) -> Output:
+ try:
+ if request.method == "GET":
+ file_path = request.args.get("path", "")
+ if not file_path:
+ return {"error": "Path is required"}
+ if not file_path.startswith("/"):
+ file_path = f"/{file_path}"
+
+ data = await runtime.call_development_function(load_file, file_path)
+ return {"data": data}
+
+ file_path = input.get("path", "")
+ if not file_path:
+ return {"error": "Path is required"}
+ if not file_path.startswith("/"):
+ file_path = f"/{file_path}"
+
+ content = input.get("content", "")
+ if not isinstance(content, str):
+ return {"error": "Content must be a string"}
+
+ content_size = len(content.encode("utf-8"))
+ if content_size > MAX_EDIT_FILE_SIZE:
+ return {"error": "File exceeds 1 MB and cannot be edited"}
+
+ res = await runtime.call_development_function(save_file, file_path, content)
+ if not res:
+ return {"error": "Failed to save file"}
+
+ return {"ok": True}
+ except Exception as e:
+ return {"error": str(e)}
+
+
+async def load_file(file_path: str) -> dict:
+ browser = FileBrowser()
+ full_path = browser.get_full_path(file_path)
+
+ if os.path.isdir(full_path):
+ raise Exception("Path points to a directory")
+
+ size = os.path.getsize(full_path)
+ if size > MAX_EDIT_FILE_SIZE:
+ raise Exception("File exceeds 1 MB and cannot be edited")
+
+ # Binary detection: only sample the first ~10KB (per backend rules)
+ if files.is_probably_binary_file(full_path, sample_size=BINARY_SAMPLE_SIZE):
+ raise Exception("Binary file detected; editing is not supported")
+
+ mime_type, _ = mimetypes.guess_type(full_path)
+ try:
+ with open(full_path, "r", encoding="utf-8", errors="strict") as file:
+ content = file.read()
+ except UnicodeDecodeError:
+ raise Exception("Unable to decode file as UTF-8; editing is not supported")
+
+ return {
+ "path": file_path,
+ "name": os.path.basename(full_path),
+ "mime_type": mime_type or "text/plain",
+ "content": content,
+ }
+
+
+def save_file(file_path: str, content: str) -> bool:
+ browser = FileBrowser()
+ return browser.save_text_file(file_path, content)
diff --git a/python/api/rename_work_dir_file.py b/python/api/rename_work_dir_file.py
new file mode 100644
index 000000000..2279d2264
--- /dev/null
+++ b/python/api/rename_work_dir_file.py
@@ -0,0 +1,54 @@
+from python.helpers.api import ApiHandler, Input, Output, Request
+from python.helpers.file_browser import FileBrowser
+from python.helpers import runtime
+from python.api import get_work_dir_files
+
+
+class RenameWorkDirFile(ApiHandler):
+ async def process(self, input: Input, request: Request) -> Output:
+ try:
+ action = input.get("action", "rename")
+ new_name = (input.get("newName", "") or "").strip()
+ if not new_name:
+ return {"error": "New name is required"}
+
+ current_path = input.get("currentPath", "")
+
+ if action == "create-folder":
+ parent_path = input.get("parentPath", current_path)
+ if not parent_path:
+ return {"error": "Parent path is required"}
+ res = await runtime.call_development_function(
+ create_folder, parent_path, new_name
+ )
+ else:
+ file_path = input.get("path", "")
+ if not file_path:
+ return {"error": "Path is required"}
+ if not file_path.startswith("/"):
+ file_path = f"/{file_path}"
+ res = await runtime.call_development_function(
+ rename_item, file_path, new_name
+ )
+
+ if res:
+ result = await runtime.call_development_function(
+ get_work_dir_files.get_files, current_path
+ )
+ return {"data": result}
+
+ error_msg = "Failed to create folder" if action == "create-folder" else "Rename failed"
+ return {"error": error_msg}
+
+ except Exception as e:
+ return {"error": str(e)}
+
+
+async def rename_item(file_path: str, new_name: str) -> bool:
+ browser = FileBrowser()
+ return browser.rename_item(file_path, new_name)
+
+
+async def create_folder(parent_path: str, folder_name: str) -> bool:
+ browser = FileBrowser()
+ return browser.create_folder(parent_path, folder_name)
diff --git a/python/helpers/file_browser.py b/python/helpers/file_browser.py
index 8340b2f62..5e3bd55ab 100644
--- a/python/helpers/file_browser.py
+++ b/python/helpers/file_browser.py
@@ -19,6 +19,7 @@ class FileBrowser:
}
MAX_FILE_SIZE = 100 * 1024 * 1024 # 100MB
+ MAX_TEXT_FILE_SIZE = 1 * 1024 * 1024 # 1MB
def __init__(self):
# if runtime.is_development():
@@ -107,6 +108,78 @@ class FileBrowser:
PrintStyle.error(f"Error deleting {file_path}: {e}")
return False
+ def rename_item(self, file_path: str, new_name: str) -> bool:
+ try:
+ if not new_name or new_name in {".", ".."}:
+ raise ValueError("Invalid new name")
+ if "/" in new_name or "\\" in new_name:
+ raise ValueError("New name cannot include path separators")
+
+ full_path = (self.base_dir / file_path).resolve()
+ if not str(full_path).startswith(str(self.base_dir)):
+ raise ValueError("Invalid path")
+ if not full_path.exists():
+ raise FileNotFoundError("File or folder not found")
+
+ new_path = full_path.with_name(new_name)
+ if not str(new_path).startswith(str(self.base_dir)):
+ raise ValueError("Invalid target path")
+ if full_path == new_path:
+ return True
+ if new_path.exists():
+ raise FileExistsError("Target already exists")
+
+ os.rename(full_path, new_path)
+ return True
+ except Exception as e:
+ PrintStyle.error(f"Error renaming {file_path}: {e}")
+ raise
+
+ def create_folder(self, parent_path: str, folder_name: str) -> bool:
+ try:
+ if not folder_name or folder_name in {".", ".."}:
+ raise ValueError("Invalid folder name")
+ if "/" in folder_name or "\\" in folder_name:
+ raise ValueError("Folder name cannot include path separators")
+
+ parent_full = (self.base_dir / parent_path).resolve()
+ if not str(parent_full).startswith(str(self.base_dir)):
+ raise ValueError("Invalid parent path")
+
+ target_dir = (parent_full / folder_name).resolve()
+ if not str(target_dir).startswith(str(self.base_dir)):
+ raise ValueError("Invalid target path")
+ if target_dir.exists():
+ raise FileExistsError("Folder already exists")
+
+ os.makedirs(target_dir, exist_ok=False)
+ return True
+ except Exception as e:
+ PrintStyle.error(f"Error creating folder {folder_name}: {e}")
+ raise
+
+ def save_text_file(self, file_path: str, content: str) -> bool:
+ try:
+ if not isinstance(content, str):
+ raise ValueError("Content must be a string")
+ content_size = len(content.encode("utf-8"))
+ if content_size > self.MAX_TEXT_FILE_SIZE:
+ raise ValueError("File exceeds 1 MB and cannot be edited")
+
+ full_path = (self.base_dir / file_path).resolve()
+ if not str(full_path).startswith(str(self.base_dir)):
+ raise ValueError("Invalid path")
+ if full_path.exists() and full_path.is_dir():
+ raise ValueError("Target is a directory")
+
+ os.makedirs(full_path.parent, exist_ok=True)
+ with open(full_path, "w", encoding="utf-8") as file:
+ file.write(content)
+ return True
+ except Exception as e:
+ PrintStyle.error(f"Error saving file {file_path}: {e}")
+ raise
+
def _is_allowed_file(self, filename: str, file) -> bool:
# allow any file to be uploaded in file browser
diff --git a/python/helpers/files.py b/python/helpers/files.py
index 04a019602..b50d12c99 100644
--- a/python/helpers/files.py
+++ b/python/helpers/files.py
@@ -230,6 +230,42 @@ def read_file_base64(relative_path):
return base64.b64encode(f.read()).decode("utf-8")
+def is_probably_binary_bytes(data: bytes, threshold: float = 0.3) -> bool:
+ """
+ Binary detection.
+
+ - Fast path: NUL bytes => binary
+ - Otherwise: treat high ratio of suspicious ASCII control bytes as binary.
+ (We intentionally do NOT treat bytes >= 0x80 as binary to avoid false
+ positives for UTF-8 text.)
+ """
+ if not data:
+ return False
+ if b"\x00" in data:
+ return True
+
+ # Count suspicious control bytes
+ allowed = {8, 9, 10, 12, 13} # \b \t \n \f \r
+ suspicious = sum(
+ 1
+ for b in data
+ if ((b < 32 and b not in allowed) or b == 127)
+ )
+ return (suspicious / len(data)) > threshold
+
+
+def is_probably_binary_file(
+ file_path: str, sample_size: int = 10 * 1024, threshold: float = 0.3
+) -> bool:
+ """Binary detection by reading only the first ~sample_size bytes of a file."""
+ try:
+ with open(file_path, "rb") as f:
+ sample = f.read(sample_size)
+ except (FileNotFoundError, PermissionError, OSError):
+ raise OSError(f"Unable to read file for binary detection: {file_path}")
+ return is_probably_binary_bytes(sample, threshold=threshold)
+
+
def replace_placeholders_text(_content: str, **kwargs):
# Replace placeholders with values from kwargs
for key, value in kwargs.items():
diff --git a/webui/components/modals/file-browser/file-browser-store.js b/webui/components/modals/file-browser/file-browser-store.js
index 7825b37b0..5ce7f3147 100644
--- a/webui/components/modals/file-browser/file-browser-store.js
+++ b/webui/components/modals/file-browser/file-browser-store.js
@@ -1,5 +1,6 @@
import { createStore } from "/js/AlpineStore.js";
import { fetchApi } from "/js/api.js";
+import { store as fileEditorStore } from "/components/modals/file-editor/file-editor-store.js";
// Model migrated from legacy file_browser.js (lift-and-shift)
const model = {
@@ -17,6 +18,11 @@ const model = {
initialPath: "", // Store path for open() call
closePromise: null,
error: null,
+ renameTarget: null,
+ renameName: "",
+ renameMode: "rename",
+ isRenaming: false,
+ renameError: null,
// --- Lifecycle -----------------------------------------------------------
init() {
@@ -36,13 +42,6 @@ const model = {
"modals/file-browser/file-browser.html"
);
- // // Setup cleanup on modal close
- // if (this.closePromise && typeof this.closePromise.then === "function") {
- // this.closePromise.then(() => {
- // this.destroy();
- // });
- // }
-
// Use stored initial path or default
path = path || this.initialPath || this.browser.currentPath || "$WORK_DIR";
this.browser.currentPath = path;
@@ -72,6 +71,7 @@ const model = {
this.history = [];
this.initialPath = "";
this.browser.entries = [];
+ this.resetRenameState();
},
// --- Helpers -------------------------------------------------------------
@@ -81,6 +81,39 @@ const model = {
return archiveExts.includes(ext);
},
+ saveScrollPosition() {
+ // Find the file browser modal's scrollable container
+ // We look for the modal containing .file-browser-root to target the correct modal
+ const fileBrowserRoot = document.querySelector('.file-browser-root');
+ if (fileBrowserRoot) {
+ const modalScroll = fileBrowserRoot.closest('.modal-scroll');
+ if (modalScroll) {
+ return {
+ scrollTop: modalScroll.scrollTop,
+ scrollLeft: modalScroll.scrollLeft
+ };
+ }
+ }
+ return null;
+ },
+
+ restoreScrollPosition(scrollPos) {
+ if (!scrollPos) return;
+
+ const restore = () => {
+ const fileBrowserRoot = document.querySelector('.file-browser-root');
+ if (fileBrowserRoot) {
+ const modalScroll = fileBrowserRoot.closest('.modal-scroll');
+ if (modalScroll) {
+ modalScroll.scrollTop = scrollPos.scrollTop;
+ modalScroll.scrollLeft = scrollPos.scrollLeft;
+ }
+ }
+ };
+
+ requestAnimationFrame(() => requestAnimationFrame(restore));
+ },
+
formatFileSize(size) {
if (size === 0) return "0 Bytes";
const k = 1024;
@@ -100,6 +133,27 @@ const model = {
return new Date(dateString).toLocaleDateString(undefined, options);
},
+ // --- Modal helpers -------------------------------------------------------
+ normalizePath(path) {
+ if (!path) return "";
+ return path.startsWith("/") ? path : `/${path}`;
+ },
+
+ buildChildPath(name) {
+ const base = this.normalizePath(this.browser.currentPath || "");
+ const trimmedBase = base.replace(/\/$/, "");
+ if (!trimmedBase) return `/${name}`;
+ return `${trimmedBase}/${name}`;
+ },
+
+ resetRenameState() {
+ this.renameTarget = null;
+ this.renameName = "";
+ this.renameMode = "rename";
+ this.isRenaming = false;
+ this.renameError = null;
+ },
+
// --- Sorting -------------------------------------------------------------
toggleSort(column) {
if (this.browser.sortBy === column) {
@@ -132,18 +186,36 @@ const model = {
// --- Navigation ----------------------------------------------------------
async fetchFiles(path = "") {
this.isLoading = true;
+
+ // Preserve scroll position if refreshing the same path
+ const isSamePath = this.browser.currentPath === path ||
+ (!path && !this.browser.currentPath);
+ const scrollPos = isSamePath ? this.saveScrollPosition() : null;
+
try {
const response = await fetchApi(
`/get_work_dir_files?path=${encodeURIComponent(path)}`
);
- if (response.ok) {
- const data = await response.json();
+ const data = await response.json().catch(() => ({}));
+
+ if (response.ok && !data.error) {
this.browser.entries = data.data.entries;
this.browser.currentPath = data.data.current_path;
this.browser.parentPath = data.data.parent_path;
+
+ // Set isLoading to false BEFORE restoring scroll to avoid reactivity issues
+ this.isLoading = false;
+
+ // Restore scroll position if on same path
+ if (scrollPos) {
+ this.restoreScrollPosition(scrollPos);
+ }
} else {
- console.error("Error fetching files:", await response.text());
+ const msg = data.error || "Error fetching files";
+ console.error("Error fetching files:", msg);
this.browser.entries = [];
+ this.isLoading = false;
+ window.toastFrontendError(msg, "File Browser Error");
}
} catch (e) {
window.toastFrontendError(
@@ -151,7 +223,6 @@ const model = {
"File Browser Error"
);
this.browser.entries = [];
- } finally {
this.isLoading = false;
}
},
@@ -170,6 +241,123 @@ const model = {
}
},
+ // --- Rename / Create -----------------------------------------------------
+ async openRenameModal(file) {
+ this.resetRenameState();
+ this.renameTarget = file;
+ this.renameName = file?.name || "";
+ this.renameMode = "rename";
+ this.renameError = null;
+ window.openModal("modals/file-browser/rename-modal.html");
+ },
+
+ async openNewFolderModal() {
+ this.resetRenameState();
+ this.renameMode = "create-folder";
+ this.renameName = "";
+ this.renameError = null;
+ window.openModal("modals/file-browser/rename-modal.html");
+ },
+
+ closeRenameModal() {
+ window.closeModal("modals/file-browser/rename-modal.html");
+ },
+
+ async confirmRename() {
+ if (this.isRenaming) return;
+
+ const newName = this.renameName.trim();
+ if (!newName) {
+ this.renameError = "Name is required.";
+ return;
+ }
+ if (newName === "." || newName === "..") {
+ this.renameError = "Name cannot be '.' or '..'.";
+ return;
+ }
+ if (newName.includes("/") || newName.includes("\\")) {
+ this.renameError = "Name cannot include path separators.";
+ return;
+ }
+ if (this.renameMode !== "create-folder" && !this.renameTarget?.path) {
+ this.renameError = "No item selected for rename.";
+ return;
+ }
+
+ // UX: pre-validate duplicates so we can show a clean inline error (no toast spam)
+ const duplicate = (this.browser.entries || []).some((entry) => {
+ if (!entry?.name) return false;
+ if (entry.name !== newName) return false;
+ // When renaming, allow keeping the same entry name
+ if (this.renameTarget?.path && entry.path === this.renameTarget.path) return false;
+ return true;
+ });
+ if (duplicate) {
+ this.renameError = `An item named "${newName}" already exists.`;
+ return;
+ }
+
+ this.isRenaming = true;
+ this.renameError = null;
+
+ try {
+ const payload =
+ this.renameMode === "create-folder"
+ ? {
+ action: "create-folder",
+ parentPath: this.browser.currentPath,
+ currentPath: this.browser.currentPath,
+ newName: newName,
+ }
+ : {
+ action: "rename",
+ path: this.renameTarget?.path,
+ currentPath: this.browser.currentPath,
+ newName: newName,
+ };
+
+ const resp = await fetchApi("/rename_work_dir_file", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(payload),
+ });
+
+ const data = await resp.json().catch(() => ({}));
+ if (!resp.ok || data.error) {
+ throw new Error(data.error || "Rename failed");
+ }
+
+ await this.fetchFiles(this.browser.currentPath);
+ this.closeRenameModal();
+ } catch (error) {
+ const message = error?.message || "Rename failed";
+ this.renameError = message;
+ const title =
+ this.renameMode === "create-folder" ? "Folder Error" : "Rename Error";
+ window.toastFrontendError(message, title);
+ } finally {
+ this.isRenaming = false;
+ }
+ },
+
+ // --- File Editor (Delegated to FileEditorStore) --------------------------
+ async openFileEditor(file) {
+ await fileEditorStore.openFile(file, async () => {
+ // Callback on successful save to refresh file list
+ await this.fetchFiles(this.browser.currentPath);
+ });
+ },
+
+ async openNewFile() {
+ const existingNames = (this.browser.entries || [])
+ .map((e) => e?.name)
+ .filter(Boolean);
+ await fileEditorStore.openNewFile(this.browser.currentPath, existingNames, async () => {
+ // Callback on successful save to refresh file list
+ await this.fetchFiles(this.browser.currentPath);
+ });
+ },
+
// --- File actions --------------------------------------------------------
async deleteFile(file) {
try {
@@ -181,13 +369,14 @@ const model = {
currentPath: this.browser.currentPath,
}),
});
- if (resp.ok) {
+ const data = await resp.json().catch(() => ({}));
+ if (resp.ok && !data.error) {
this.browser.entries = this.browser.entries.filter(
(e) => e.path !== file.path
);
window.toastFrontendSuccess("File deleted successfully", "File Deleted");
} else {
- window.toastFrontendError(`Error deleting file: ${await resp.text()}`, "Delete Error");
+ window.toastFrontendError(data.error || "Error deleting file", "Delete Error");
}
} catch (e) {
window.toastFrontendError(
@@ -222,8 +411,8 @@ const model = {
method: "POST",
body: formData,
});
- if (resp.ok) {
- const data = await resp.json();
+ const data = await resp.json().catch(() => ({}));
+ if (resp.ok && !data.error) {
this.browser.entries = data.data.entries;
this.browser.currentPath = data.data.current_path;
this.browser.parentPath = data.data.parent_path;
@@ -234,7 +423,7 @@ const model = {
alert(`Some files failed to upload:\n${msg}`);
}
} else {
- alert(await resp.text());
+ alert(data.error || "Error uploading files");
}
} catch (e) {
window.toastFrontendError(
diff --git a/webui/components/modals/file-browser/file-browser.html b/webui/components/modals/file-browser/file-browser.html
index 0ccec66a6..e46be6757 100644
--- a/webui/components/modals/file-browser/file-browser.html
+++ b/webui/components/modals/file-browser/file-browser.html
@@ -28,6 +28,16 @@
</button>
<div id="current-path"><span id="path-text" x-text="$store.fileBrowser.browser.currentPath"></span></div>
</div>
+ <div class="new-item-buttons">
+ <button class="btn btn-ok btn-new-item" @click="$store.fileBrowser.openNewFile()">
+ <span class="material-symbols-outlined">note_add</span>
+ New File
+ </button>
+ <button class="btn btn-ok btn-new-item" @click="$store.fileBrowser.openNewFolderModal()">
+ <span class="material-symbols-outlined">create_new_folder</span>
+ New Folder
+ </button>
+ </div>
<!-- Files list -->
<div class="files-list">
@@ -48,10 +58,60 @@
<div class="file-size" x-text="$store.fileBrowser.formatFileSize(file.size)"></div>
<div class="file-date" x-text="$store.fileBrowser.formatDate(file.modified)"></div>
<div class="file-actions">
- <button class="btn-icon-action" @click.stop="$store.fileBrowser.downloadFile(file)" title="Download file">
+ <!-- Single-item actions (Edit/Rename/...) are grouped under a dropdown -->
+ <div
+ class="dropdown file-actions-dropdown"
+ x-data="{
+ open: false,
+ toggle() { this.open = !this.open; },
+ close() { this.open = false; }
+ }"
+ @click.outside="close()"
+ @keydown.escape.window="close()"
+ >
+ <button
+ type="button"
+ class="btn-icon-action dropdown-trigger"
+ @click.stop="toggle()"
+ :aria-expanded="open.toString()"
+ aria-label="More actions"
+ title="More actions"
+ >
+ <span class="material-symbols-outlined">more_vert</span>
+ </button>
+
+ <div
+ class="dropdown-menu"
+ x-show="open"
+ x-transition
+ :class="{ 'bottom': $el.getBoundingClientRect().bottom > window.innerHeight - 100 }"
+ style="display: none;"
+ @click="close()"
+ >
+ <button
+ type="button"
+ class="dropdown-item"
+ x-show="!file.is_dir"
+ @click="$store.fileBrowser.openFileEditor(file)"
+ >
+ <span class="material-symbols-outlined">file_open</span>
+ <span>Edit</span>
+ </button>
+
+ <button
+ type="button"
+ class="dropdown-item"
+ @click="$store.fileBrowser.openRenameModal(file)"
+ >
+ <span class="material-symbols-outlined">drive_file_rename_outline</span>
+ <span>Rename</span>
+ </button>
+ </div>
+ </div>
+ <button class="btn-icon-action" x-show="!file.is_dir" @click.stop="$store.fileBrowser.downloadFile(file)" title="Download file">
<span class="material-symbols-outlined">download</span>
</button>
- <button class="btn-icon-action" @click.stop="$confirmClick($event, () => $store.fileBrowser.deleteFile(file))" title="Delete file">
+ <button class="btn-icon-action" @click.stop="$confirmClick($event, () => $store.fileBrowser.deleteFile(file))" title="Delete item">
<span class="material-symbols-outlined">delete</span>
</button>
</div>
@@ -132,8 +192,7 @@
/* File Browser Styles */
.files-list,
- .file-header,
- .file-item {
+ .file-header {
width: 100%;
border-radius: 4px;
overflow: hidden;
@@ -142,7 +201,7 @@
/* Header Styles */
.file-header {
display: grid;
- grid-template-columns: 2fr 0.6fr 1fr 80px;
+ grid-template-columns: 2fr 0.6fr 1fr 160px;
background: var(--secondary-bg);
padding: 8px 0;
font-weight: bold;
@@ -160,14 +219,15 @@
/* File Item Styles */
.file-item {
display: grid;
- grid-template-columns: 2fr 0.6fr 1fr 80px;
+ grid-template-columns: 2fr 0.6fr 1fr 160px;
align-items: center;
padding: 8px 0;
font-size: 0.875rem;
border-top: 1px solid var(--color-border);
transition: background-color 0.2s;
white-space: nowrap;
- overflow: hidden;
+ border-radius: 4px;
+ overflow: visible; /* allow action dropdown menus to overflow the row */
color: var(--color-text);
}
.file-item:hover {
@@ -221,6 +281,17 @@
border: 1px solid var(--color-border);
border-radius: 8px;
}
+
+ .new-item-buttons {
+ display: flex;
+ justify-content: flex-end;
+ gap: 0.5em;
+ margin-bottom: 0.5em;
+ }
+ .new-item-buttons button {
+ margin-left: 0.5em;
+ }
+
.nav-button {
padding: 4px 12px;
border: 1px solid var(--color-border);
@@ -285,11 +356,34 @@
display: flex;
gap: var(--spacing-xs);
}
+ .file-actions .dropdown-menu {
+ top: auto !important;
+ bottom: 100% !important;
+ margin-top: 0;
+ margin-bottom: var(--spacing-xs);
+ }
+ .btn-new-item {
+ display: inline-flex;
+ align-items: center;
+ gap: 0.4rem;
+ padding: 8px 14px;
+ }
+ .btn-secondary {
+ background: var(--color-secondary);
+ color: var(--color-text);
+ border: 1px solid var(--color-border);
+ }
+ .btn-secondary:hover {
+ filter: brightness(1.05);
+ }
+ .btn-secondary:active {
+ filter: brightness(0.95);
+ }
/* Responsive Design */
@media (max-width: 768px) {
.file-header,
.file-item {
- grid-template-columns: 1fr 0.5fr 80px;
+ grid-template-columns: 1fr 0.5fr 120px;
}
.file-cell-date,
.file-date {
@@ -299,7 +393,7 @@
@media (max-width: 540px) {
.file-header,
.file-item {
- grid-template-columns: 1fr 80px;
+ grid-template-columns: 1fr 120px;
}
.file-cell-size,
.file-size,
diff --git a/webui/components/modals/file-browser/rename-modal.html b/webui/components/modals/file-browser/rename-modal.html
new file mode 100644
index 000000000..6f0367f9a
--- /dev/null
+++ b/webui/components/modals/file-browser/rename-modal.html
@@ -0,0 +1,86 @@
+<html>
+<head>
+ <title>Rename</title>
+ <script type="module">
+ import { store } from "/components/modals/file-browser/file-browser-store.js";
+ </script>
+</head>
+<body>
+ <div x-data>
+ <template x-if="$store.fileBrowser">
+ <div class="rename-modal-root" x-init="$nextTick(() => $refs.renameInput?.focus())">
+ <div class="rename-form">
+ <label class="rename-label" x-text="$store.fileBrowser.renameMode === 'create-folder' ? 'New folder name' : 'New name'"></label>
+ <input
+ class="rename-input"
+ type="text"
+ x-ref="renameInput"
+ x-model="$store.fileBrowser.renameName"
+ @keydown.enter.prevent="$store.fileBrowser.confirmRename()"
+ :disabled="$store.fileBrowser.isRenaming"
+ />
+ <template x-if="$store.fileBrowser.renameError">
+ <p class="rename-error" x-text="$store.fileBrowser.renameError"></p>
+ </template>
+ <p class="rename-hint" x-text="$store.fileBrowser.renameMode === 'create-folder' ? 'Folder will be created in the current directory.' : 'Renaming will keep the item in the same directory.'"></p>
+ </div>
+ </div>
+ </template>
+ </div>
+
+ <template x-if="$store.fileBrowser">
+ <div class="modal-footer" data-modal-footer>
+ <button class="btn btn-cancel" @click="$store.fileBrowser.closeRenameModal()" :disabled="$store.fileBrowser.isRenaming">Cancel</button>
+ <button class="btn btn-ok" @click="$store.fileBrowser.confirmRename()" :disabled="$store.fileBrowser.isRenaming || !$store.fileBrowser.renameName.trim()" x-text="$store.fileBrowser.renameMode === 'create-folder' ? 'Create Folder' : 'Rename'"></button>
+ </div>
+ </template>
+
+ <style>
+ .rename-modal-root {
+ display: flex;
+ flex-direction: column;
+ gap: var(--spacing-md);
+ width: 100%;
+ }
+
+ .rename-form {
+ display: flex;
+ flex-direction: column;
+ gap: var(--spacing-sm);
+ margin: 1rem;
+ }
+
+ .rename-label {
+ font-weight: 600;
+ color: var(--color-text);
+ }
+
+ .rename-input {
+ width: 100%;
+ padding: 10px 12px;
+ border-radius: 6px;
+ border: 1px solid var(--color-border);
+ background: var(--color-background);
+ color: var(--color-text);
+ }
+
+ .rename-input:disabled {
+ opacity: 0.7;
+ cursor: not-allowed;
+ }
+
+ .rename-hint {
+ margin: 0;
+ color: var(--color-text-secondary);
+ font-size: 0.85rem;
+ }
+
+ .rename-error {
+ margin: 0;
+ color: var(--color-accent);
+ font-weight: 500;
+ font-size: 0.85rem;
+ }
+ </style>
+</body>
+</html>