diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-24 22:52:13 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-24 22:52:13 +0300 |
commit | de976d7d8bcfcb7bcc1436e215a8713aefbf091f (patch) | |
tree | 3ae409c022b5120e5e40d883316156d46908f471 | |
parent | 030b535d831a8abf4a73d4e36f3f63adb07fff03 (diff) |
Bookmarks: Deleting a tree of bookmarks
Sidebar asks for confirmation when deleting a folder hierarchy of bookmarks.
-rw-r--r-- | po/en.po | 15 | ||||
-rw-r--r-- | res/lang/de.bin | bin | 24591 -> 24641 bytes | |||
-rw-r--r-- | res/lang/en.bin | bin | 23192 -> 23514 bytes | |||
-rw-r--r-- | res/lang/es.bin | bin | 25722 -> 25772 bytes | |||
-rw-r--r-- | res/lang/fi.bin | bin | 25727 -> 25777 bytes | |||
-rw-r--r-- | res/lang/fr.bin | bin | 26696 -> 26746 bytes | |||
-rw-r--r-- | res/lang/ia.bin | bin | 25319 -> 25369 bytes | |||
-rw-r--r-- | res/lang/ie.bin | bin | 25081 -> 25131 bytes | |||
-rw-r--r-- | res/lang/pl.bin | bin | 26252 -> 26302 bytes | |||
-rw-r--r-- | res/lang/ru.bin | bin | 37978 -> 38028 bytes | |||
-rw-r--r-- | res/lang/sr.bin | bin | 37635 -> 37685 bytes | |||
-rw-r--r-- | res/lang/tok.bin | bin | 23517 -> 23567 bytes | |||
-rw-r--r-- | res/lang/zh_Hans.bin | bin | 22271 -> 22321 bytes | |||
-rw-r--r-- | res/lang/zh_Hant.bin | bin | 22456 -> 22506 bytes | |||
-rw-r--r-- | src/bookmarks.c | 17 | ||||
-rw-r--r-- | src/bookmarks.h | 3 | ||||
-rw-r--r-- | src/ui/sidebarwidget.c | 44 |
17 files changed, 66 insertions, 13 deletions
@@ -532,6 +532,21 @@ msgstr "Do you really want to erase the history of all visited pages?" | |||
532 | msgid "dlg.history.clear" | 532 | msgid "dlg.history.clear" |
533 | msgstr "Clear History" | 533 | msgstr "Clear History" |
534 | 534 | ||
535 | msgid "heading.confirm.bookmarks.delete" | ||
536 | msgstr "DELETE BOOKMARKS" | ||
537 | |||
538 | #, c-format | ||
539 | msgid "dlg.confirm.bookmarks.delete" | ||
540 | msgid_plural "dlg.confirm.bookmarks.delete.n" | ||
541 | msgstr[0] "Do you really want to delete the bookmark inside this folder?" | ||
542 | msgstr[1] "Do you really want to delete all %u bookmarks inside this folder?" | ||
543 | |||
544 | #, c-format | ||
545 | msgid "dlg.bookmarks.delete" | ||
546 | msgid_plural "dlg.bookmarks.delete.n" | ||
547 | msgstr[0] "Delete Bookmark" | ||
548 | msgstr[1] "Delete %u Bookmarks" | ||
549 | |||
535 | msgid "bookmark.tag.home" | 550 | msgid "bookmark.tag.home" |
536 | msgstr "Use as Homepage" | 551 | msgstr "Use as Homepage" |
537 | 552 | ||
diff --git a/res/lang/de.bin b/res/lang/de.bin index 4d48c61f..0d63824a 100644 --- a/res/lang/de.bin +++ b/res/lang/de.bin | |||
Binary files differ | |||
diff --git a/res/lang/en.bin b/res/lang/en.bin index 8782920f..ef09f624 100644 --- a/res/lang/en.bin +++ b/res/lang/en.bin | |||
Binary files differ | |||
diff --git a/res/lang/es.bin b/res/lang/es.bin index fa86ea3a..a45af687 100644 --- a/res/lang/es.bin +++ b/res/lang/es.bin | |||
Binary files differ | |||
diff --git a/res/lang/fi.bin b/res/lang/fi.bin index f23cbf09..404c34cd 100644 --- a/res/lang/fi.bin +++ b/res/lang/fi.bin | |||
Binary files differ | |||
diff --git a/res/lang/fr.bin b/res/lang/fr.bin index d4c5cf55..e7a5e71d 100644 --- a/res/lang/fr.bin +++ b/res/lang/fr.bin | |||
Binary files differ | |||
diff --git a/res/lang/ia.bin b/res/lang/ia.bin index ee6533ca..ef2c8ca8 100644 --- a/res/lang/ia.bin +++ b/res/lang/ia.bin | |||
Binary files differ | |||
diff --git a/res/lang/ie.bin b/res/lang/ie.bin index 2bbc7ada..2f7400d6 100644 --- a/res/lang/ie.bin +++ b/res/lang/ie.bin | |||
Binary files differ | |||
diff --git a/res/lang/pl.bin b/res/lang/pl.bin index 651a6231..1325a496 100644 --- a/res/lang/pl.bin +++ b/res/lang/pl.bin | |||
Binary files differ | |||
diff --git a/res/lang/ru.bin b/res/lang/ru.bin index 1a3f7213..9d6d24de 100644 --- a/res/lang/ru.bin +++ b/res/lang/ru.bin | |||
Binary files differ | |||
diff --git a/res/lang/sr.bin b/res/lang/sr.bin index 184699f1..de8bc5b2 100644 --- a/res/lang/sr.bin +++ b/res/lang/sr.bin | |||
Binary files differ | |||
diff --git a/res/lang/tok.bin b/res/lang/tok.bin index a77aa161..e233fa63 100644 --- a/res/lang/tok.bin +++ b/res/lang/tok.bin | |||
Binary files differ | |||
diff --git a/res/lang/zh_Hans.bin b/res/lang/zh_Hans.bin index 1fe4392d..754d3a3f 100644 --- a/res/lang/zh_Hans.bin +++ b/res/lang/zh_Hans.bin | |||
Binary files differ | |||
diff --git a/res/lang/zh_Hant.bin b/res/lang/zh_Hant.bin index 244bb3a1..a8d3690d 100644 --- a/res/lang/zh_Hant.bin +++ b/res/lang/zh_Hant.bin | |||
Binary files 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) { | |||
83 | return cmpStringCase_String(&(*a)->title, &(*b)->title); | 83 | return cmpStringCase_String(&(*a)->title, &(*b)->title); |
84 | } | 84 | } |
85 | 85 | ||
86 | iBool filterInsideFolder_Bookmark(void *context, const iBookmark *bm) { | ||
87 | return hasParent_Bookmark(bm, id_Bookmark(context)); | ||
88 | } | ||
89 | |||
86 | /*----------------------------------------------------------------------------------------------*/ | 90 | /*----------------------------------------------------------------------------------------------*/ |
87 | 91 | ||
88 | static const char *oldFileName_Bookmarks_ = "bookmarks.txt"; | 92 | static const char *oldFileName_Bookmarks_ = "bookmarks.txt"; |
@@ -345,16 +349,9 @@ iBool remove_Bookmarks(iBookmarks *d, uint32_t id) { | |||
345 | lock_Mutex(d->mtx); | 349 | lock_Mutex(d->mtx); |
346 | iBookmark *bm = (iBookmark *) remove_Hash(&d->bookmarks, id); | 350 | iBookmark *bm = (iBookmark *) remove_Hash(&d->bookmarks, id); |
347 | if (bm) { | 351 | if (bm) { |
348 | /* If this is a remote source, make sure all the remote bookmarks are | 352 | /* Remove all the contained bookmarks as well. */ |
349 | removed as well. */ | 353 | iConstForEach(PtrArray, i, list_Bookmarks(d, NULL, filterInsideFolder_Bookmark, bm)) { |
350 | if (hasTag_Bookmark(bm, remoteSource_BookmarkTag)) { | 354 | delete_Bookmark((iBookmark *) remove_Hash(&d->bookmarks, id_Bookmark(i.ptr))); |
351 | iForEach(Hash, i, &d->bookmarks) { | ||
352 | iBookmark *j = (iBookmark *) i.value; | ||
353 | if (j->parentId == id_Bookmark(bm)) { | ||
354 | remove_HashIterator(&i); | ||
355 | delete_Bookmark(j); | ||
356 | } | ||
357 | } | ||
358 | } | 355 | } |
359 | delete_Bookmark(bm); | 356 | delete_Bookmark(bm); |
360 | } | 357 | } |
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 { | |||
56 | iLocalDef uint32_t id_Bookmark (const iBookmark *d) { return d->node.key; } | 56 | iLocalDef uint32_t id_Bookmark (const iBookmark *d) { return d->node.key; } |
57 | iLocalDef iBool isFolder_Bookmark (const iBookmark *d) { return isEmpty_String(&d->url); } | 57 | iLocalDef iBool isFolder_Bookmark (const iBookmark *d) { return isEmpty_String(&d->url); } |
58 | 58 | ||
59 | iBool hasParent_Bookmark (const iBookmark *, uint32_t parentId); | ||
59 | int depth_Bookmark (const iBookmark *); | 60 | int depth_Bookmark (const iBookmark *); |
60 | iBool hasTag_Bookmark (const iBookmark *, const char *tag); | 61 | iBool hasTag_Bookmark (const iBookmark *, const char *tag); |
61 | void addTag_Bookmark (iBookmark *, const char *tag); | 62 | void addTag_Bookmark (iBookmark *, const char *tag); |
@@ -78,6 +79,8 @@ iLocalDef void addOrRemoveTag_Bookmark(iBookmark *d, const char *tag, iBool add) | |||
78 | int cmpTitleAscending_Bookmark (const iBookmark **, const iBookmark **); | 79 | int cmpTitleAscending_Bookmark (const iBookmark **, const iBookmark **); |
79 | int cmpTree_Bookmark (const iBookmark **, const iBookmark **); | 80 | int cmpTree_Bookmark (const iBookmark **, const iBookmark **); |
80 | 81 | ||
82 | iBool filterInsideFolder_Bookmark (void *parentFolder, const iBookmark *); | ||
83 | |||
81 | /*----------------------------------------------------------------------------------------------*/ | 84 | /*----------------------------------------------------------------------------------------------*/ |
82 | 85 | ||
83 | iDeclareType(Bookmarks) | 86 | 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 | |||
1111 | postCommand_App("bookmarks.changed"); | 1111 | postCommand_App("bookmarks.changed"); |
1112 | } | 1112 | } |
1113 | 1113 | ||
1114 | static size_t numBookmarks_(const iPtrArray *bmList) { | ||
1115 | size_t num = 0; | ||
1116 | iConstForEach(PtrArray, i, bmList) { | ||
1117 | if (!isFolder_Bookmark(i.ptr) && !hasTag_Bookmark(i.ptr, remote_BookmarkTag)) { | ||
1118 | num++; | ||
1119 | } | ||
1120 | } | ||
1121 | return num; | ||
1122 | } | ||
1123 | |||
1114 | static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) { | 1124 | static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) { |
1115 | iWidget *w = as_Widget(d); | 1125 | iWidget *w = as_Widget(d); |
1116 | /* Handle commands. */ | 1126 | /* Handle commands. */ |
@@ -1313,9 +1323,37 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
1313 | } | 1323 | } |
1314 | else if (isCommand_Widget(w, ev, "bookmark.delete")) { | 1324 | else if (isCommand_Widget(w, ev, "bookmark.delete")) { |
1315 | const iSidebarItem *item = d->contextItem; | 1325 | const iSidebarItem *item = d->contextItem; |
1316 | if (d->mode == bookmarks_SidebarMode && item && remove_Bookmarks(bookmarks_App(), item->id)) { | 1326 | if (d->mode == bookmarks_SidebarMode && item) { |
1317 | removeEntries_Feeds(item->id); | 1327 | iBookmark *bm = get_Bookmarks(bookmarks_App(), item->id); |
1318 | postCommand_App("bookmarks.changed"); | 1328 | if (isFolder_Bookmark(bm)) { |
1329 | const iPtrArray *list = list_Bookmarks(bookmarks_App(), NULL, | ||
1330 | filterInsideFolder_Bookmark, bm); | ||
1331 | if (argLabel_Command(cmd, "confirmed") || isEmpty_PtrArray(list)) { | ||
1332 | iConstForEach(PtrArray, i, list) { | ||
1333 | removeEntries_Feeds(id_Bookmark(i.ptr)); | ||
1334 | } | ||
1335 | remove_Bookmarks(bookmarks_App(), item->id); | ||
1336 | postCommand_App("bookmarks.changed"); | ||
1337 | } | ||
1338 | else { | ||
1339 | const size_t numBookmarks = numBookmarks_(list); | ||
1340 | makeQuestion_Widget(uiHeading_ColorEscape "${heading.confirm.bookmarks.delete}", | ||
1341 | formatCStrs_Lang("dlg.confirm.bookmarks.delete.n", numBookmarks), | ||
1342 | (iMenuItem[]){ | ||
1343 | { "${cancel}" }, | ||
1344 | { format_CStr(uiTextCaution_ColorEscape "%s", | ||
1345 | formatCStrs_Lang("dlg.bookmarks.delete.n", numBookmarks)), | ||
1346 | 0, 0, format_CStr("!bookmark.delete confirmed:1 ptr:%p", d) }, | ||
1347 | }, 2); | ||
1348 | } | ||
1349 | } | ||
1350 | else { | ||
1351 | /* TODO: Move it to a Trash folder? */ | ||
1352 | if (remove_Bookmarks(bookmarks_App(), item->id)) { | ||
1353 | removeEntries_Feeds(item->id); | ||
1354 | postCommand_App("bookmarks.changed"); | ||
1355 | } | ||
1356 | } | ||
1319 | } | 1357 | } |
1320 | return iTrue; | 1358 | return iTrue; |
1321 | } | 1359 | } |