Update ProjectManager.cpp
This commit is contained in:
parent
c5d9985d00
commit
c95eb8e1e1
@ -153,7 +153,6 @@ void FileExplorer::Show(bool* p_open)
|
|||||||
{
|
{
|
||||||
if (!s_initialized) return;
|
if (!s_initialized) return;
|
||||||
|
|
||||||
// rebuild tree if the root changed
|
|
||||||
if (s_root != lastTreeRoot) treeDirty = true;
|
if (s_root != lastTreeRoot) treeDirty = true;
|
||||||
EnsureTreeCache(s_root);
|
EnsureTreeCache(s_root);
|
||||||
|
|
||||||
@ -164,12 +163,8 @@ void FileExplorer::Show(bool* p_open)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
// LEFT PANE: interactive folder‐tree with icons
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
ImGui::BeginChild("##FolderPane", ImVec2(250,0), true);
|
ImGui::BeginChild("##FolderPane", ImVec2(250,0), true);
|
||||||
{
|
{
|
||||||
// recursive lambda to draw each node
|
|
||||||
std::function<void(const TreeNode&)> drawNode = [&](const TreeNode& node) {
|
std::function<void(const TreeNode&)> drawNode = [&](const TreeNode& node) {
|
||||||
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow
|
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow
|
||||||
| ImGuiTreeNodeFlags_SpanAvailWidth;
|
| ImGuiTreeNodeFlags_SpanAvailWidth;
|
||||||
@ -191,14 +186,12 @@ void FileExplorer::Show(bool* p_open)
|
|||||||
label
|
label
|
||||||
);
|
);
|
||||||
|
|
||||||
// 3) click to change directory
|
|
||||||
if (ImGui::IsItemClicked()) {
|
if (ImGui::IsItemClicked()) {
|
||||||
s_currentDir = node.path;
|
s_currentDir = node.path;
|
||||||
treeDirty = true; // also force tree repaint?
|
treeDirty = true; // also force tree repaint?
|
||||||
rebuild = true; // file‐grid rebuild
|
rebuild = true; // file‐grid rebuild
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4) children
|
|
||||||
if (open) {
|
if (open) {
|
||||||
for (auto& child : node.children)
|
for (auto& child : node.children)
|
||||||
drawNode(child);
|
drawNode(child);
|
||||||
@ -212,12 +205,8 @@ void FileExplorer::Show(bool* p_open)
|
|||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
// RIGHT PANE: toolbar + file‐grid
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
ImGui::BeginChild("##ContentPane", ImVec2(0,0), false);
|
ImGui::BeginChild("##ContentPane", ImVec2(0,0), false);
|
||||||
|
|
||||||
// --- Filters / Sort / Search state (static to persist frame-to-frame) ---
|
|
||||||
static char searchBuf[256] = "";
|
static char searchBuf[256] = "";
|
||||||
static fs::path lastDir;
|
static fs::path lastDir;
|
||||||
static int lastSortMode = -1;
|
static int lastSortMode = -1;
|
||||||
@ -230,7 +219,6 @@ void FileExplorer::Show(bool* p_open)
|
|||||||
static std::string lastSearch;
|
static std::string lastSearch;
|
||||||
static bool rebuild = true;
|
static bool rebuild = true;
|
||||||
|
|
||||||
// Filters / Sort popup
|
|
||||||
if (ImGui::Button("Filters / Sort")) ImGui::OpenPopup("FileFilterPopup");
|
if (ImGui::Button("Filters / Sort")) ImGui::OpenPopup("FileFilterPopup");
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetNextItemWidth(200);
|
ImGui::SetNextItemWidth(200);
|
||||||
@ -251,7 +239,6 @@ void FileExplorer::Show(bool* p_open)
|
|||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
// “Up” button + current path display
|
|
||||||
if (s_currentDir != s_root) {
|
if (s_currentDir != s_root) {
|
||||||
if (ImGui::Button("Up")) {
|
if (ImGui::Button("Up")) {
|
||||||
s_currentDir = s_currentDir.parent_path();
|
s_currentDir = s_currentDir.parent_path();
|
||||||
@ -267,7 +254,6 @@ void FileExplorer::Show(bool* p_open)
|
|||||||
}
|
}
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
// Detect any state changes → rebuild the file‐grid cache
|
|
||||||
if ( lastDir != s_currentDir
|
if ( lastDir != s_currentDir
|
||||||
|| lastSortMode != sortMode
|
|| lastSortMode != sortMode
|
||||||
|| lastSortAsc != sortAscending
|
|| lastSortAsc != sortAscending
|
||||||
@ -298,7 +284,6 @@ void FileExplorer::Show(bool* p_open)
|
|||||||
bool isDir = e.is_directory();
|
bool isDir = e.is_directory();
|
||||||
AssetType t = AssetManager::AssetTypeFromPath(e.path().string());
|
AssetType t = AssetManager::AssetTypeFromPath(e.path().string());
|
||||||
|
|
||||||
// type filters
|
|
||||||
if (!isDir) {
|
if (!isDir) {
|
||||||
if ((t==AssetType::Scene && !showScenes )||
|
if ((t==AssetType::Scene && !showScenes )||
|
||||||
(t==AssetType::Image && !showImages )||
|
(t==AssetType::Image && !showImages )||
|
||||||
@ -308,7 +293,6 @@ void FileExplorer::Show(bool* p_open)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// search filter
|
|
||||||
if (!fileSearchQuery.empty()
|
if (!fileSearchQuery.empty()
|
||||||
&& e.path().filename().string().find(fileSearchQuery)==std::string::npos)
|
&& e.path().filename().string().find(fileSearchQuery)==std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
@ -318,7 +302,6 @@ void FileExplorer::Show(bool* p_open)
|
|||||||
ce.isDirectory = isDir;
|
ce.isDirectory = isDir;
|
||||||
ce.type = t;
|
ce.type = t;
|
||||||
|
|
||||||
// thumbnail
|
|
||||||
if (isDir) {
|
if (isDir) {
|
||||||
ce.thumbID = (ImTextureID)(intptr_t)s_folderIcon;
|
ce.thumbID = (ImTextureID)(intptr_t)s_folderIcon;
|
||||||
}
|
}
|
||||||
@ -332,7 +315,6 @@ void FileExplorer::Show(bool* p_open)
|
|||||||
EngineLoadTextureIfNeeded(ICONS_PATH + IconFileForPath(ce.path));
|
EngineLoadTextureIfNeeded(ICONS_PATH + IconFileForPath(ce.path));
|
||||||
}
|
}
|
||||||
|
|
||||||
// label for non‐image files
|
|
||||||
if (!isDir && t!=AssetType::Image) {
|
if (!isDir && t!=AssetType::Image) {
|
||||||
static const std::unordered_map<AssetType,const char*> L = {
|
static const std::unordered_map<AssetType,const char*> L = {
|
||||||
{AssetType::Prefab,"Prefab"},
|
{AssetType::Prefab,"Prefab"},
|
||||||
@ -354,7 +336,6 @@ void FileExplorer::Show(bool* p_open)
|
|||||||
cacheEntries.push_back(std::move(ce));
|
cacheEntries.push_back(std::move(ce));
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort
|
|
||||||
std::sort(cacheEntries.begin(), cacheEntries.end(),
|
std::sort(cacheEntries.begin(), cacheEntries.end(),
|
||||||
[&](auto& a, auto& b){
|
[&](auto& a, auto& b){
|
||||||
if (sortMode==1) {
|
if (sortMode==1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user