From de976d7d8bcfcb7bcc1436e215a8713aefbf091f Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 24 Sep 2021 22:52:13 +0300 Subject: Bookmarks: Deleting a tree of bookmarks Sidebar asks for confirmation when deleting a folder hierarchy of bookmarks. --- po/en.po | 15 +++++++++++++++ res/lang/de.bin | Bin 24591 -> 24641 bytes res/lang/en.bin | Bin 23192 -> 23514 bytes res/lang/es.bin | Bin 25722 -> 25772 bytes res/lang/fi.bin | Bin 25727 -> 25777 bytes res/lang/fr.bin | Bin 26696 -> 26746 bytes res/lang/ia.bin | Bin 25319 -> 25369 bytes res/lang/ie.bin | Bin 25081 -> 25131 bytes res/lang/pl.bin | Bin 26252 -> 26302 bytes res/lang/ru.bin | Bin 37978 -> 38028 bytes res/lang/sr.bin | Bin 37635 -> 37685 bytes res/lang/tok.bin | Bin 23517 -> 23567 bytes res/lang/zh_Hans.bin | Bin 22271 -> 22321 bytes res/lang/zh_Hant.bin | Bin 22456 -> 22506 bytes src/bookmarks.c | 17 +++++++---------- src/bookmarks.h | 3 +++ src/ui/sidebarwidget.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 17 files changed, 66 insertions(+), 13 deletions(-) diff --git a/po/en.po b/po/en.po index 24525b03..24ca12a3 100644 --- a/po/en.po +++ b/po/en.po @@ -532,6 +532,21 @@ msgstr "Do you really want to erase the history of all visited pages?" msgid "dlg.history.clear" msgstr "Clear History" +msgid "heading.confirm.bookmarks.delete" +msgstr "DELETE BOOKMARKS" + +#, c-format +msgid "dlg.confirm.bookmarks.delete" +msgid_plural "dlg.confirm.bookmarks.delete.n" +msgstr[0] "Do you really want to delete the bookmark inside this folder?" +msgstr[1] "Do you really want to delete all %u bookmarks inside this folder?" + +#, c-format +msgid "dlg.bookmarks.delete" +msgid_plural "dlg.bookmarks.delete.n" +msgstr[0] "Delete Bookmark" +msgstr[1] "Delete %u Bookmarks" + msgid "bookmark.tag.home" msgstr "Use as Homepage" diff --git a/res/lang/de.bin b/res/lang/de.bin index 4d48c61f..0d63824a 100644 Binary files a/res/lang/de.bin and b/res/lang/de.bin differ diff --git a/res/lang/en.bin b/res/lang/en.bin index 8782920f..ef09f624 100644 Binary files a/res/lang/en.bin and b/res/lang/en.bin differ diff --git a/res/lang/es.bin b/res/lang/es.bin index fa86ea3a..a45af687 100644 Binary files a/res/lang/es.bin and b/res/lang/es.bin differ diff --git a/res/lang/fi.bin b/res/lang/fi.bin index f23cbf09..404c34cd 100644 Binary files a/res/lang/fi.bin and b/res/lang/fi.bin differ diff --git a/res/lang/fr.bin b/res/lang/fr.bin index d4c5cf55..e7a5e71d 100644 Binary files a/res/lang/fr.bin and b/res/lang/fr.bin differ diff --git a/res/lang/ia.bin b/res/lang/ia.bin index ee6533ca..ef2c8ca8 100644 Binary files a/res/lang/ia.bin and b/res/lang/ia.bin differ diff --git a/res/lang/ie.bin b/res/lang/ie.bin index 2bbc7ada..2f7400d6 100644 Binary files a/res/lang/ie.bin and b/res/lang/ie.bin differ diff --git a/res/lang/pl.bin b/res/lang/pl.bin index 651a6231..1325a496 100644 Binary files a/res/lang/pl.bin and b/res/lang/pl.bin differ diff --git a/res/lang/ru.bin b/res/lang/ru.bin index 1a3f7213..9d6d24de 100644 Binary files a/res/lang/ru.bin and b/res/lang/ru.bin differ diff --git a/res/lang/sr.bin b/res/lang/sr.bin index 184699f1..de8bc5b2 100644 Binary files a/res/lang/sr.bin and b/res/lang/sr.bin differ diff --git a/res/lang/tok.bin b/res/lang/tok.bin index a77aa161..e233fa63 100644 Binary files a/res/lang/tok.bin and b/res/lang/tok.bin differ diff --git a/res/lang/zh_Hans.bin b/res/lang/zh_Hans.bin index 1fe4392d..754d3a3f 100644 Binary files a/res/lang/zh_Hans.bin and b/res/lang/zh_Hans.bin differ diff --git a/res/lang/zh_Hant.bin b/res/lang/zh_Hant.bin index 244bb3a1..a8d3690d 100644 Binary files a/res/lang/zh_Hant.bin and b/res/lang/zh_Hant.bin differ diff --git a/src/bookmarks.c b/src/bookmarks.c index 35e16d9a..fe2ca47a 100644 --- a/src/bookmarks.c +++ b/src/bookmarks.c @@ -83,6 +83,10 @@ int cmpTitleAscending_Bookmark(const iBookmark **a, const iBookmark **b) { return cmpStringCase_String(&(*a)->title, &(*b)->title); } +iBool filterInsideFolder_Bookmark(void *context, const iBookmark *bm) { + return hasParent_Bookmark(bm, id_Bookmark(context)); +} + /*----------------------------------------------------------------------------------------------*/ static const char *oldFileName_Bookmarks_ = "bookmarks.txt"; @@ -345,16 +349,9 @@ iBool remove_Bookmarks(iBookmarks *d, uint32_t id) { lock_Mutex(d->mtx); iBookmark *bm = (iBookmark *) remove_Hash(&d->bookmarks, id); if (bm) { - /* If this is a remote source, make sure all the remote bookmarks are - removed as well. */ - if (hasTag_Bookmark(bm, remoteSource_BookmarkTag)) { - iForEach(Hash, i, &d->bookmarks) { - iBookmark *j = (iBookmark *) i.value; - if (j->parentId == id_Bookmark(bm)) { - remove_HashIterator(&i); - delete_Bookmark(j); - } - } + /* Remove all the contained bookmarks as well. */ + iConstForEach(PtrArray, i, list_Bookmarks(d, NULL, filterInsideFolder_Bookmark, bm)) { + delete_Bookmark((iBookmark *) remove_Hash(&d->bookmarks, id_Bookmark(i.ptr))); } delete_Bookmark(bm); } diff --git a/src/bookmarks.h b/src/bookmarks.h index 61a5c102..13501ded 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); } +iBool hasParent_Bookmark (const iBookmark *, uint32_t parentId); int depth_Bookmark (const iBookmark *); iBool hasTag_Bookmark (const iBookmark *, const char *tag); void addTag_Bookmark (iBookmark *, const char *tag); @@ -78,6 +79,8 @@ iLocalDef void addOrRemoveTag_Bookmark(iBookmark *d, const char *tag, iBool add) int cmpTitleAscending_Bookmark (const iBookmark **, const iBookmark **); int cmpTree_Bookmark (const iBookmark **, const iBookmark **); +iBool filterInsideFolder_Bookmark (void *parentFolder, const iBookmark *); + /*----------------------------------------------------------------------------------------------*/ iDeclareType(Bookmarks) diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index e8aa69c1..8e38dcb8 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -1111,6 +1111,16 @@ static void bookmarkMovedOntoFolder_SidebarWidget_(iSidebarWidget *d, size_t ind postCommand_App("bookmarks.changed"); } +static size_t numBookmarks_(const iPtrArray *bmList) { + size_t num = 0; + iConstForEach(PtrArray, i, bmList) { + if (!isFolder_Bookmark(i.ptr) && !hasTag_Bookmark(i.ptr, remote_BookmarkTag)) { + num++; + } + } + return num; +} + static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) { iWidget *w = as_Widget(d); /* Handle commands. */ @@ -1313,9 +1323,37 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) } else if (isCommand_Widget(w, ev, "bookmark.delete")) { const iSidebarItem *item = d->contextItem; - if (d->mode == bookmarks_SidebarMode && item && remove_Bookmarks(bookmarks_App(), item->id)) { - removeEntries_Feeds(item->id); - postCommand_App("bookmarks.changed"); + if (d->mode == bookmarks_SidebarMode && item) { + iBookmark *bm = get_Bookmarks(bookmarks_App(), item->id); + if (isFolder_Bookmark(bm)) { + const iPtrArray *list = list_Bookmarks(bookmarks_App(), NULL, + filterInsideFolder_Bookmark, bm); + if (argLabel_Command(cmd, "confirmed") || isEmpty_PtrArray(list)) { + iConstForEach(PtrArray, i, list) { + removeEntries_Feeds(id_Bookmark(i.ptr)); + } + remove_Bookmarks(bookmarks_App(), item->id); + postCommand_App("bookmarks.changed"); + } + else { + const size_t numBookmarks = numBookmarks_(list); + makeQuestion_Widget(uiHeading_ColorEscape "${heading.confirm.bookmarks.delete}", + formatCStrs_Lang("dlg.confirm.bookmarks.delete.n", numBookmarks), + (iMenuItem[]){ + { "${cancel}" }, + { format_CStr(uiTextCaution_ColorEscape "%s", + formatCStrs_Lang("dlg.bookmarks.delete.n", numBookmarks)), + 0, 0, format_CStr("!bookmark.delete confirmed:1 ptr:%p", d) }, + }, 2); + } + } + else { + /* TODO: Move it to a Trash folder? */ + if (remove_Bookmarks(bookmarks_App(), item->id)) { + removeEntries_Feeds(item->id); + postCommand_App("bookmarks.changed"); + } + } } return iTrue; } -- cgit v1.2.3