From 35d61082f59d239d23c9ab3b60a96a821e18ccc5 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Mon, 29 Sep 2025 19:42:24 -0500 Subject: [PATCH] bookmarks, part 1 --- src/gui/newFilePicker.cpp | 124 ++++++++++++++++++++++++++++++++++++-- src/gui/newFilePicker.h | 5 +- src/gui/settings.cpp | 2 - 3 files changed, 124 insertions(+), 7 deletions(-) diff --git a/src/gui/newFilePicker.cpp b/src/gui/newFilePicker.cpp index eaf0ff251..f39845c36 100644 --- a/src/gui/newFilePicker.cpp +++ b/src/gui/newFilePicker.cpp @@ -408,6 +408,20 @@ void FurnaceFilePicker::readDirectory(String path) { stopReading=false; scheduledSort=1; fileThread=new std::thread(_fileThread,this); + + // check whether this path is bookmarked + isPathBookmarked=false; + for (String& i: bookmarks) { + size_t separator=i.find('\n'); + if (separator==String::npos) continue; + String iName=i.substr(0,separator); + String iPath=i.substr(separator+1); + + if (this->path==iPath) { + isPathBookmarked=true; + break; + } + } } void FurnaceFilePicker::setHomeDir(String where) { @@ -587,6 +601,32 @@ bool FurnaceFilePicker::isPathAbsolute(const String& p) { #endif } +void FurnaceFilePicker::addBookmark(const String& p) { + if (p==path) isPathBookmarked=true; + for (String& i: bookmarks) { + size_t separator=i.find('\n'); + if (separator==String::npos) continue; + String iName=i.substr(0,separator); + String iPath=i.substr(separator+1); + + if (p==iPath) return; + } + size_t lastSep=p.rfind(DIR_SEPARATOR); + if (lastSep==String::npos) { + String name=p; + name+="\n"; + name+=p; + + bookmarks.push_back(name); + } else { + String name=p.substr(lastSep+1); + name+="\n"; + name+=p; + + bookmarks.push_back(name); + } +} + void FurnaceFilePicker::setSizeConstraints(const ImVec2& min, const ImVec2& max) { minSize=min; maxSize=max; @@ -850,6 +890,55 @@ void FurnaceFilePicker::drawFileList(ImVec2& tableSize, bool& acknowledged) { } } +void FurnaceFilePicker::drawBookmarks(ImVec2& tableSize, String& newDir) { + if (ImGui::BeginTable("BookmarksList",1,ImGuiTableFlags_BordersOuter|ImGuiTableFlags_ScrollY,tableSize)) { + ImGui::TableSetupScrollFreeze(0,1); + ImGui::TableNextRow(ImGuiTableRowFlags_Headers); + ImGui::TableNextColumn(); + ImGui::Text("Bookmarks"); + ImGui::SameLine(); + float iconSize=ImGui::CalcTextSize(ICON_FA_PLUS).x; + if (ImGui::Selectable(ICON_FA_PLUS "##AddBookmark",false,0,ImVec2(iconSize,0))) { + } + if (ImGui::BeginPopupContextItem("NewBookmark",ImGuiPopupFlags_MouseButtonLeft)) { + ImGui::Text("UI for new bookmark here..."); + ImGui::EndPopup(); + } + ImGui::SameLine(); + if (ImGui::Selectable(ICON_FA_TIMES "##CloseBookmarks",false,0,ImVec2(iconSize,0))) { + showBookmarks=false; + } + + int index=-1; + int markedForRemoval=-1; + for (String& i: bookmarks) { + ++index; + size_t separator=i.find('\n'); + if (separator==String::npos) continue; + String iName=i.substr(0,separator); + String iPath=i.substr(separator+1); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::PushID(index); + if (ImGui::Selectable(iName.c_str(),iPath==path)) { + newDir=iPath; + } + if (ImGui::BeginPopupContextItem("BookmarkOpts")) { + if (ImGui::MenuItem("remove")) { + markedForRemoval=index; + if (iPath==path) isPathBookmarked=false; + } + } + ImGui::PopID(); + } + if (markedForRemoval>=0) { + bookmarks.erase(bookmarks.begin()+markedForRemoval); + } + ImGui::EndTable(); + } +} + bool FurnaceFilePicker::draw(ImGuiWindowFlags winFlags) { if (!isOpen) { hasSizeConstraints=false; @@ -1058,13 +1147,30 @@ bool FurnaceFilePicker::draw(ImGuiWindowFlags winFlags) { } // search bar - if (ImGui::Button(showBookmarks?(ICON_FA_BOOKMARK "##Bookmarks"):(ICON_FA_BOOKMARK_O "##Bookmarks"))) { - showBookmarks=!showBookmarks; + if (ImGui::Button(isPathBookmarked?(ICON_FA_BOOKMARK "##Bookmarks"):(ICON_FA_BOOKMARK_O "##Bookmarks"))) { + if (isPathBookmarked && showBookmarks) { + for (size_t i=0; i