summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bookmarks.c9
-rw-r--r--src/bookmarks.h2
-rw-r--r--src/ui/sidebarwidget.c22
3 files changed, 32 insertions, 1 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c
index f97ef0c6..0791a207 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -41,6 +41,15 @@ void deinit_Bookmark(iBookmark *d) {
41 deinit_String(&d->url); 41 deinit_String(&d->url);
42} 42}
43 43
44iBool hasTag_Bookmark(const iBookmark *d, const char *tag) {
45 iRegExp *pattern = new_RegExp(format_CStr("\\b%s\\b", tag), caseSensitive_RegExpOption);
46 iRegExpMatch m;
47 init_RegExpMatch(&m);
48 const iBool found = matchString_RegExp(pattern, &d->tags, &m);
49 iRelease(pattern);
50 return found;
51}
52
44iDefineTypeConstruction(Bookmark) 53iDefineTypeConstruction(Bookmark)
45 54
46static int cmpTimeDescending_Bookmark_(const iBookmark **a, const iBookmark **b) { 55static int cmpTimeDescending_Bookmark_(const iBookmark **a, const iBookmark **b) {
diff --git a/src/bookmarks.h b/src/bookmarks.h
index 84bdbd68..228c7885 100644
--- a/src/bookmarks.h
+++ b/src/bookmarks.h
@@ -41,6 +41,8 @@ struct Impl_Bookmark {
41 41
42iLocalDef uint32_t id_Bookmark (const iBookmark *d) { return d->node.key; } 42iLocalDef uint32_t id_Bookmark (const iBookmark *d) { return d->node.key; }
43 43
44iBool hasTag_Bookmark (const iBookmark *d, const char *tag);
45
44iDeclareType(Bookmarks) 46iDeclareType(Bookmarks)
45iDeclareTypeConstruction(Bookmarks) 47iDeclareTypeConstruction(Bookmarks)
46 48
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 7cde5d7b..6f1a7c04 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -202,9 +202,11 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
202 (iMenuItem[]){ { "Edit Bookmark...", 0, 0, "bookmark.edit" }, 202 (iMenuItem[]){ { "Edit Bookmark...", 0, 0, "bookmark.edit" },
203 { "Copy URL", 0, 0, "bookmark.copy" }, 203 { "Copy URL", 0, 0, "bookmark.copy" },
204 { "---", 0, 0, NULL }, 204 { "---", 0, 0, NULL },
205 { "Subscribe", 0, 0, "bookmark.tag tag:subscribed" },
206 { "Use as Homepage", 0, 0, "bookmark.tag tag:homepage" },
205 { "---", 0, 0, NULL }, 207 { "---", 0, 0, NULL },
206 { uiTextCaution_ColorEscape "Delete Bookmark", 0, 0, "bookmark.delete" } }, 208 { uiTextCaution_ColorEscape "Delete Bookmark", 0, 0, "bookmark.delete" } },
207 5); 209 7);
208 break; 210 break;
209 } 211 }
210 case history_SidebarMode: { 212 case history_SidebarMode: {
@@ -650,6 +652,24 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
650 } 652 }
651 return iTrue; 653 return iTrue;
652 } 654 }
655 else if (equal_Command(cmd, "bookmark.tag")) {
656 const iSidebarItem *item = d->menuItem;
657 if (d->mode == bookmarks_SidebarMode && item) {
658 const char *tag = cstr_String(string_Command(cmd, "tag"));
659 iBookmark *bm = get_Bookmarks(bookmarks_App(), item->id);
660 if (hasTag_Bookmark(bm, tag)) {
661 size_t pos = indexOfCStr_String(&bm->tags, tag);
662 remove_Block(&bm->tags.chars, pos, strlen(tag));
663 trim_String(&bm->tags);
664 }
665 else {
666 appendChar_String(&bm->tags, ' ');
667 appendCStr_String(&bm->tags, tag);
668 }
669 postCommand_App("bookmarks.changed");
670 }
671 return iTrue;
672 }
653 else if (equal_Command(cmd, "bookmark.delete")) { 673 else if (equal_Command(cmd, "bookmark.delete")) {
654 const iSidebarItem *item = d->menuItem; 674 const iSidebarItem *item = d->menuItem;
655 if (d->mode == bookmarks_SidebarMode && item && remove_Bookmarks(bookmarks_App(), item->id)) { 675 if (d->mode == bookmarks_SidebarMode && item && remove_Bookmarks(bookmarks_App(), item->id)) {