diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks.c | 17 | ||||
-rw-r--r-- | src/bookmarks.h | 3 | ||||
-rw-r--r-- | src/ui/sidebarwidget.c | 44 |
3 files changed, 51 insertions, 13 deletions
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 | } |