summaryrefslogtreecommitdiff
path: root/src/ui/sidebarwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-23 22:11:24 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-23 22:11:24 +0300
commit27ebfc904b9b3eac3ef5479ed0d0ba166fac1543 (patch)
tree0a7a74bf586701645107c27a04564b41368260db /src/ui/sidebarwidget.c
parent48c3553660f4c20fc3bb4fb5df95c058adf9dd87 (diff)
Bookmarks: TOML syntax; field for manual order
The bookmarks file is now saved in a TOML subset and named "bookmarks.ini". This makes it more robust and forwards compatible. Added a field for sort order, since that will be used for manual ordering.
Diffstat (limited to 'src/ui/sidebarwidget.c')
-rw-r--r--src/ui/sidebarwidget.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index ffedfeeb..3463f1a5 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -116,24 +116,26 @@ static iBool isResizing_SidebarWidget_(const iSidebarWidget *d) {
116 return (flags_Widget(d->resizer) & pressed_WidgetFlag) != 0; 116 return (flags_Widget(d->resizer) & pressed_WidgetFlag) != 0;
117} 117}
118 118
119static int cmpTitle_Bookmark_(const iBookmark **a, const iBookmark **b) { 119static int cmpTree_Bookmark_(const iBookmark **a, const iBookmark **b) {
120 const iBookmark *bm1 = *a, *bm2 = *b; 120 const iBookmark *bm1 = *a, *bm2 = *b;
121 if (bm2->sourceId == id_Bookmark(bm1)) { 121 if (bm2->parentId == id_Bookmark(bm1)) {
122 return -1; 122 return -1;
123 } 123 }
124 if (bm1->sourceId == id_Bookmark(bm2)) { 124 if (bm1->parentId == id_Bookmark(bm2)) {
125 return 1; 125 return 1;
126 } 126 }
127 if (bm1->sourceId == bm2->sourceId) { 127 if (bm1->parentId == bm2->parentId) {
128 return cmpStringCase_String(&bm1->title, &bm2->title); 128 //return cmpStringCase_String(&bm1->title, &bm2->title);
129 return iCmp(bm1->order, bm2->order);
129 } 130 }
130 if (bm1->sourceId) { 131 if (bm1->parentId) {
131 bm1 = get_Bookmarks(bookmarks_App(), bm1->sourceId); 132 bm1 = get_Bookmarks(bookmarks_App(), bm1->parentId);
132 } 133 }
133 if (bm2->sourceId) { 134 if (bm2->parentId) {
134 bm2 = get_Bookmarks(bookmarks_App(), bm2->sourceId); 135 bm2 = get_Bookmarks(bookmarks_App(), bm2->parentId);
135 } 136 }
136 return cmpStringCase_String(&bm1->title, &bm2->title); 137// return cmpStringCase_String(&bm1->title, &bm2->title);
138 return iCmp(bm1->order, bm2->order);
137} 139}
138 140
139static iLabelWidget *addActionButton_SidebarWidget_(iSidebarWidget *d, const char *label, 141static iLabelWidget *addActionButton_SidebarWidget_(iSidebarWidget *d, const char *label,
@@ -331,9 +333,10 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
331 iRegExp *subTag = iClob(new_RegExp("\\b" subscribed_BookmarkTag "\\b", caseSensitive_RegExpOption)); 333 iRegExp *subTag = iClob(new_RegExp("\\b" subscribed_BookmarkTag "\\b", caseSensitive_RegExpOption));
332 iRegExp *remoteSourceTag = iClob(new_RegExp("\\b" remoteSource_BookmarkTag "\\b", caseSensitive_RegExpOption)); 334 iRegExp *remoteSourceTag = iClob(new_RegExp("\\b" remoteSource_BookmarkTag "\\b", caseSensitive_RegExpOption));
333 iRegExp *linkSplitTag = iClob(new_RegExp("\\b" linkSplit_BookmarkTag "\\b", caseSensitive_RegExpOption)); 335 iRegExp *linkSplitTag = iClob(new_RegExp("\\b" linkSplit_BookmarkTag "\\b", caseSensitive_RegExpOption));
334 iConstForEach(PtrArray, i, list_Bookmarks(bookmarks_App(), cmpTitle_Bookmark_, NULL, NULL)) { 336 iConstForEach(PtrArray, i, list_Bookmarks(bookmarks_App(), cmpTree_Bookmark_, NULL, NULL)) {
335 const iBookmark *bm = i.ptr; 337 const iBookmark *bm = i.ptr;
336 iSidebarItem *item = new_SidebarItem(); 338 iSidebarItem *item = new_SidebarItem();
339 item->listItem.isDraggable = iTrue;
337 item->id = id_Bookmark(bm); 340 item->id = id_Bookmark(bm);
338 item->icon = bm->icon; 341 item->icon = bm->icon;
339 set_String(&item->url, &bm->url); 342 set_String(&item->url, &bm->url);
@@ -1573,12 +1576,14 @@ static void draw_SidebarItem_(const iSidebarItem *d, iPaint *p, iRect itemRect,
1573 const iSidebarWidget *sidebar = findParentClass_Widget(constAs_Widget(list), 1576 const iSidebarWidget *sidebar = findParentClass_Widget(constAs_Widget(list),
1574 &Class_SidebarWidget); 1577 &Class_SidebarWidget);
1575 const iBool isMenuVisible = isVisible_Widget(sidebar->menu); 1578 const iBool isMenuVisible = isVisible_Widget(sidebar->menu);
1576 const iBool isPressing = isMouseDown_ListWidget(list); 1579 const iBool isDragging = constDragItem_ListWidget(list) == d;
1580 const iBool isPressing = isMouseDown_ListWidget(list) && !isDragging;
1577 const iBool isHover = 1581 const iBool isHover =
1578 (!isMenuVisible && 1582 (!isMenuVisible &&
1579 isHover_Widget(constAs_Widget(list)) && 1583 isHover_Widget(constAs_Widget(list)) &&
1580 constHoverItem_ListWidget(list) == d) || 1584 constHoverItem_ListWidget(list) == d) ||
1581 (isMenuVisible && sidebar->contextItem == d); 1585 (isMenuVisible && sidebar->contextItem == d) ||
1586 isDragging;
1582 const int scrollBarWidth = scrollBarWidth_ListWidget(list); 1587 const int scrollBarWidth = scrollBarWidth_ListWidget(list);
1583#if defined (iPlatformApple) 1588#if defined (iPlatformApple)
1584 const int blankWidth = 0; 1589 const int blankWidth = 0;
@@ -1729,12 +1734,14 @@ static void draw_SidebarItem_(const iSidebarItem *d, iPaint *p, iRect itemRect,
1729 metaIconWidth 1734 metaIconWidth
1730 - 2 * gap_UI - (blankWidth ? blankWidth - 1.5f * gap_UI : (gap_UI / 2)), 1735 - 2 * gap_UI - (blankWidth ? blankWidth - 1.5f * gap_UI : (gap_UI / 2)),
1731 textPos.y); 1736 textPos.y);
1732 fillRect_Paint(p, 1737 if (!isDragging) {
1733 init_Rect(metaPos.x, 1738 fillRect_Paint(p,
1734 top_Rect(itemRect), 1739 init_Rect(metaPos.x,
1735 right_Rect(itemRect) - metaPos.x, 1740 top_Rect(itemRect),
1736 height_Rect(itemRect)), 1741 right_Rect(itemRect) - metaPos.x,
1737 bg); 1742 height_Rect(itemRect)),
1743 bg);
1744 }
1738 iInt2 mpos = metaPos; 1745 iInt2 mpos = metaPos;
1739 iStringConstIterator iter; 1746 iStringConstIterator iter;
1740 init_StringConstIterator(&iter, &d->meta); 1747 init_StringConstIterator(&iter, &d->meta);