From 6e38bf2c249ebcd6b6d96bb81c64a3ede2c0c8ab Mon Sep 17 00:00:00 2001 From: emerycp Date: Tue, 1 Aug 2023 11:57:26 -0400 Subject: [PATCH 1/6] NK92 - Search crawling Do a Log for now. --- Nuake/src/Core/FileSystem.cpp | 10 ++++++++++ Nuake/src/Core/FileSystem.h | 1 + Nuake/src/Core/String.cpp | 13 +++++++++++++ Nuake/src/Core/String.h | 1 + 4 files changed, 25 insertions(+) diff --git a/Nuake/src/Core/FileSystem.cpp b/Nuake/src/Core/FileSystem.cpp index c2ed7bac..9dcab855 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -228,5 +228,15 @@ namespace Nuake const auto& split = String::Split(path, '\\'); return String::Split(split[split.size() - 1], '.')[0]; } + + void FileSystem::SearchFilesWithKeyword(const std::string& keyword, const std::string& directory) { + const std::string& sanitizedKeyword = String::Sanitize(keyword); + for (const auto& entry : std::filesystem::recursive_directory_iterator(directory)) { + if (entry.is_regular_file() && entry.path().filename().string().find(sanitizedKeyword) != std::string::npos) { + std::cout << entry.path() << std::endl; + } + } + } + } diff --git a/Nuake/src/Core/FileSystem.h b/Nuake/src/Core/FileSystem.h index f337058f..5a7ea8f4 100644 --- a/Nuake/src/Core/FileSystem.h +++ b/Nuake/src/Core/FileSystem.h @@ -34,6 +34,7 @@ namespace Nuake static Ref GetFileTree(); static Ref GetFile(const std::string& path); static std::string GetFileNameFromPath(const std::string& path); + static void FileSystem::SearchFilesWithKeyword(const std::string& keyword, const std::string& directory); static void ScanDirectory(Ref directory); static void GetDirectories(); diff --git a/Nuake/src/Core/String.cpp b/Nuake/src/Core/String.cpp index 7c4ccc5a..cd68caf7 100644 --- a/Nuake/src/Core/String.cpp +++ b/Nuake/src/Core/String.cpp @@ -1,5 +1,6 @@ #include "String.h" #include +#include #include namespace Nuake @@ -36,6 +37,18 @@ namespace Nuake return result; } + std::string String::Sanitize(const std::string& keyword) { + std::string sanitizedKeyword = keyword; + + // Remove spaces, underscores, and hyphens using regex + sanitizedKeyword = std::regex_replace(sanitizedKeyword, std::regex("[ _-]+"), ""); + + // Convert to lowercase + std::transform(sanitizedKeyword.begin(), sanitizedKeyword.end(), sanitizedKeyword.begin(), ::tolower); + + return sanitizedKeyword; + } + std::vector String::Split(const std::string& string, char delimiter) { std::vector result; diff --git a/Nuake/src/Core/String.h b/Nuake/src/Core/String.h index be3f6aa7..c3b55e17 100644 --- a/Nuake/src/Core/String.h +++ b/Nuake/src/Core/String.h @@ -15,6 +15,7 @@ namespace Nuake static bool EndsWith(const std::string& string, const std::string& end); static bool IsDigit(const char& character); static std::string RemoveWhiteSpace(const std::string& string); + static std::string Sanitize(const std::string& keyword); static std::vector Split(const std::string& string, char delimiter); static float ToFloat(const std::string& string); From ff82a185871fe84b1ba4de37d1f7d1c79c18ff93 Mon Sep 17 00:00:00 2001 From: emerycp Date: Tue, 1 Aug 2023 14:28:17 -0400 Subject: [PATCH 2/6] NK-92 - Update file system --- Editor/src/Windows/FileSystemUI.cpp | 16 ++++++++++++++++ Editor/src/Windows/FileSystemUI.h | 1 + Nuake/src/Core/FileSystem.cpp | 25 ++++++++++++++----------- Nuake/src/Core/FileSystem.h | 3 ++- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 2e10a976..68ae7a99 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -583,6 +583,22 @@ namespace Nuake const uint32_t numButtonAfterPathBrowser = 2; ImGui::SameLine(); + char buffer[256]; + memset(buffer, 0, sizeof(buffer)); + std::strncpy(buffer, m_searchKeyWord.c_str(), sizeof(buffer)); + + if (ImGui::InputTextWithHint("##Search", "Asset search & filter ..", buffer, sizeof(buffer))) + { + m_searchKeyWord = std::string(buffer); + FileSystem::FilteredDirectories = FileSystem::SearchFilesWithKeyword(m_searchKeyWord, FileSystem::RootDirectory->fullPath); + RefreshFileBrowser(); + + // TODO: Fix when creating a new file + } + + + ImGui::SameLine(); + ImGui::PushStyleColor(ImGuiCol_ChildBg, colors[ImGuiCol_TitleBgCollapsed]); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 4)); diff --git a/Editor/src/Windows/FileSystemUI.h b/Editor/src/Windows/FileSystemUI.h index 9090aa85..514748fa 100644 --- a/Editor/src/Windows/FileSystemUI.h +++ b/Editor/src/Windows/FileSystemUI.h @@ -12,6 +12,7 @@ namespace Nuake { public: static Ref m_CurrentDirectory; bool m_hasClickedOnFile; + std::string m_searchKeyWord; FileSystemUI(EditorInterface* editor) { diff --git a/Nuake/src/Core/FileSystem.cpp b/Nuake/src/Core/FileSystem.cpp index 9dcab855..cd362270 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -57,6 +57,7 @@ namespace Nuake std::string FileSystem::Root = ""; Ref FileSystem::RootDirectory; + std::vector FileSystem::FilteredDirectories; void FileSystem::ScanDirectory(Ref directory) { @@ -75,15 +76,15 @@ namespace Nuake } else if (entry.is_regular_file()) { - std::string absolutePath = entry.path().string(); - std::string name = entry.path().filename().string(); - std::string extension = entry.path().extension().string(); - Ref newFile = CreateRef(directory, absolutePath, name, extension); - //newFile->Type = entry.path().extension().string(); - //newFile->name = entry.path().filename().string(); - //newFile->Parent = directory; - //newFile->fullPath = entry.path().string(); - directory->Files.push_back(newFile); + std::filesystem::path currentPath = entry.path(); + if (FilteredDirectories.empty() || std::find(FilteredDirectories.begin(), FilteredDirectories.end(), currentPath) != FilteredDirectories.end()) + { + std::string absolutePath = currentPath.string(); + std::string name = currentPath.filename().string(); + std::string extension = currentPath.extension().string(); + Ref newFile = CreateRef(directory, absolutePath, name, extension); + directory->Files.push_back(newFile); + } } } } @@ -229,13 +230,15 @@ namespace Nuake return String::Split(split[split.size() - 1], '.')[0]; } - void FileSystem::SearchFilesWithKeyword(const std::string& keyword, const std::string& directory) { + std::vector FileSystem::SearchFilesWithKeyword(const std::string& keyword, const std::string& directory) { + std::vector result; const std::string& sanitizedKeyword = String::Sanitize(keyword); for (const auto& entry : std::filesystem::recursive_directory_iterator(directory)) { if (entry.is_regular_file() && entry.path().filename().string().find(sanitizedKeyword) != std::string::npos) { - std::cout << entry.path() << std::endl; + result.push_back(entry.path()); } } + return result; } diff --git a/Nuake/src/Core/FileSystem.h b/Nuake/src/Core/FileSystem.h index 5a7ea8f4..f9771bbf 100644 --- a/Nuake/src/Core/FileSystem.h +++ b/Nuake/src/Core/FileSystem.h @@ -25,6 +25,7 @@ namespace Nuake static std::string Root; static Ref RootDirectory; + static std::vector FilteredDirectories; static void SetRootDirectory(const std::string path); @@ -34,7 +35,7 @@ namespace Nuake static Ref GetFileTree(); static Ref GetFile(const std::string& path); static std::string GetFileNameFromPath(const std::string& path); - static void FileSystem::SearchFilesWithKeyword(const std::string& keyword, const std::string& directory); + static std::vector FileSystem::SearchFilesWithKeyword(const std::string& keyword, const std::string& directory); static void ScanDirectory(Ref directory); static void GetDirectories(); From b114d27ce2b562c70492a95be69e04efb522d637 Mon Sep 17 00:00:00 2001 From: emerycp Date: Tue, 1 Aug 2023 17:16:48 -0400 Subject: [PATCH 3/6] NK-92 - Fix when creating a new file --- Editor/src/Windows/FileSystemUI.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 68ae7a99..0c213fcc 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -593,7 +593,10 @@ namespace Nuake FileSystem::FilteredDirectories = FileSystem::SearchFilesWithKeyword(m_searchKeyWord, FileSystem::RootDirectory->fullPath); RefreshFileBrowser(); - // TODO: Fix when creating a new file + if(m_searchKeyWord.empty()) + { + FileSystem::FilteredDirectories.clear(); + } } From 9159c6236bcf21addfb32f21ac21c60545f15048 Mon Sep 17 00:00:00 2001 From: emerycp Date: Tue, 1 Aug 2023 19:39:38 -0400 Subject: [PATCH 4/6] NK-92 - Search Bar In Filebrowser --- Editor/src/Windows/FileSystemUI.cpp | 79 +++++++++++++++-------------- Nuake/src/Core/FileSystem.cpp | 27 ++-------- Nuake/src/Core/FileSystem.h | 2 - Nuake/src/Window.cpp | 4 +- 4 files changed, 49 insertions(+), 63 deletions(-) diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 0c213fcc..1bce4aa3 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -384,6 +384,7 @@ namespace Nuake ImGui::Text(file->GetName().c_str()); ImGui::PopFont(); + } bool Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size = -1.0f) @@ -532,8 +533,6 @@ namespace Nuake ImGui::EndChild(); ImGui::SameLine(); - avail = ImGui::GetContentRegionAvail(); - std::vector> paths = std::vector>(); Ref currentParent = m_CurrentDirectory; @@ -581,31 +580,13 @@ namespace Nuake } const uint32_t numButtonAfterPathBrowser = 2; - ImGui::SameLine(); - - char buffer[256]; - memset(buffer, 0, sizeof(buffer)); - std::strncpy(buffer, m_searchKeyWord.c_str(), sizeof(buffer)); - - if (ImGui::InputTextWithHint("##Search", "Asset search & filter ..", buffer, sizeof(buffer))) - { - m_searchKeyWord = std::string(buffer); - FileSystem::FilteredDirectories = FileSystem::SearchFilesWithKeyword(m_searchKeyWord, FileSystem::RootDirectory->fullPath); - RefreshFileBrowser(); - - if(m_searchKeyWord.empty()) - { - FileSystem::FilteredDirectories.clear(); - } - } - - + const uint32_t searchBarSize = 6; ImGui::SameLine(); ImGui::PushStyleColor(ImGuiCol_ChildBg, colors[ImGuiCol_TitleBgCollapsed]); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 4)); - ImGui::BeginChild("pathBrowser", ImVec2(ImGui::GetContentRegionAvail().x - (numButtonAfterPathBrowser * buttonWidth) - 4.0, 24)); + ImGui::BeginChild("pathBrowser", ImVec2((ImGui::GetContentRegionAvail().x - (numButtonAfterPathBrowser * buttonWidth * searchBarSize)) - 4.0, 24)); for (int i = paths.size() - 1; i > 0; i--) { if (i != paths.size()) @@ -629,13 +610,30 @@ namespace Nuake ImGui::SameLine(); ImGui::Text("/"); } - + ImGui::EndChild(); ImGui::PopStyleVar(); - ImGui::PopStyleVar(); ImGui::PopStyleColor(); + + ImGui::SameLine(); + + ImGui::BeginChild("searchBar", ImVec2(ImGui::GetContentRegionAvail().x - (numButtonAfterPathBrowser * buttonWidth), 24)); + char buffer[256]; + memset(buffer, 0, sizeof(buffer)); + std::strncpy(buffer, m_searchKeyWord.c_str(), sizeof(buffer)); + if (ImGui::InputTextEx("##Search", "Asset search & filter ..", buffer, sizeof(buffer), ImVec2(ImGui::GetContentRegionAvail().x, 24), ImGuiInputTextFlags_EscapeClearsAll)) + { + m_searchKeyWord = std::string(buffer); + // FileSystem::FilteredFiles = FileSystem::SearchFilesWithKeyword(m_searchKeyWord, FileSystem::RootDirectory->fullPath); + // if(m_searchKeyWord.empty()) + // { + // FileSystem::FilteredFiles.clear(); + // } + //RefreshFileBrowser(); + } + ImGui::EndChild(); ImGui::SameLine(); @@ -652,8 +650,9 @@ namespace Nuake } ImGui::PopStyleColor(); // Button color + + ImGui::SameLine(); } - ImGui::EndChild(); ImDrawList* drawList = ImGui::GetWindowDrawList(); @@ -687,13 +686,16 @@ namespace Nuake { for (Ref& d : m_CurrentDirectory->Directories) { - if (i + 1 % amount != 0) - ImGui::TableNextColumn(); - else - ImGui::TableNextRow(); + if(String::Sanitize(d->name).find(String::Sanitize(m_searchKeyWord)) != std::string::npos) + { + if (i + 1 % amount != 0) + ImGui::TableNextColumn(); + else + ImGui::TableNextRow(); - DrawDirectory(d, i); - i++; + DrawDirectory(d, i); + i++; + } } } @@ -701,13 +703,16 @@ namespace Nuake { for (auto f : m_CurrentDirectory->Files) { - if (i - 1 % amount != 0 || i == 1) - ImGui::TableNextColumn(); - else - ImGui::TableNextRow(); + if(String::Sanitize(f->GetName()).find(String::Sanitize(m_searchKeyWord)) != std::string::npos) + { + if (i - 1 % amount != 0 || i == 1) + ImGui::TableNextColumn(); + else + ImGui::TableNextRow(); - DrawFile(f, i); - i++; + DrawFile(f, i); + i++; + } } } diff --git a/Nuake/src/Core/FileSystem.cpp b/Nuake/src/Core/FileSystem.cpp index cd362270..0298be94 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -57,7 +57,6 @@ namespace Nuake std::string FileSystem::Root = ""; Ref FileSystem::RootDirectory; - std::vector FileSystem::FilteredDirectories; void FileSystem::ScanDirectory(Ref directory) { @@ -71,20 +70,16 @@ namespace Nuake newDir->Parent = directory; ScanDirectory(newDir); - directory->Directories.push_back(newDir); } else if (entry.is_regular_file()) { std::filesystem::path currentPath = entry.path(); - if (FilteredDirectories.empty() || std::find(FilteredDirectories.begin(), FilteredDirectories.end(), currentPath) != FilteredDirectories.end()) - { - std::string absolutePath = currentPath.string(); - std::string name = currentPath.filename().string(); - std::string extension = currentPath.extension().string(); - Ref newFile = CreateRef(directory, absolutePath, name, extension); - directory->Files.push_back(newFile); - } + std::string absolutePath = currentPath.string(); + std::string name = currentPath.filename().string(); + std::string extension = currentPath.extension().string(); + Ref newFile = CreateRef(directory, absolutePath, name, extension); + directory->Files.push_back(newFile); } } } @@ -229,17 +224,5 @@ namespace Nuake const auto& split = String::Split(path, '\\'); return String::Split(split[split.size() - 1], '.')[0]; } - - std::vector FileSystem::SearchFilesWithKeyword(const std::string& keyword, const std::string& directory) { - std::vector result; - const std::string& sanitizedKeyword = String::Sanitize(keyword); - for (const auto& entry : std::filesystem::recursive_directory_iterator(directory)) { - if (entry.is_regular_file() && entry.path().filename().string().find(sanitizedKeyword) != std::string::npos) { - result.push_back(entry.path()); - } - } - return result; - } - } diff --git a/Nuake/src/Core/FileSystem.h b/Nuake/src/Core/FileSystem.h index f9771bbf..f337058f 100644 --- a/Nuake/src/Core/FileSystem.h +++ b/Nuake/src/Core/FileSystem.h @@ -25,7 +25,6 @@ namespace Nuake static std::string Root; static Ref RootDirectory; - static std::vector FilteredDirectories; static void SetRootDirectory(const std::string path); @@ -35,7 +34,6 @@ namespace Nuake static Ref GetFileTree(); static Ref GetFile(const std::string& path); static std::string GetFileNameFromPath(const std::string& path); - static std::vector FileSystem::SearchFilesWithKeyword(const std::string& keyword, const std::string& directory); static void ScanDirectory(Ref directory); static void GetDirectories(); diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index abfcf8a3..97f38215 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -67,7 +67,7 @@ namespace Nuake SetWindowIcon("resources/Images/nuake-logo.png"); glfwMakeContextCurrent(m_Window); - //SetVSync(true) + SetVSync(true); Logger::Log("Driver detected " + std::string(((char*)glGetString(GL_VERSION))), "renderer"); @@ -248,7 +248,7 @@ namespace Nuake void Window::SetVSync(bool enabled) { - glfwSwapInterval(enabled ? 0 : 1); + glfwSwapInterval(enabled ? 1: 0); } void Window::SetDecorated(bool enabled) From 17a6ded94a6725a0d812b704c4eabe6a9f084e03 Mon Sep 17 00:00:00 2001 From: emerycp Date: Tue, 1 Aug 2023 19:42:19 -0400 Subject: [PATCH 5/6] NK-92 Removed Forgotten Comments --- Editor/src/Windows/FileSystemUI.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 1bce4aa3..6093e641 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -626,12 +626,6 @@ namespace Nuake if (ImGui::InputTextEx("##Search", "Asset search & filter ..", buffer, sizeof(buffer), ImVec2(ImGui::GetContentRegionAvail().x, 24), ImGuiInputTextFlags_EscapeClearsAll)) { m_searchKeyWord = std::string(buffer); - // FileSystem::FilteredFiles = FileSystem::SearchFilesWithKeyword(m_searchKeyWord, FileSystem::RootDirectory->fullPath); - // if(m_searchKeyWord.empty()) - // { - // FileSystem::FilteredFiles.clear(); - // } - //RefreshFileBrowser(); } ImGui::EndChild(); From 276fc764b27af2aa036a1194b9f7b4f21f0f8b26 Mon Sep 17 00:00:00 2001 From: emerycp Date: Wed, 2 Aug 2023 08:40:16 -0400 Subject: [PATCH 6/6] NK-92 PR Comments --- Editor/src/Windows/FileSystemUI.cpp | 2 -- Nuake/src/Core/String.cpp | 3 ++- Nuake/src/Window.cpp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 6093e641..713d3a83 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -384,7 +384,6 @@ namespace Nuake ImGui::Text(file->GetName().c_str()); ImGui::PopFont(); - } bool Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size = -1.0f) @@ -610,7 +609,6 @@ namespace Nuake ImGui::SameLine(); ImGui::Text("/"); } - ImGui::EndChild(); ImGui::PopStyleVar(); diff --git a/Nuake/src/Core/String.cpp b/Nuake/src/Core/String.cpp index cd68caf7..db6be8a3 100644 --- a/Nuake/src/Core/String.cpp +++ b/Nuake/src/Core/String.cpp @@ -37,7 +37,8 @@ namespace Nuake return result; } - std::string String::Sanitize(const std::string& keyword) { + std::string String::Sanitize(const std::string& keyword) + { std::string sanitizedKeyword = keyword; // Remove spaces, underscores, and hyphens using regex diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index 97f38215..5bc39d31 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -248,7 +248,7 @@ namespace Nuake void Window::SetVSync(bool enabled) { - glfwSwapInterval(enabled ? 1: 0); + glfwSwapInterval(enabled ? 1 : 0); } void Window::SetDecorated(bool enabled)