summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c21
-rw-r--r--src/ui/documentwidget.h1
-rw-r--r--src/ui/sidebarwidget.c46
-rw-r--r--src/ui/sidebarwidget.h2
-rw-r--r--src/ui/window.c3
5 files changed, 71 insertions, 2 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index ff1c577a..7e4bdc73 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -313,6 +313,27 @@ static void updateVisible_DocumentWidget_(iDocumentWidget *d) {
313 } 313 }
314} 314}
315 315
316const iString *bookmarkTitle_DocumentWidget(const iDocumentWidget *d) {
317 iStringArray *title = iClob(new_StringArray());
318 if (!isEmpty_String(title_GmDocument(d->doc))) {
319 pushBack_StringArray(title, title_GmDocument(d->doc));
320 }
321 if (!isEmpty_String(d->titleUser)) {
322 pushBack_StringArray(title, d->titleUser);
323 }
324 else {
325 iUrl parts;
326 init_Url(&parts, d->mod.url);
327 if (!isEmpty_Range(&parts.host)) {
328 pushBackRange_StringArray(title, parts.host);
329 }
330 }
331 if (isEmpty_StringArray(title)) {
332 pushBackCStr_StringArray(title, "Blank Page");
333 }
334 return collect_String(joinCStr_StringArray(title, " \u2014 "));
335}
336
316static void updateWindowTitle_DocumentWidget_(const iDocumentWidget *d) { 337static void updateWindowTitle_DocumentWidget_(const iDocumentWidget *d) {
317 iLabelWidget *tabButton = tabPageButton_Widget(findWidget_App("doctabs"), d); 338 iLabelWidget *tabButton = tabPageButton_Widget(findWidget_App("doctabs"), d);
318 if (!tabButton) { 339 if (!tabButton) {
diff --git a/src/ui/documentwidget.h b/src/ui/documentwidget.h
index 05b8b50f..98591901 100644
--- a/src/ui/documentwidget.h
+++ b/src/ui/documentwidget.h
@@ -18,6 +18,7 @@ iHistory * history_DocumentWidget (iDocumentWidget *);
18const iString * url_DocumentWidget (const iDocumentWidget *); 18const iString * url_DocumentWidget (const iDocumentWidget *);
19iBool isRequestOngoing_DocumentWidget (const iDocumentWidget *); 19iBool isRequestOngoing_DocumentWidget (const iDocumentWidget *);
20const iGmDocument * document_DocumentWidget (const iDocumentWidget *); 20const iGmDocument * document_DocumentWidget (const iDocumentWidget *);
21const iString * bookmarkTitle_DocumentWidget (const iDocumentWidget *);
21 22
22void setUrl_DocumentWidget (iDocumentWidget *, const iString *url); 23void setUrl_DocumentWidget (iDocumentWidget *, const iString *url);
23void setUrlFromCache_DocumentWidget (iDocumentWidget *, const iString *url, iBool isFromCache); 24void setUrlFromCache_DocumentWidget (iDocumentWidget *, const iString *url, iBool isFromCache);
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 }
diff --git a/src/ui/sidebarwidget.h b/src/ui/sidebarwidget.h
index 4d002eee..1645207e 100644
--- a/src/ui/sidebarwidget.h
+++ b/src/ui/sidebarwidget.h
@@ -13,7 +13,7 @@ enum iSidebarMode {
13iDeclareWidgetClass(SidebarWidget) 13iDeclareWidgetClass(SidebarWidget)
14iDeclareObjectConstruction(SidebarWidget) 14iDeclareObjectConstruction(SidebarWidget)
15 15
16void setMode_SidebarWidget (iSidebarWidget *, enum iSidebarMode mode); 16void setMode_SidebarWidget (iSidebarWidget *, enum iSidebarMode mode);
17 17
18enum iSidebarMode mode_SidebarWidget (const iSidebarWidget *); 18enum iSidebarMode mode_SidebarWidget (const iSidebarWidget *);
19int width_SidebarWidget (const iSidebarWidget *); 19int width_SidebarWidget (const iSidebarWidget *);
diff --git a/src/ui/window.c b/src/ui/window.c
index 112b44eb..4f59ef1a 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -72,6 +72,7 @@ static const iMenuItem navMenuItems[] = {
72 { "Open Location...", SDLK_l, KMOD_PRIMARY, "focus.set id:url" }, 72 { "Open Location...", SDLK_l, KMOD_PRIMARY, "focus.set id:url" },
73 { "---", 0, 0, NULL }, 73 { "---", 0, 0, NULL },
74 { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" }, 74 { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" },
75 { "Bookmark This Page", SDLK_d, KMOD_PRIMARY, "bookmark.add" },
75 { "---", 0, 0, NULL }, 76 { "---", 0, 0, NULL },
76 { "Toggle Sidebar", SDLK_s, KMOD_PRIMARY | KMOD_ALT, "sidebar.toggle" }, 77 { "Toggle Sidebar", SDLK_s, KMOD_PRIMARY | KMOD_ALT, "sidebar.toggle" },
77 { "Zoom In", SDLK_EQUALS, KMOD_PRIMARY, "zoom.delta arg:10" }, 78 { "Zoom In", SDLK_EQUALS, KMOD_PRIMARY, "zoom.delta arg:10" },
@@ -93,6 +94,8 @@ static const iMenuItem fileMenuItems[] = {
93 94
94static const iMenuItem editMenuItems[] = { 95static const iMenuItem editMenuItems[] = {
95 { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" }, 96 { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" },
97 { "---", 0, 0, NULL },
98 { "Bookmark This Page", SDLK_d, KMOD_PRIMARY, "bookmark.add" },
96}; 99};
97 100
98static const iMenuItem viewMenuItems[] = { 101static const iMenuItem viewMenuItems[] = {