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();