mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Deletion of Assets and Directories
This commit is contained in:
@@ -137,6 +137,36 @@ class AssetHierarchy
|
|||||||
Log.EngineLogger.Trace($"Created root node");
|
Log.EngineLogger.Trace($"Created root node");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Deletes the file that belongs to the given assetNode
|
||||||
|
public void DeleteFile(AssetNode assetNode)
|
||||||
|
{
|
||||||
|
if (assetNode.IsDirectory)
|
||||||
|
{
|
||||||
|
if (Directory.DelTree(assetNode.Path) case .Err(let error))
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Error($"Couldn't delete Directory ({error}).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (File.Delete(assetNode.Path) case .Err(let error))
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Error($"Couldn't delete File \"{assetNode.Path}\" ({error}).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StringView assetDescriptorPath = assetNode.AssetFile?.FilePath ?? "";
|
||||||
|
|
||||||
|
// If it exists, also try to delete the .ass file
|
||||||
|
if (File.Exists(assetDescriptorPath))
|
||||||
|
{
|
||||||
|
if (File.Delete(assetDescriptorPath) case .Err(let error))
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Error($"Couldn't delete Asset descriptor file \"{assetDescriptorPath}\" ({error}).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SetResourcesDirectory(StringView fileName)
|
public void SetResourcesDirectory(StringView fileName)
|
||||||
{
|
{
|
||||||
ResourcesDirectory = fileName;
|
ResourcesDirectory = fileName;
|
||||||
|
|||||||
@@ -469,12 +469,17 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
ImGui.TextUnformatted(entry->Name);
|
ImGui.TextUnformatted(entry->Name);
|
||||||
|
|
||||||
|
bool wantsDelete = false;
|
||||||
|
|
||||||
if (ImGui.BeginPopupContextWindow())
|
if (ImGui.BeginPopupContextWindow())
|
||||||
{
|
{
|
||||||
ShowItemContextMenu(entry);
|
ShowItemContextMenu(entry, ref wantsDelete);
|
||||||
ImGui.EndPopup();
|
ImGui.EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wantsDelete)
|
||||||
|
ImGui.OpenPopup("Delete?");
|
||||||
|
|
||||||
// TODO: Sub assets are probably borked now... I don't know if they ever worked, didn't test them
|
// TODO: Sub assets are probably borked now... I don't know if they ever worked, didn't test them
|
||||||
if (entry->SubAssets?.Count > 0)
|
if (entry->SubAssets?.Count > 0)
|
||||||
{
|
{
|
||||||
@@ -532,6 +537,8 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
if (ImGui.Button("Yes", ImGui.Vec2(120, 0)))
|
if (ImGui.Button("Yes", ImGui.Vec2(120, 0)))
|
||||||
{
|
{
|
||||||
|
_manager.AssetHierarchy.DeleteFile(fileOrFolder.Value);
|
||||||
|
|
||||||
ImGui.CloseCurrentPopup();
|
ImGui.CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -548,7 +555,7 @@ namespace GlitchyEditor.EditWindows
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Shows the context menu for the given file/folder.
|
/// Shows the context menu for the given file/folder.
|
||||||
private void ShowItemContextMenu(TreeNode<AssetNode> fileOrFolder)
|
private void ShowItemContextMenu(TreeNode<AssetNode> fileOrFolder, ref bool wantsDelete)
|
||||||
{
|
{
|
||||||
bool isFile = !fileOrFolder->IsDirectory;
|
bool isFile = !fileOrFolder->IsDirectory;
|
||||||
|
|
||||||
@@ -570,7 +577,7 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
if (ImGui.MenuItem("Delete"))
|
if (ImGui.MenuItem("Delete"))
|
||||||
{
|
{
|
||||||
ImGui.OpenPopup("Delete?");
|
wantsDelete = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user