From 1e2f6e2d674bc38b343f8cf28d8762fa36fb6e88 Mon Sep 17 00:00:00 2001 From: WuTofu <5987870+WuTofu@users.noreply.github.com> Date: Fri, 8 May 2026 06:32:30 +0800 Subject: [PATCH] feat: enhance long press action to delete both files and directories (#1803) ## Summary * **What is the goal of this PR?** Enhance file browser long-press behavior so the delete action now works for both files and directories. * **What changes are included?** Updated `FileBrowserActivity.cpp` to support for directory deletion on long-press --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**NO**_ --- src/activities/home/FileBrowserActivity.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/activities/home/FileBrowserActivity.cpp b/src/activities/home/FileBrowserActivity.cpp index 3ea626e2..870e93b6 100644 --- a/src/activities/home/FileBrowserActivity.cpp +++ b/src/activities/home/FileBrowserActivity.cpp @@ -139,17 +139,20 @@ void FileBrowserActivity::loop() { return; } - if (mode == Mode::Books && mappedInput.getHeldTime() >= GO_HOME_MS && !isDirectory) { - // --- LONG PRESS ACTION: DELETE FILE --- + if (mode == Mode::Books && mappedInput.getHeldTime() >= GO_HOME_MS) { + // --- LONG PRESS ACTION: DELETE FILE OR DIRECTORY --- std::string cleanBasePath = basepath; if (cleanBasePath.back() != '/') cleanBasePath += "/"; const std::string fullPath = cleanBasePath + entry; - auto handler = [this, fullPath](const ActivityResult& res) { + auto handler = [this, fullPath, isDirectory](const ActivityResult& res) { if (!res.isCancelled) { LOG_DBG("FileBrowser", "Attempting to delete: %s", fullPath.c_str()); - clearFileMetadata(fullPath); - if (Storage.remove(fullPath.c_str())) { + if (!isDirectory) { + clearFileMetadata(fullPath); + } + const bool deleted = isDirectory ? Storage.removeDir(fullPath.c_str()) : Storage.remove(fullPath.c_str()); + if (deleted) { LOG_DBG("FileBrowser", "Deleted successfully"); loadFiles(); if (files.empty()) { @@ -161,7 +164,7 @@ void FileBrowserActivity::loop() { requestUpdate(true); } else { - LOG_ERR("FileBrowser", "Failed to delete file: %s", fullPath.c_str()); + LOG_ERR("FileBrowser", "Failed to delete: %s", fullPath.c_str()); } } else { LOG_DBG("FileBrowser", "Delete cancelled by user");