From 83bbb4f6ba9ba1ff6fb53befc2064387c2d9a314 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 6 Mar 2026 19:39:49 -0600 Subject: [PATCH] Add recycle bin to script deleting. --- .../Editor/Modules/ContentDatabaseModule.cs | 6 ++++- Source/Engine/Content/Content.cpp | 27 ++++++++++++++++--- Source/Engine/Content/Content.h | 8 +++++- .../Platform/Windows/WindowsFileSystem.cpp | 4 +-- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Source/Editor/Modules/ContentDatabaseModule.cs b/Source/Editor/Modules/ContentDatabaseModule.cs index 9c16324f3..57982f8c3 100644 --- a/Source/Editor/Modules/ContentDatabaseModule.cs +++ b/Source/Editor/Modules/ContentDatabaseModule.cs @@ -754,6 +754,10 @@ namespace FlaxEditor.Modules // Delete asset by using content pool FlaxEngine.Content.DeleteAsset(path); } + else if (item is ScriptItem) + { + FlaxEngine.Content.DeleteScript(path); + } else if (deletedByUser) { // Delete file @@ -901,7 +905,7 @@ namespace FlaxEditor.Modules { // Item doesn't exist anymore Editor.Log(string.Format($"Content item \'{child.Path}\' has been removed")); - Delete(child, false); + Delete(child); i--; } else if (canHaveAssets && child is AssetItem childAsset) diff --git a/Source/Engine/Content/Content.cpp b/Source/Engine/Content/Content.cpp index 1e2e267d9..4d63368fa 100644 --- a/Source/Engine/Content/Content.cpp +++ b/Source/Engine/Content/Content.cpp @@ -791,6 +791,27 @@ void Content::DeleteAsset(Asset* asset) asset->DeleteObject(); } +void Content::DeleteScript(const StringView& path) +{ + PROFILE_CPU(); + if (path.IsEmpty()) + return; + + // Return if asset + Asset* asset = GetAsset(path); + if (asset != nullptr) + { + return; + } + +#if USE_EDITOR + LOG(Info, "Deleting script '{0}'", path); + + // Delete file + deleteFileSafety(path, Guid::Empty, false); +#endif +} + void Content::DeleteAsset(const StringView& path) { PROFILE_CPU(); @@ -823,9 +844,9 @@ void Content::DeleteAsset(const StringView& path) #endif } -void Content::deleteFileSafety(const StringView& path, const Guid& id) +void Content::deleteFileSafety(const StringView& path, const Guid& id, bool useId) { - if (!id.IsValid()) + if (!id.IsValid() && useId) { LOG(Warning, "Cannot remove file \'{0}\'. Given ID is invalid.", path); return; @@ -834,7 +855,7 @@ void Content::deleteFileSafety(const StringView& path, const Guid& id) // Ensure that file has the same ID (prevent from deleting different assets) auto storage = ContentStorageManager::TryGetStorage(path); - if (storage) + if (storage && useId) { storage->CloseFileHandles(); // Close file handle to allow removing it if (!storage->HasAsset(id)) diff --git a/Source/Engine/Content/Content.h b/Source/Engine/Content/Content.h index e286e7c7d..9f0e2eeef 100644 --- a/Source/Engine/Content/Content.h +++ b/Source/Engine/Content/Content.h @@ -306,6 +306,12 @@ public: /// /// The asset. API_FUNCTION() static void DeleteAsset(Asset* asset); + + /// + /// Deletes the script item at the specified path. + /// + /// The script path. + API_FUNCTION() static void DeleteScript(const StringView& path); /// /// Deletes the asset at the specified path. @@ -389,7 +395,7 @@ private: static void onAssetLoaded(Asset* asset); static void onAssetUnload(Asset* asset); static void onAssetChangeId(Asset* asset, const Guid& oldId, const Guid& newId); - static void deleteFileSafety(const StringView& path, const Guid& id); + static void deleteFileSafety(const StringView& path, const Guid& id, bool useId = true); // Internal bindings #if !COMPILE_WITHOUT_CSHARP diff --git a/Source/Engine/Platform/Windows/WindowsFileSystem.cpp b/Source/Engine/Platform/Windows/WindowsFileSystem.cpp index 3019b49a7..f5acd6df0 100644 --- a/Source/Engine/Platform/Windows/WindowsFileSystem.cpp +++ b/Source/Engine/Platform/Windows/WindowsFileSystem.cpp @@ -17,7 +17,7 @@ #define __shobjidl_h__ #define LPFNADDPROPSHEETPAGE void* #include -#include +#include #include #undef ShellExecute @@ -111,7 +111,7 @@ bool WindowsFileSystem::MoveFileToRecycleBin(const StringView& path) op.wFunc = FO_DELETE; op.pFrom = pathNullNull; op.pTo = nullptr; - op.fFlags = FOF_ALLOWUNDO | FOF_NO_UI; + op.fFlags = FOF_ALLOWUNDO | FOF_NO_UI | FOF_NOCONFIRMATION; op.fAnyOperationsAborted = FALSE; op.hNameMappings = nullptr; op.lpszProgressTitle = nullptr;