summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/sidebarwidget.c18
-rw-r--r--src/ui/widget.c4
2 files changed, 10 insertions, 12 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index b8e29a7d..78227cf3 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -15,20 +15,18 @@
15iDeclareType(SidebarItem) 15iDeclareType(SidebarItem)
16 16
17struct Impl_SidebarItem { 17struct Impl_SidebarItem {
18 uint32_t id;
18 int indent; 19 int indent;
19 iChar icon; 20 iChar icon;
20 iString label; 21 iString label;
21 iString meta; 22 iString meta;
22 iString url; 23 iString url;
23 size_t index;
24 const void *src;
25}; 24};
26 25
27void init_SidebarItem(iSidebarItem *d) { 26void init_SidebarItem(iSidebarItem *d) {
27 d->id = 0;
28 d->indent = 0; 28 d->indent = 0;
29 d->icon = 0; 29 d->icon = 0;
30 d->index = 0;
31 d->src = NULL;
32 init_String(&d->label); 30 init_String(&d->label);
33 init_String(&d->meta); 31 init_String(&d->meta);
34 init_String(&d->url); 32 init_String(&d->url);
@@ -110,7 +108,7 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
110 const iGmHeading *head = i.value; 108 const iGmHeading *head = i.value;
111 iSidebarItem item; 109 iSidebarItem item;
112 init_SidebarItem(&item); 110 init_SidebarItem(&item);
113 item.index = index_ArrayConstIterator(&i); 111 item.id = index_ArrayConstIterator(&i);
114 setRange_String(&item.label, head->text); 112 setRange_String(&item.label, head->text);
115 item.indent = head->level * 4 * gap_UI; 113 item.indent = head->level * 4 * gap_UI;
116 pushBack_Array(&d->items, &item); 114 pushBack_Array(&d->items, &item);
@@ -122,6 +120,7 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
122 const iBookmark *bm = i.ptr; 120 const iBookmark *bm = i.ptr;
123 iSidebarItem item; 121 iSidebarItem item;
124 init_SidebarItem(&item); 122 init_SidebarItem(&item);
123 item.id = id_Bookmark(bm);
125 item.icon = bm->icon; 124 item.icon = bm->icon;
126 set_String(&item.url, &bm->url); 125 set_String(&item.url, &bm->url);
127 set_String(&item.label, &bm->title); 126 set_String(&item.label, &bm->title);
@@ -129,7 +128,6 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
129 init_Date(&date, &bm->when); 128 init_Date(&date, &bm->when);
130 iString *ds = format_Date(&date, "%Y %b %d"); 129 iString *ds = format_Date(&date, "%Y %b %d");
131 set_String(&item.meta, ds); 130 set_String(&item.meta, ds);
132 item.src = bm;
133 delete_String(ds); 131 delete_String(ds);
134 pushBack_Array(&d->items, &item); 132 pushBack_Array(&d->items, &item);
135 } 133 }
@@ -251,7 +249,7 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, size_t index) {
251 switch (d->mode) { 249 switch (d->mode) {
252 case documentOutline_SidebarMode: { 250 case documentOutline_SidebarMode: {
253 const iGmDocument *doc = document_DocumentWidget(document_App()); 251 const iGmDocument *doc = document_DocumentWidget(document_App());
254 const iGmHeading *head = constAt_Array(headings_GmDocument(doc), item->index); 252 const iGmHeading *head = constAt_Array(headings_GmDocument(doc), item->id);
255 postCommandf_App("document.goto loc:%p", head->text.start); 253 postCommandf_App("document.goto loc:%p", head->text.start);
256 break; 254 break;
257 } 255 }
@@ -367,8 +365,12 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
367 } 365 }
368 else if (equal_Command(cmd, "bookmark.delete")) { 366 else if (equal_Command(cmd, "bookmark.delete")) {
369 if (d->mode == bookmarks_SidebarMode && d->hoverItem < size_Array(&d->items)) { 367 if (d->mode == bookmarks_SidebarMode && d->hoverItem < size_Array(&d->items)) {
370 368 const iSidebarItem *item = at_Array(&d->items, d->hoverItem);
369 if (remove_Bookmarks(bookmarks_App(), item->id)) {
370 postCommand_App("bookmarks.changed");
371 }
371 } 372 }
373 return iTrue;
372 } 374 }
373 else if (equal_Command(cmd, "bookmarks.changed")) { 375 else if (equal_Command(cmd, "bookmarks.changed")) {
374 updateItems_SidebarWidget_(d); 376 updateItems_SidebarWidget_(d);
diff --git a/src/ui/widget.c b/src/ui/widget.c
index cfd8304b..4dd847c7 100644
--- a/src/ui/widget.c
+++ b/src/ui/widget.c
@@ -412,10 +412,6 @@ iBool dispatchEvent_Widget(iWidget *d, const SDL_Event *ev) {
412 } 412 }
413 } 413 }
414 if (class_Widget(d)->processEvent(d, ev)) { 414 if (class_Widget(d)->processEvent(d, ev)) {
415 if (ev->type == SDL_MOUSEBUTTONDOWN) {
416 printf("mb.down eaten by %p '%s'\n", d, cstr_String(id_Widget(d)));
417 fflush(stdout);
418 }
419 return iTrue; 415 return iTrue;
420 } 416 }
421 } 417 }