diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index a5a093a1..ea6e43de 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -40,7 +40,9 @@ class MyEntityScript is ScriptableEntity { #include -namespace Nuake { +namespace Nuake +{ + // TODO: add filetree in same panel void FileSystemUI::Draw() { @@ -114,7 +116,7 @@ namespace Nuake { return true; } - void FileSystemUI::DrawFile(Ref file) + void FileSystemUI::DrawFile(Ref file, uint32_t drawId) { ImGui::PushFont(EditorInterface::bigIconFont); std::string fileExtension = file->GetExtension(); @@ -163,6 +165,26 @@ namespace Nuake { } } + const std::string hoverMenuId = std::string("item_hover_menu") + std::to_string(drawId); + if (ImGui::IsItemHovered() && ImGui::IsMouseReleased(1)) + { + ImGui::OpenPopup(hoverMenuId.c_str()); + m_hasClickedOnFile = true; + } + + if (ImGui::BeginPopup(hoverMenuId.c_str())) + { + if (ImGui::MenuItem("Delete")) + { + if(FileSystem::RemoveFile(file->GetAbsolutePath()) != 0) + { + Logger::Log("Failed to remove file: " + file->GetAbsolutePath(), CRITICAL); + } + } + ImGui::EndPopup(); + RefreshFileBrowser(); + } + ImGui::Text(file->GetName().c_str()); ImGui::PopFont(); } @@ -181,7 +203,12 @@ namespace Nuake { void FileSystemUI::DrawContextMenu() { - if (ImGui::BeginPopupContextWindow()) + if (!m_hasClickedOnFile && ImGui::IsMouseReleased(1) && ImGui::IsWindowHovered()) + { + ImGui::OpenPopup("window_hover_menu"); + } + + if (ImGui::BeginPopup("window_hover_menu")) { if (ImGui::MenuItem("New folder")) { @@ -372,12 +399,14 @@ namespace Nuake { else ImGui::TableNextRow(); - DrawFile(f); + DrawFile(f, i); i++; } } DrawContextMenu(); + m_hasClickedOnFile = false; + ImGui::EndTable(); } diff --git a/Editor/src/Windows/FileSystemUI.h b/Editor/src/Windows/FileSystemUI.h index be528a2b..2ab62141 100644 --- a/Editor/src/Windows/FileSystemUI.h +++ b/Editor/src/Windows/FileSystemUI.h @@ -11,9 +11,12 @@ namespace Nuake { public: Ref m_CurrentDirectory; + bool m_hasClickedOnFile; - FileSystemUI(EditorInterface* editor) { + FileSystemUI(EditorInterface* editor) + { m_CurrentDirectory = FileSystem::RootDirectory; + m_hasClickedOnFile = false; Editor = editor; } @@ -23,8 +26,9 @@ namespace Nuake { void EditorInterfaceDrawFiletree(Ref dir); void DrawDirectory(Ref directory); bool EntityContainsItself(Entity source, Entity target); - void DrawFile(Ref file); + void DrawFile(Ref file, uint32_t drawId); void DrawDirectoryExplorer(); + bool DeletePopup(); void DrawContextMenu(); void RefreshFileBrowser(); }; diff --git a/Nuake/src/Core/FileSystem.cpp b/Nuake/src/Core/FileSystem.cpp index 6bc26271..1376a051 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -166,6 +166,11 @@ namespace Nuake fileWriter.close(); } + int FileSystem::RemoveFile(const std::string& path) + { + return std::remove(path.c_str()); + } + Ref FileSystem::GetFileTree() { return RootDirectory; diff --git a/Nuake/src/Core/FileSystem.h b/Nuake/src/Core/FileSystem.h index 0a4ba20a..f0f8ecf1 100644 --- a/Nuake/src/Core/FileSystem.h +++ b/Nuake/src/Core/FileSystem.h @@ -43,6 +43,7 @@ namespace Nuake static bool BeginWriteFile(const std::string path); static bool WriteLine(const std::string line); static void EndWriteFile(); + static int RemoveFile(const std::string& path); }; class File