From 1480fff5e633d9a2d0c8cb1efb2fd517e2c25a99 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 24 Sep 2021 19:00:02 +0300 Subject: Bookmarks: Export page uses folders --- src/bookmarks.c | 42 ++++++++++++++++++++++++++++++++++-------- src/bookmarks.h | 1 + 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/bookmarks.c b/src/bookmarks.c index f7691655..35e16d9a 100644 --- a/src/bookmarks.c +++ b/src/bookmarks.c @@ -462,6 +462,16 @@ const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksCompareFunc cmp, return list; } +size_t count_Bookmarks(const iBookmarks *d) { + size_t n = 0; + iConstForEach(Hash, i, &d->bookmarks) { + if (!isFolder_Bookmark((const iBookmark *) i.value)) { + n++; + } + } + return n; +} + const iString *bookmarkListPage_Bookmarks(const iBookmarks *d, enum iBookmarkListType listType) { iString *str = collectNew_String(); lock_Mutex(d->mtx); @@ -474,21 +484,37 @@ const iString *bookmarkListPage_Bookmarks(const iBookmarks *d, enum iBookmarkLis appendFormat_String(str, "%s\n\n" "${bookmark.export.saving}\n\n", - formatCStrs_Lang("bookmark.export.count.n", size_Hash(&d->bookmarks))); + formatCStrs_Lang("bookmark.export.count.n", count_Bookmarks(d))); } else if (listType == listByTag_BookmarkListType) { appendFormat_String(str, "${bookmark.export.taginfo}\n\n"); } iStringSet *tags = new_StringSet(); - const iPtrArray *bmList = list_Bookmarks(d, - listType == listByCreationTime_BookmarkListType - ? cmpTimeDescending_Bookmark_ - : cmpTitleAscending_Bookmark, - NULL, - NULL); + const iPtrArray *bmList = + list_Bookmarks(d, + listType == listByCreationTime_BookmarkListType ? cmpTimeDescending_Bookmark_ + : listType == listByTag_BookmarkListType ? cmpTitleAscending_Bookmark + : cmpTree_Bookmark, + NULL, NULL); + if (listType == listByFolder_BookmarkListType) { + iConstForEach(PtrArray, i, bmList) { + const iBookmark *bm = i.ptr; + if (!isFolder_Bookmark(bm) && !bm->parentId) { + appendFormat_String(str, "=> %s %s\n", cstr_String(&bm->url), cstr_String(&bm->title)); + } + } + } iConstForEach(PtrArray, i, bmList) { const iBookmark *bm = i.ptr; - if (listType == listByFolder_BookmarkListType) { + if (isFolder_Bookmark(bm)) { + if (listType == listByFolder_BookmarkListType) { + const int depth = depth_Bookmark(bm); + appendFormat_String(str, "\n%s %s\n", + depth == 0 ? "##" : "###", cstr_String(&bm->title)); + } + continue; + } + if (listType == listByFolder_BookmarkListType && bm->parentId) { appendFormat_String(str, "=> %s %s\n", cstr_String(&bm->url), cstr_String(&bm->title)); } else if (listType == listByCreationTime_BookmarkListType) { diff --git a/src/bookmarks.h b/src/bookmarks.h index 40170062..61a5c102 100644 --- a/src/bookmarks.h +++ b/src/bookmarks.h @@ -56,6 +56,7 @@ struct Impl_Bookmark { iLocalDef uint32_t id_Bookmark (const iBookmark *d) { return d->node.key; } iLocalDef iBool isFolder_Bookmark (const iBookmark *d) { return isEmpty_String(&d->url); } +int depth_Bookmark (const iBookmark *); iBool hasTag_Bookmark (const iBookmark *, const char *tag); void addTag_Bookmark (iBookmark *, const char *tag); void removeTag_Bookmark (iBookmark *, const char *tag); -- cgit v1.2.3