summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-08-14 17:08:39 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-08-14 17:08:39 +0300
commitf60baccbe3e04769e9bab66625a4f3923a01f191 (patch)
tree2623a655e952e972827a2fbf110093d065dc5d7b /src
parentf8f382ed14151d3c293a9ee754f0a66f513fb7d3 (diff)
Deleting bookmarks
Diffstat (limited to 'src')
-rw-r--r--src/bookmarks.c9
-rw-r--r--src/bookmarks.h2
-rw-r--r--src/ui/sidebarwidget.c18
-rw-r--r--src/ui/widget.c4
4 files changed, 18 insertions, 15 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c
index 96a2b6a0..29b3d836 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -118,8 +118,13 @@ void add_Bookmarks(iBookmarks *d, const iString *url, const iString *title, cons
118 insert_Bookmarks_(d, bm); 118 insert_Bookmarks_(d, bm);
119} 119}
120 120
121void remove_Bookmarks(iBookmarks *d, uint32_t id) { 121iBool remove_Bookmarks(iBookmarks *d, uint32_t id) {
122 delete_Bookmark((iBookmark *) remove_Hash(&d->bookmarks, id)); 122 iBookmark *bm = (iBookmark *) remove_Hash(&d->bookmarks, id);
123 if (bm) {
124 delete_Bookmark(bm);
125 return iTrue;
126 }
127 return iFalse;
123} 128}
124 129
125const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksFilterFunc filter, 130const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksFilterFunc filter,
diff --git a/src/bookmarks.h b/src/bookmarks.h
index e1f517ad..336e542a 100644
--- a/src/bookmarks.h
+++ b/src/bookmarks.h
@@ -27,7 +27,7 @@ void load_Bookmarks (iBookmarks *, const char *dirPath);
27void save_Bookmarks (const iBookmarks *, const char *dirPath); 27void save_Bookmarks (const iBookmarks *, const char *dirPath);
28 28
29void add_Bookmarks (iBookmarks *, const iString *url, const iString *title, const iString *tags, iChar icon); 29void add_Bookmarks (iBookmarks *, const iString *url, const iString *title, const iString *tags, iChar icon);
30void remove_Bookmarks (iBookmarks *, uint32_t id); 30iBool remove_Bookmarks (iBookmarks *, uint32_t id);
31 31
32typedef iBool (*iBookmarksFilterFunc) (const iBookmark *); 32typedef iBool (*iBookmarksFilterFunc) (const iBookmark *);
33typedef int (*iBookmarksCompareFunc)(const iBookmark **, const iBookmark **); 33typedef int (*iBookmarksCompareFunc)(const iBookmark **, const iBookmark **);
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 }