diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index a5a093a1..cde997cf 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -41,6 +41,7 @@ class MyEntityScript is ScriptableEntity { #include namespace Nuake { + // TODO: add filetree in same panel void FileSystemUI::Draw() { @@ -114,7 +115,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 +164,25 @@ 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().c_str()) != 0) + { + Logger::Log("Failed to remove file: " + file->GetAbsolutePath(), CRITICAL); + } + } + ImGui::EndPopup(); + RefreshFileBrowser(); + } + ImGui::Text(file->GetName().c_str()); ImGui::PopFont(); } @@ -181,7 +201,9 @@ 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 +394,13 @@ 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..0c9de64d 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -166,6 +166,11 @@ namespace Nuake fileWriter.close(); } + int FileSystem::RemoveFile(char const* path) + { + return std::remove(path); + } + Ref FileSystem::GetFileTree() { return RootDirectory; diff --git a/Nuake/src/Core/FileSystem.h b/Nuake/src/Core/FileSystem.h index 0a4ba20a..e24efaac 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(char const* path); }; class File