From 782f4bbafdcc6f318441c3cc652c3f4fa2594702 Mon Sep 17 00:00:00 2001 From: emerycp Date: Sat, 22 Jul 2023 13:05:22 -0400 Subject: [PATCH] NK-107 - Context Menu Folder --- Editor/src/Windows/FileSystemUI.cpp | 66 ++++++++++++++++++++++++++--- Editor/src/Windows/FileSystemUI.h | 2 +- Nuake/src/Core/FileSystem.cpp | 5 +++ Nuake/src/Core/FileSystem.h | 1 + 4 files changed, 67 insertions(+), 7 deletions(-) diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index bba1f1c7..c2680c78 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -55,7 +55,7 @@ namespace Nuake } } - void FileSystemUI::DrawDirectory(Ref directory) + void FileSystemUI::DrawDirectory(Ref directory, uint32_t drawId) { ImGui::PushFont(FontManager::GetFont(Icons)); const char* icon = ICON_FA_FOLDER; @@ -65,6 +65,63 @@ namespace Nuake m_CurrentDirectory = directory; } + 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("Open")) + { + m_CurrentDirectory = directory; + } + + ImGui::Separator(); + + if (ImGui::BeginMenu("Copy")) + { + if (ImGui::MenuItem("Full Path")) + { + OS::CopyToClipboard(directory->fullPath); + } + + if (ImGui::MenuItem("Directory Name")) + { + OS::CopyToClipboard(String::Split(directory->name, '/')[0]); + } + + ImGui::EndPopup(); + } + + if (ImGui::MenuItem("Delete")) + { + if (FileSystem::DeleteFolder(directory->fullPath) != 0) + { + Logger::Log("Failed to remove directory: " + directory->name, "editor", CRITICAL); + } + RefreshFileBrowser(); + } + + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 0.2f)); + if (ImGui::MenuItem("Rename")) + { + + } + ImGui::PopStyleColor(); + + ImGui::Separator(); + + if (ImGui::MenuItem("Show in File Explorer")) + { + OS::OpenIn(directory->fullPath); + } + + ImGui::EndPopup(); + } + ImGui::Text(directory->name.c_str()); ImGui::PopFont(); } @@ -229,10 +286,7 @@ namespace Nuake if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) { - if (file->GetExtension() == ".scene") - { - PopupHelper::Confirmation(openScene); - } + shouldOpenScene = file->GetExtension() == ".scene"; } if (shouldOpenScene) @@ -545,7 +599,7 @@ namespace Nuake else ImGui::TableNextRow(); - DrawDirectory(d); + DrawDirectory(d, i); i++; } } diff --git a/Editor/src/Windows/FileSystemUI.h b/Editor/src/Windows/FileSystemUI.h index edad2cee..9090aa85 100644 --- a/Editor/src/Windows/FileSystemUI.h +++ b/Editor/src/Windows/FileSystemUI.h @@ -24,7 +24,7 @@ namespace Nuake { void DrawDirectoryContent(); void DrawFiletree(); void EditorInterfaceDrawFiletree(Ref dir); - void DrawDirectory(Ref directory); + void DrawDirectory(Ref directory, uint32_t drawId); bool EntityContainsItself(Entity source, Entity target); void DrawFile(Ref file, uint32_t drawId); void DrawDirectoryExplorer(); diff --git a/Nuake/src/Core/FileSystem.cpp b/Nuake/src/Core/FileSystem.cpp index 8b943af5..a8d49aae 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -178,6 +178,11 @@ namespace Nuake return std::remove(path.c_str()); } + int FileSystem::DeleteFolder(const std::string& path) + { + return std::filesystem::remove_all(path.c_str()); + } + Ref FileSystem::GetFileTree() { return RootDirectory; diff --git a/Nuake/src/Core/FileSystem.h b/Nuake/src/Core/FileSystem.h index 460a9966..c0f0bade 100644 --- a/Nuake/src/Core/FileSystem.h +++ b/Nuake/src/Core/FileSystem.h @@ -47,6 +47,7 @@ namespace Nuake static bool WriteLine(const std::string line); static void EndWriteFile(); static int RemoveFile(const std::string& path); + static int DeleteFolder(const std::string& path); }; class File