mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
NK-92 - Search Bar In Filebrowser
This commit is contained in:
@@ -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<Ref<Directory>> paths = std::vector<Ref<Directory>>();
|
||||
|
||||
Ref<Directory> 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<Directory>& 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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,6 @@ namespace Nuake
|
||||
std::string FileSystem::Root = "";
|
||||
|
||||
Ref<Directory> FileSystem::RootDirectory;
|
||||
std::vector<std::filesystem::path> FileSystem::FilteredDirectories;
|
||||
|
||||
void FileSystem::ScanDirectory(Ref<Directory> 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<File> newFile = CreateRef<File>(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<File> newFile = CreateRef<File>(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<std::filesystem::path> FileSystem::SearchFilesWithKeyword(const std::string& keyword, const std::string& directory) {
|
||||
std::vector<std::filesystem::path> 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace Nuake
|
||||
static std::string Root;
|
||||
|
||||
static Ref<Directory> RootDirectory;
|
||||
static std::vector<std::filesystem::path> FilteredDirectories;
|
||||
|
||||
static void SetRootDirectory(const std::string path);
|
||||
|
||||
@@ -35,7 +34,6 @@ namespace Nuake
|
||||
static Ref<Directory> GetFileTree();
|
||||
static Ref<File> GetFile(const std::string& path);
|
||||
static std::string GetFileNameFromPath(const std::string& path);
|
||||
static std::vector<std::filesystem::path> FileSystem::SearchFilesWithKeyword(const std::string& keyword, const std::string& directory);
|
||||
static void ScanDirectory(Ref<Directory> directory);
|
||||
static void GetDirectories();
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user