From 6b2c6571473378ba72d9c4c774c1149e3d2c3ba9 Mon Sep 17 00:00:00 2001 From: yohannd1 Date: Tue, 20 Jan 2026 01:21:42 -0300 Subject: [PATCH] newFilePicker: refactor + fix hint bug --- src/gui/newFilePicker.cpp | 86 ++++++++++++++++----------------------- src/gui/newFilePicker.h | 3 +- 2 files changed, 36 insertions(+), 53 deletions(-) diff --git a/src/gui/newFilePicker.cpp b/src/gui/newFilePicker.cpp index 9062a82f1..1a4b9c477 100644 --- a/src/gui/newFilePicker.cpp +++ b/src/gui/newFilePicker.cpp @@ -577,9 +577,6 @@ bool FurnaceFilePicker::readDirectory(String path) { entries.clear(); chosenEntries.clear(); updateEntryName(); - if (!entryNameHint.empty()) { - entryName=entryNameHint; - } // start new file thread String newPath=normalizePath(path); @@ -619,12 +616,18 @@ void FurnaceFilePicker::setHomeDir(String where) { } void FurnaceFilePicker::updateEntryName() { - if (chosenEntries.empty()) { - entryName=""; - } else if (chosenEntries.size()>1) { - entryName=_(""); - } else { - entryName=chosenEntries[0]->name; + bool found=false; + for (int i=0; i<(int)chosenEntries.size(); i++) { + bool isDir=chosenEntries[i]->type==FP_TYPE_DIR; + if ((isDir && dirSelect) || (!isDir && !dirSelect)) { + if (found) { + entryName=_(""); + break; + } else { + entryName=chosenEntries[i]->name; + found=true; + } + } } } @@ -1053,7 +1056,7 @@ void FurnaceFilePicker::drawFileList(ImVec2& tableSize, bool& acknowledged) { } ImGui::PopID(); ImGui::SameLine(); - + // why? can't I just not format? ImGui::TextNoHashHide("%s",i->name.c_str()); @@ -1654,16 +1657,7 @@ bool FurnaceFilePicker::draw(ImGuiWindowFlags winFlags) { ImGui::OpenPopup(_("Warning###ConfirmOverwrite")); logV("confirm overwrite"); } else { - curStatus=FP_STATUS_ACCEPTED; - if (noClose) { - for (FileEntry* j: chosenEntries) { - j->isSelected=false; - } - chosenEntries.clear(); - updateEntryName(); - } else { - isOpen=false; - } + acceptAndClose(); } } } else { @@ -1746,31 +1740,13 @@ bool FurnaceFilePicker::draw(ImGuiWindowFlags winFlags) { logV("confirm overwrite"); } else { finalSelection.push_back(dirCheckPath); - curStatus=FP_STATUS_ACCEPTED; - if (noClose) { - for (FileEntry* j: chosenEntries) { - j->isSelected=false; - } - chosenEntries.clear(); - updateEntryName(); - } else { - isOpen=false; - } + acceptAndClose(); } } } else { if (dirSelect) { finalSelection.push_back(path); - curStatus=FP_STATUS_ACCEPTED; - if (noClose) { - for (FileEntry* j: chosenEntries) { - j->isSelected=false; - } - chosenEntries.clear(); - updateEntryName(); - } else { - isOpen=false; - } + acceptAndClose(); } } } @@ -1780,16 +1756,7 @@ bool FurnaceFilePicker::draw(ImGuiWindowFlags winFlags) { if (ImGui::BeginPopupModal(_("Warning###ConfirmOverwrite"),NULL,ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoSavedSettings)) { ImGui::TextUnformatted(_("The file you selected already exists! Would you like to overwrite it?")); if (ImGui::Button(_("Yes"))) { - curStatus=FP_STATUS_ACCEPTED; - if (noClose) { - for (FileEntry* j: chosenEntries) { - j->isSelected=false; - } - chosenEntries.clear(); - updateEntryName(); - } else { - isOpen=false; - } + acceptAndClose(); ImGui::CloseCurrentPopup(); } ImGui::SameLine(); @@ -1811,7 +1778,7 @@ bool FurnaceFilePicker::draw(ImGuiWindowFlags winFlags) { ImGui::End(); } } - + hasSizeConstraints=false; @@ -1872,7 +1839,9 @@ bool FurnaceFilePicker::open(String name, String pa, String hint, int flags, con enforceScrollY=2; windowName=name; } - hint=entryNameHint; + + entryName=hint.empty()?"":hint; + isOpen=true; //ImGui::GetIO().ConfigFlags|=ImGuiConfigFlags_NavEnableKeyboard; @@ -1997,3 +1966,16 @@ FurnaceFilePicker::FurnaceFilePicker(): defaultTypeStyle[i].icon=ICON_FA_QUESTION "##File"; } } + +void FurnaceFilePicker::acceptAndClose() { + curStatus=FP_STATUS_ACCEPTED; + if (noClose) { + for (FileEntry* j: chosenEntries) { + j->isSelected=false; + } + chosenEntries.clear(); + updateEntryName(); + } else { + isOpen=false; + } +} diff --git a/src/gui/newFilePicker.h b/src/gui/newFilePicker.h index 86a402a5b..0681fd362 100644 --- a/src/gui/newFilePicker.h +++ b/src/gui/newFilePicker.h @@ -106,7 +106,6 @@ class FurnaceFilePicker { String failMessage; String homeDir; String entryName; - String entryNameHint; ImGuiListClipper listClipper; ImVec2 minSize, maxSize; bool haveFiles, haveStat, stopReading, isOpen, isMobile; @@ -160,6 +159,8 @@ class FurnaceFilePicker { void drawFileList(ImVec2& tableSize, bool& acknowledged); void drawBookmarks(ImVec2& tableSize, String& newDir); + void acceptAndClose(); + public: void readDirectorySub(); void searchSub(String subPath, int depth);