summaryrefslogtreecommitdiff
path: root/src/ui/sidebarwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/sidebarwidget.c')
-rw-r--r--src/ui/sidebarwidget.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 8e38dcb8..3018f16d 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -108,7 +108,7 @@ struct Impl_SidebarWidget {
108 iWidget * menu; 108 iWidget * menu;
109 iSidebarItem * contextItem; /* list item accessed in the context menu */ 109 iSidebarItem * contextItem; /* list item accessed in the context menu */
110 size_t contextIndex; /* index of list item accessed in the context menu */ 110 size_t contextIndex; /* index of list item accessed in the context menu */
111 iIntSet closedFolders; /* otherwise open */ 111 iIntSet * closedFolders; /* otherwise open */
112}; 112};
113 113
114iDefineObjectConstructionArgs(SidebarWidget, (enum iSidebarSide side), side) 114iDefineObjectConstructionArgs(SidebarWidget, (enum iSidebarSide side), side)
@@ -255,7 +255,7 @@ static void updateContextMenu_SidebarWidget_(iSidebarWidget *d) {
255 255
256static iBool isBookmarkFolded_SidebarWidget_(const iSidebarWidget *d, const iBookmark *bm) { 256static iBool isBookmarkFolded_SidebarWidget_(const iSidebarWidget *d, const iBookmark *bm) {
257 while (bm->parentId) { 257 while (bm->parentId) {
258 if (contains_IntSet(&d->closedFolders, bm->parentId)) { 258 if (contains_IntSet(d->closedFolders, bm->parentId)) {
259 return iTrue; 259 return iTrue;
260 } 260 }
261 bm = get_Bookmarks(bookmarks_App(), bm->parentId); 261 bm = get_Bookmarks(bookmarks_App(), bm->parentId);
@@ -397,7 +397,7 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
397 item->id = id_Bookmark(bm); 397 item->id = id_Bookmark(bm);
398 item->indent = depth_Bookmark(bm); 398 item->indent = depth_Bookmark(bm);
399 if (isFolder_Bookmark(bm)) { 399 if (isFolder_Bookmark(bm)) {
400 item->icon = contains_IntSet(&d->closedFolders, item->id) ? 0x27e9 : 0xfe40; 400 item->icon = contains_IntSet(d->closedFolders, item->id) ? 0x27e9 : 0xfe40;
401 } 401 }
402 else { 402 else {
403 item->icon = bm->icon; 403 item->icon = bm->icon;
@@ -655,6 +655,11 @@ iBool setMode_SidebarWidget(iSidebarWidget *d, enum iSidebarMode mode) {
655 return iTrue; 655 return iTrue;
656} 656}
657 657
658void setClosedFolders_SidebarWidget(iSidebarWidget *d, const iIntSet *closedFolders) {
659 delete_IntSet(d->closedFolders);
660 d->closedFolders = copy_IntSet(closedFolders);
661}
662
658enum iSidebarMode mode_SidebarWidget(const iSidebarWidget *d) { 663enum iSidebarMode mode_SidebarWidget(const iSidebarWidget *d) {
659 return d ? d->mode : 0; 664 return d ? d->mode : 0;
660} 665}
@@ -663,6 +668,10 @@ float width_SidebarWidget(const iSidebarWidget *d) {
663 return d ? d->widthAsGaps : 0; 668 return d ? d->widthAsGaps : 0;
664} 669}
665 670
671const iIntSet *closedFolders_SidebarWidget(const iSidebarWidget *d) {
672 return d->closedFolders;
673}
674
666static const char *normalModeLabels_[max_SidebarMode] = { 675static const char *normalModeLabels_[max_SidebarMode] = {
667 book_Icon " ${sidebar.bookmarks}", 676 book_Icon " ${sidebar.bookmarks}",
668 star_Icon " ${sidebar.feeds}", 677 star_Icon " ${sidebar.feeds}",
@@ -736,7 +745,7 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) {
736 d->resizer = NULL; 745 d->resizer = NULL;
737 d->list = NULL; 746 d->list = NULL;
738 d->actions = NULL; 747 d->actions = NULL;
739 init_IntSet(&d->closedFolders); 748 d->closedFolders = new_IntSet();
740 /* On a phone, the right sidebar is used exclusively for Identities. */ 749 /* On a phone, the right sidebar is used exclusively for Identities. */
741 const iBool isPhone = deviceType_App() == phone_AppDeviceType; 750 const iBool isPhone = deviceType_App() == phone_AppDeviceType;
742 if (!isPhone || d->side == left_SidebarSide) { 751 if (!isPhone || d->side == left_SidebarSide) {
@@ -820,7 +829,7 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) {
820 829
821void deinit_SidebarWidget(iSidebarWidget *d) { 830void deinit_SidebarWidget(iSidebarWidget *d) {
822 deinit_String(&d->cmdPrefix); 831 deinit_String(&d->cmdPrefix);
823 deinit_IntSet(&d->closedFolders); 832 delete_IntSet(d->closedFolders);
824} 833}
825 834
826iBool setButtonFont_SidebarWidget(iSidebarWidget *d, int font) { 835iBool setButtonFont_SidebarWidget(iSidebarWidget *d, int font) {
@@ -869,11 +878,11 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, iSidebarItem *item, si
869 } 878 }
870 case bookmarks_SidebarMode: 879 case bookmarks_SidebarMode:
871 if (isEmpty_String(&item->url)) /* a folder */ { 880 if (isEmpty_String(&item->url)) /* a folder */ {
872 if (contains_IntSet(&d->closedFolders, item->id)) { 881 if (contains_IntSet(d->closedFolders, item->id)) {
873 remove_IntSet(&d->closedFolders, item->id); 882 remove_IntSet(d->closedFolders, item->id);
874 } 883 }
875 else { 884 else {
876 insert_IntSet(&d->closedFolders, item->id); 885 insert_IntSet(d->closedFolders, item->id);
877 } 886 }
878 updateItems_SidebarWidget_(d); 887 updateItems_SidebarWidget_(d);
879 break; 888 break;
@@ -956,8 +965,8 @@ void setWidth_SidebarWidget(iSidebarWidget *d, float widthAsGaps) {
956 int width = widthAsGaps * gap_UI; /* in pixels */ 965 int width = widthAsGaps * gap_UI; /* in pixels */
957 if (!isFixedWidth) { 966 if (!isFixedWidth) {
958 /* Even less space if the other sidebar is visible, too. */ 967 /* Even less space if the other sidebar is visible, too. */
959 const int otherWidth = 968 const iWidget *other = findWidget_App(d->side == left_SidebarSide ? "sidebar2" : "sidebar");
960 width_Widget(findWidget_App(d->side == left_SidebarSide ? "sidebar2" : "sidebar")); 969 const int otherWidth = isVisible_Widget(other) ? width_Widget(other) : 0;
961 width = iClamp(width, 30 * gap_UI, size_Root(w->root).x - 50 * gap_UI - otherWidth); 970 width = iClamp(width, 30 * gap_UI, size_Root(w->root).x - 50 * gap_UI - otherWidth);
962 } 971 }
963 d->widthAsGaps = (float) width / (float) gap_UI; 972 d->widthAsGaps = (float) width / (float) gap_UI;
@@ -1328,6 +1337,8 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1328 if (isFolder_Bookmark(bm)) { 1337 if (isFolder_Bookmark(bm)) {
1329 const iPtrArray *list = list_Bookmarks(bookmarks_App(), NULL, 1338 const iPtrArray *list = list_Bookmarks(bookmarks_App(), NULL,
1330 filterInsideFolder_Bookmark, bm); 1339 filterInsideFolder_Bookmark, bm);
1340 /* Folder deletion requires confirmation because folders can contain
1341 any number of bookmarks and other folders. */
1331 if (argLabel_Command(cmd, "confirmed") || isEmpty_PtrArray(list)) { 1342 if (argLabel_Command(cmd, "confirmed") || isEmpty_PtrArray(list)) {
1332 iConstForEach(PtrArray, i, list) { 1343 iConstForEach(PtrArray, i, list) {
1333 removeEntries_Feeds(id_Bookmark(i.ptr)); 1344 removeEntries_Feeds(id_Bookmark(i.ptr));