bookmarks, part 1

This commit is contained in:
tildearrow 2025-09-29 19:42:24 -05:00
parent 826c34ecc6
commit 35d61082f5
3 changed files with 124 additions and 7 deletions

View file

@ -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<bookmarks.size(); i++) {
size_t separator=bookmarks[i].find('\n');
if (separator==String::npos) continue;
String iName=bookmarks[i].substr(0,separator);
String iPath=bookmarks[i].substr(separator+1);
if (iPath==path) {
bookmarks.erase(bookmarks.begin()+i);
break;
}
}
isPathBookmarked=false;
} else {
addBookmark(path);
}
showBookmarks=true;
}
ImGui::SameLine();
if (ImGui::Button(ICON_FA_COG "##Settings")) {
}
if (ImGui::BeginPopupContextItem("FilePickerSettings",ImGuiPopupFlags_MouseButtonLeft)) {
ImGui::Checkbox("Show bookmarks",&showBookmarks);
if (ImGui::Checkbox("Show hidden files",&showHiddenFiles)) {
scheduledSort=1;
}
@ -1108,9 +1214,16 @@ bool FurnaceFilePicker::draw(ImGuiWindowFlags winFlags) {
ImVec2 oldCellPadding=ImGui::GetStyle().CellPadding;
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding,ImVec2(oldCellPadding.x,0));
if (ImGui::BeginTable("BMPanel",2,ImGuiTableFlags_BordersInnerV|ImGuiTableFlags_Resizable)) {
ImGui::TableSetupColumn("left",ImGuiTableColumnFlags_WidthStretch,0.2f);
ImGui::TableSetupColumn("right",ImGuiTableColumnFlags_WidthStretch,0.8f);
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Here we go...");
ImVec2 bookmarksSize=tableSize;
bookmarksSize.x=ImGui::GetContentRegionAvail().x;
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding,oldCellPadding);
drawBookmarks(bookmarksSize,newDir);
ImGui::PopStyleVar();
ImGui::TableNextColumn();
tableSize.x=ImGui::GetContentRegionAvail().x;
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding,oldCellPadding);
@ -1400,6 +1513,7 @@ FilePickerStatus FurnaceFilePicker::getStatus() {
}
void FurnaceFilePicker::loadSettings(DivConfig& conf) {
showBookmarks=conf.getBool(configPrefix+"showBookmarks",true);
showHiddenFiles=conf.getBool(configPrefix+"showHiddenFiles",true);
singleClickSelect=conf.getBool(configPrefix+"singleClickSelect",false);
clearSearchOnDirChange=conf.getBool(configPrefix+"clearSearchOnDirChange",false);
@ -1411,6 +1525,7 @@ void FurnaceFilePicker::loadSettings(DivConfig& conf) {
}
void FurnaceFilePicker::saveSettings(DivConfig& conf) {
conf.set(configPrefix+"showBookmarks",showBookmarks);
conf.set(configPrefix+"showHiddenFiles",showHiddenFiles);
conf.set(configPrefix+"singleClickSelect",singleClickSelect);
conf.set(configPrefix+"clearSearchOnDirChange",clearSearchOnDirChange);
@ -1470,12 +1585,13 @@ FurnaceFilePicker::FurnaceFilePicker():
isModal(false),
isEmbed(false),
hasSizeConstraints(false),
showBookmarks(false),
isPathBookmarked(false),
scheduledSort(0),
curFilterType(0),
sortMode(FP_SORT_NAME),
curStatus(FP_STATUS_WAITING),
editingPath(false),
showBookmarks(true),
showHiddenFiles(true),
singleClickSelect(false),
clearSearchOnDirChange(false),

View file

@ -110,7 +110,7 @@ class FurnaceFilePicker {
bool sortInvert[FP_SORT_MAX];
bool multiSelect;
bool confirmOverwrite, dirSelect, noClose, isModal, isEmbed, hasSizeConstraints;
bool showBookmarks;
bool isPathBookmarked;
int scheduledSort, imguiFlags;
size_t curFilterType;
SortModes sortMode;
@ -129,6 +129,7 @@ class FurnaceFilePicker {
// configuration
String configPrefix;
std::vector<String> bookmarks;
bool showBookmarks;
bool showHiddenFiles;
bool singleClickSelect;
bool clearSearchOnDirChange;
@ -142,8 +143,10 @@ class FurnaceFilePicker {
void readDirectory(String path);
String normalizePath(const String& which);
bool isPathAbsolute(const String& p);
void addBookmark(const String& p);
void drawFileList(ImVec2& tableSize, bool& acknowledged);
void drawBookmarks(ImVec2& tableSize, String& newDir);
public:
void readDirectorySub();

View file

@ -6178,8 +6178,6 @@ void FurnaceGUI::popWarningColor() {
}
}
#define IGFD_FileStyleByExtension IGFD_FileStyleByExtention
#ifdef _WIN32
#define SYSTEM_FONT_PATH_1 "C:\\Windows\\Fonts\\segoeui.ttf"
#define SYSTEM_FONT_PATH_2 "C:\\Windows\\Fonts\\tahoma.ttf"