Add recycle bin to script deleting.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -306,6 +306,12 @@ public:
|
||||
/// </summary>
|
||||
/// <param name="asset">The asset.</param>
|
||||
API_FUNCTION() static void DeleteAsset(Asset* asset);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the script item at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The script path.</param>
|
||||
API_FUNCTION() static void DeleteScript(const StringView& path);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#define __shobjidl_h__
|
||||
#define LPFNADDPROPSHEETPAGE void*
|
||||
#include <ShlObj.h>
|
||||
#include <ShellAPI.h>
|
||||
#include <shellapi.h>
|
||||
#include <KnownFolders.h>
|
||||
#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;
|
||||
|
||||
Reference in New Issue
Block a user