bookmarks, part 2

This commit is contained in:
tildearrow 2025-10-01 13:32:33 -05:00
parent 919ff4a9d2
commit 8fbfef94cf
2 changed files with 39 additions and 10 deletions

View file

@ -601,7 +601,7 @@ bool FurnaceFilePicker::isPathAbsolute(const String& p) {
#endif
}
void FurnaceFilePicker::addBookmark(const String& p) {
void FurnaceFilePicker::addBookmark(const String& p, String n) {
if (p==path) isPathBookmarked=true;
for (String& i: bookmarks) {
size_t separator=i.find('\n');
@ -611,15 +611,23 @@ void FurnaceFilePicker::addBookmark(const String& p) {
if (p==iPath) return;
}
size_t lastSep=p.rfind(DIR_SEPARATOR);
if (lastSep==String::npos) {
String name=p;
name+="\n";
name+=p;
if (n.empty()) {
size_t lastSep=p.rfind(DIR_SEPARATOR);
if (lastSep==String::npos) {
String name=p;
name+="\n";
name+=p;
bookmarks.push_back(name);
bookmarks.push_back(name);
} else {
String name=p.substr(lastSep+1);
name+="\n";
name+=p;
bookmarks.push_back(name);
}
} else {
String name=p.substr(lastSep+1);
String name=n;
name+="\n";
name+=p;
@ -899,9 +907,27 @@ void FurnaceFilePicker::drawBookmarks(ImVec2& tableSize, String& newDir) {
ImGui::SameLine();
float iconSize=ImGui::CalcTextSize(ICON_FA_PLUS).x;
if (ImGui::Selectable(ICON_FA_PLUS "##AddBookmark",false,0,ImVec2(iconSize,0))) {
newBookmarkName="New Bookmark";
newBookmarkPath=path;
}
if (ImGui::BeginPopupContextItem("NewBookmark",ImGuiPopupFlags_MouseButtonLeft)) {
ImGui::Text("UI for new bookmark here...");
ImGui::Text("Name");
ImGui::InputText("##NameI",&newBookmarkName);
ImGui::Text("Path:");
ImGui::InputText("##PathI",&newBookmarkPath);
ImGui::BeginDisabled(newBookmarkName.empty() || newBookmarkPath.empty());
if (ImGui::Button("OK")) {
if (newBookmarkName.empty() || newBookmarkPath.empty()) {
// no!
} else {
newBookmarkPath=normalizePath(newBookmarkPath);
addBookmark(newBookmarkPath,newBookmarkName);
}
ImGui::CloseCurrentPopup();
}
ImGui::EndDisabled();
ImGui::EndPopup();
}
ImGui::SameLine();

View file

@ -122,6 +122,9 @@ class FurnaceFilePicker {
// for "create directory"
String mkdirPath, mkdirError;
// for "create bookmark"
String newBookmarkName, newBookmarkPath;
// for the "edit path" button
String editablePath;
bool editingPath;
@ -143,7 +146,7 @@ class FurnaceFilePicker {
void readDirectory(String path);
String normalizePath(const String& which);
bool isPathAbsolute(const String& p);
void addBookmark(const String& p);
void addBookmark(const String& p, String n="");
void drawFileList(ImVec2& tableSize, bool& acknowledged);
void drawBookmarks(ImVec2& tableSize, String& newDir);