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.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index ca10f0da..8108c797 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -2,6 +2,7 @@
2#include "labelwidget.h" 2#include "labelwidget.h"
3#include "scrollwidget.h" 3#include "scrollwidget.h"
4#include "documentwidget.h" 4#include "documentwidget.h"
5#include "bookmarks.h"
5#include "paint.h" 6#include "paint.h"
6#include "util.h" 7#include "util.h"
7#include "command.h" 8#include "command.h"
@@ -111,8 +112,23 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
111 } 112 }
112 break; 113 break;
113 } 114 }
114 case bookmarks_SidebarMode: 115 case bookmarks_SidebarMode: {
116 iConstForEach(PtrArray, i, list_Bookmarks(bookmarks_App(), NULL, NULL)) {
117 const iBookmark *bm = i.ptr;
118 iSidebarItem item;
119 init_SidebarItem(&item);
120 item.icon = bm->icon;
121 set_String(&item.url, &bm->url);
122 set_String(&item.label, &bm->title);
123 iDate date;
124 init_Date(&date, &bm->when);
125 iString *ds = format_Date(&date, "%Y %b %d");
126 set_String(&item.meta, ds);
127 delete_String(ds);
128 pushBack_Array(&d->items, &item);
129 }
115 break; 130 break;
131 }
116 case history_SidebarMode: 132 case history_SidebarMode:
117 break; 133 break;
118 default: 134 default:
@@ -230,6 +246,10 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, size_t index) {
230 postCommandf_App("document.goto loc:%p", head->text.start); 246 postCommandf_App("document.goto loc:%p", head->text.start);
231 break; 247 break;
232 } 248 }
249 case bookmarks_SidebarMode: {
250 postCommandf_App("open url:%s", cstr_String(&item->url));
251 break;
252 }
233 } 253 }
234} 254}
235 255
@@ -336,6 +356,9 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
336 d->scrollY = 0; 356 d->scrollY = 0;
337 updateItems_SidebarWidget_(d); 357 updateItems_SidebarWidget_(d);
338 } 358 }
359 else if (equal_Command(cmd, "bookmarks.changed")) {
360 updateItems_SidebarWidget_(d);
361 }
339 } 362 }
340 if (ev->type == SDL_MOUSEMOTION) { 363 if (ev->type == SDL_MOUSEMOTION) {
341 const iInt2 mouse = init_I2(ev->motion.x, ev->motion.y); 364 const iInt2 mouse = init_I2(ev->motion.x, ev->motion.y);
@@ -407,6 +430,27 @@ static void draw_SidebarWidget_(const iSidebarWidget *d) {
407 mid_Rect(itemRect).y - lineHeight_Text(font) / 2), 430 mid_Rect(itemRect).y - lineHeight_Text(font) / 2),
408 fg, range_String(&item->label)); 431 fg, range_String(&item->label));
409 } 432 }
433 else if (d->mode == bookmarks_SidebarMode) {
434 const int fg =
435 isHover ? (isPressing ? black_ColorId : white_ColorId) : gray75_ColorId;
436 iString str;
437 init_String(&str);
438 appendChar_String(&str, item->icon ? item->icon : 0x1f588);
439 const iRect iconArea = { pos, init_I2(10 * gap_UI, d->itemHeight) };
440 drawCentered_Text(uiBookmarkIcon_FontId,
441 iconArea,
442 iTrue,
443 isHover && isPressing ? black_ColorId : cyan_ColorId,
444 "%s",
445 cstr_String(&str));
446 deinit_String(&str);
447 iInt2 textPos = topRight_Rect(iconArea);
448 drawRange_Text(font, textPos, fg, range_String(&item->label));
449 drawRange_Text(font,
450 addY_I2(textPos, lineHeight_Text(font)),
451 isHover ? (isPressing ? black_ColorId : cyan_ColorId) : teal_ColorId,
452 range_String(&item->meta));
453 }
410 unsetClip_Paint(&p); 454 unsetClip_Paint(&p);
411 pos.y += d->itemHeight; 455 pos.y += d->itemHeight;
412 } 456 }