mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-04 11:35:06 +03:00
Merge pull request #55 from antopilo/feature/NK-92-search-bar-in-filebrowser
Feature/nk-92 search bar in filebrowser
This commit is contained in:
@@ -532,8 +532,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,12 +579,13 @@ namespace Nuake
|
||||
}
|
||||
|
||||
const uint32_t numButtonAfterPathBrowser = 2;
|
||||
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())
|
||||
@@ -610,13 +609,23 @@ 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);
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
@@ -633,8 +642,9 @@ namespace Nuake
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor(); // Button color
|
||||
|
||||
ImGui::SameLine();
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
||||
@@ -668,13 +678,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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -682,13 +695,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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Nuake {
|
||||
public:
|
||||
static Ref<Directory> m_CurrentDirectory;
|
||||
bool m_hasClickedOnFile;
|
||||
std::string m_searchKeyWord;
|
||||
|
||||
FileSystemUI(EditorInterface* editor)
|
||||
{
|
||||
|
||||
@@ -70,19 +70,15 @@ namespace Nuake
|
||||
|
||||
newDir->Parent = directory;
|
||||
ScanDirectory(newDir);
|
||||
|
||||
directory->Directories.push_back(newDir);
|
||||
}
|
||||
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();
|
||||
std::filesystem::path currentPath = entry.path();
|
||||
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);
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "String.h"
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
|
||||
namespace Nuake
|
||||
@@ -36,6 +37,19 @@ 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<std::string> String::Split(const std::string& string, char delimiter)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
|
||||
@@ -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<std::string> Split(const std::string& string, char delimiter);
|
||||
|
||||
static float ToFloat(const std::string& string);
|
||||
|
||||
@@ -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