From be3f7a9ec1854ca35f031fd0ae70e73f39ea42eb Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 21 Sep 2025 17:45:06 -0500 Subject: [PATCH] new file picker, part 2 working stat --- src/gui/gui.cpp | 2 + src/gui/newFilePicker.cpp | 92 +++++++++++++++++++++++++++++---------- src/gui/newFilePicker.h | 7 +++ 3 files changed, 78 insertions(+), 23 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 1a3186e2e..12afd63a6 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -4944,6 +4944,8 @@ bool FurnaceGUI::loop() { MEASURE(effectList,drawEffectList()); MEASURE(userPresets,drawUserPresets()); MEASURE(patManager,drawPatManager()); + + newFilePicker->draw(); } else { globalWinFlags=0; ImGui::DockSpaceOverViewport(0,NULL,lockLayout?(ImGuiDockNodeFlags_NoWindowMenuButton|ImGuiDockNodeFlags_NoMove|ImGuiDockNodeFlags_NoResize|ImGuiDockNodeFlags_NoCloseButton|ImGuiDockNodeFlags_NoDocking|ImGuiDockNodeFlags_NoDockingSplit|ImGuiDockNodeFlags_NoDockingSplitOther):0); diff --git a/src/gui/newFilePicker.cpp b/src/gui/newFilePicker.cpp index 93ece73be..b7b0faeb5 100644 --- a/src/gui/newFilePicker.cpp +++ b/src/gui/newFilePicker.cpp @@ -21,9 +21,11 @@ // this will eventually replace ImGuiFileDialog as the built-in file picker. #include "newFilePicker.h" -#include "imgui.h" #include #include +#include +#include +#include static void _fileThread(void* item) { ((FurnaceFilePicker*)item)->readDirectorySub(); @@ -68,6 +70,9 @@ void FurnaceFilePicker::readDirectorySub() { } entries.push_back(newEntry); + if (stopReading) { + break; + } } if (closedir(dir)!=0) { // ?! @@ -77,7 +82,33 @@ void FurnaceFilePicker::readDirectorySub() { haveFiles=true; /// STAGE 2: retrieve file information + struct stat st; + String filePath; + for (FileEntry* i: entries) { + if (stopReading) { + return; + } + if (*path.rbegin()=='/') { + filePath=path+i->name; + } else { + filePath=path+'/'+i->name; + } + + if (stat(filePath.c_str(),&st)<0) { + // fall back to unknown + continue; + } + + // read file information + struct tm* retTM=localtime_r(&st.st_mtime,&i->time); + if (retTM!=NULL) { + i->hasTime=true; + } + + i->size=st.st_size; + i->hasSize=true; + } haveStat=true; } @@ -137,32 +168,47 @@ bool FurnaceFilePicker::draw() { ImGui::Text("Could not load this directory!\n(%s)",failMessage.c_str()); } } else { - if (ImGui::BeginTable("FileList",3,ImGuiTableFlags_Borders)) { + if (ImGui::BeginTable("FileList",3,ImGuiTableFlags_Borders|ImGuiTableFlags_ScrollY)) { entryLock.lock(); int index=0; - for (FileEntry* i: entries) { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - if (i->type==FP_TYPE_DIR) { - ImGui::PushStyleColor(ImGuiCol_Text,0xff00ffff); - } - ImGui::PushID(index++); - if (ImGui::Selectable("##File",false)) { - if (i->type==FP_TYPE_DIR || i->type==FP_TYPE_LINK) { - if (*path.rbegin()=='/') { - newDir=path+i->name; - } else { - newDir=path+'/'+i->name; + listClipper.Begin(entries.size()); + while (listClipper.Step()) { + for (int _i=listClipper.DisplayStart; _itype==FP_TYPE_DIR) { + ImGui::PushStyleColor(ImGuiCol_Text,0xff00ffff); + } + ImGui::PushID(index++); + if (ImGui::Selectable("##File",false)) { + if (i->type==FP_TYPE_DIR || i->type==FP_TYPE_LINK) { + if (*path.rbegin()=='/') { + newDir=path+i->name; + } else { + newDir=path+'/'+i->name; + } } } - } - ImGui::PopID(); - ImGui::SameLine(); - - ImGui::TextUnformatted(i->name.c_str()); + ImGui::PopID(); + ImGui::SameLine(); + + ImGui::TextUnformatted(i->name.c_str()); - if (i->type==FP_TYPE_DIR) { - ImGui::PopStyleColor(); + ImGui::TableNextColumn(); + if (i->hasSize) { + ImGui::Text("%" PRIu64,i->size); + } + + ImGui::TableNextColumn(); + if (i->hasTime) { + ImGui::Text("%d/%02d/%02d %02d:%02d",i->time.tm_year+1900,i->time.tm_mon+1,i->time.tm_mday,i->time.tm_hour,i->time.tm_min); + } + + if (i->type==FP_TYPE_DIR) { + ImGui::PopStyleColor(); + } } } ImGui::EndTable(); @@ -196,4 +242,4 @@ FurnaceFilePicker::FurnaceFilePicker(): stopReading(false), isOpen(false) { -} \ No newline at end of file +} diff --git a/src/gui/newFilePicker.h b/src/gui/newFilePicker.h index ad9285d3a..76f5376bc 100644 --- a/src/gui/newFilePicker.h +++ b/src/gui/newFilePicker.h @@ -18,7 +18,9 @@ */ #include "../ta-utils.h" +#include #include +#include "imgui.h" class FurnaceFilePicker { enum FileType { @@ -33,9 +35,13 @@ class FurnaceFilePicker { String path; String name; String ext; + bool hasSize, hasTime; uint64_t size; struct tm time; FileType type; + FileEntry(): + hasSize(false), hasTime(false), + size(0), type(FP_TYPE_UNKNOWN) {} }; std::vector entries; std::vector sortedEntries; @@ -44,6 +50,7 @@ class FurnaceFilePicker { String windowName; String path; String failMessage; + ImGuiListClipper listClipper; bool haveFiles, haveStat, stopReading, isOpen; void clearAllFiles();