diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-05-05 15:22:13 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-05-05 15:22:13 +0300 |
commit | 8cd4fbea6da42c2df77dd17eb0b1626d8611c0a2 (patch) | |
tree | f0a33dc68947de1d408179a1860cdc4361ce6481 /src | |
parent | a47d8d7051e9d5b0eaddf2c3895c439c4f26a104 (diff) |
Bookmark editor has toggles for some special tags
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks.h | 20 | ||||
-rw-r--r-- | src/ui/sidebarwidget.c | 30 | ||||
-rw-r--r-- | src/ui/util.c | 15 |
3 files changed, 52 insertions, 13 deletions
diff --git a/src/bookmarks.h b/src/bookmarks.h index 635682d1..353b4197 100644 --- a/src/bookmarks.h +++ b/src/bookmarks.h | |||
@@ -52,9 +52,23 @@ struct Impl_Bookmark { | |||
52 | 52 | ||
53 | iLocalDef uint32_t id_Bookmark (const iBookmark *d) { return d->node.key; } | 53 | iLocalDef uint32_t id_Bookmark (const iBookmark *d) { return d->node.key; } |
54 | 54 | ||
55 | iBool hasTag_Bookmark (const iBookmark *d, const char *tag); | 55 | iBool hasTag_Bookmark (const iBookmark *, const char *tag); |
56 | void addTag_Bookmark (iBookmark *d, const char *tag); | 56 | void addTag_Bookmark (iBookmark *, const char *tag); |
57 | void removeTag_Bookmark (iBookmark *d, const char *tag); | 57 | void removeTag_Bookmark (iBookmark *, const char *tag); |
58 | |||
59 | iLocalDef void addTagIfMissing_Bookmark(iBookmark *d, const char *tag) { | ||
60 | if (!hasTag_Bookmark(d, tag)) { | ||
61 | addTag_Bookmark(d, tag); | ||
62 | } | ||
63 | } | ||
64 | iLocalDef void addOrRemoveTag_Bookmark(iBookmark *d, const char *tag, iBool add) { | ||
65 | if (add) { | ||
66 | addTagIfMissing_Bookmark(d, tag); | ||
67 | } | ||
68 | else { | ||
69 | removeTag_Bookmark(d, tag); | ||
70 | } | ||
71 | } | ||
58 | 72 | ||
59 | /*----------------------------------------------------------------------------------------------*/ | 73 | /*----------------------------------------------------------------------------------------------*/ |
60 | 74 | ||
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 245b76a3..eae0432f 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c | |||
@@ -265,9 +265,10 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { | |||
265 | break; | 265 | break; |
266 | } | 266 | } |
267 | case bookmarks_SidebarMode: { | 267 | case bookmarks_SidebarMode: { |
268 | iRegExp *homeTag = iClob(new_RegExp("\\bhomepage\\b", caseSensitive_RegExpOption)); | 268 | iRegExp *homeTag = iClob(new_RegExp("\\b" homepage_BookmarkTag "\\b", caseSensitive_RegExpOption)); |
269 | iRegExp *subTag = iClob(new_RegExp("\\bsubscribed\\b", caseSensitive_RegExpOption)); | 269 | iRegExp *subTag = iClob(new_RegExp("\\b" subscribed_BookmarkTag "\\b", caseSensitive_RegExpOption)); |
270 | iRegExp *remoteSourceTag = iClob(new_RegExp("\\bremotesource\\b", caseSensitive_RegExpOption)); | 270 | iRegExp *remoteSourceTag = iClob(new_RegExp("\\b" remoteSource_BookmarkTag "\\b", caseSensitive_RegExpOption)); |
271 | iRegExp *linkSplitTag = iClob(new_RegExp("\\b" linkSplit_BookmarkTag "\\b", caseSensitive_RegExpOption)); | ||
271 | iConstForEach(PtrArray, i, list_Bookmarks(bookmarks_App(), cmpTitle_Bookmark_, NULL, NULL)) { | 272 | iConstForEach(PtrArray, i, list_Bookmarks(bookmarks_App(), cmpTitle_Bookmark_, NULL, NULL)) { |
272 | const iBookmark *bm = i.ptr; | 273 | const iBookmark *bm = i.ptr; |
273 | iSidebarItem *item = new_SidebarItem(); | 274 | iSidebarItem *item = new_SidebarItem(); |
@@ -290,6 +291,10 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { | |||
290 | appendChar_String(&item->meta, 0x2913); | 291 | appendChar_String(&item->meta, 0x2913); |
291 | item->isBold = iTrue; | 292 | item->isBold = iTrue; |
292 | } | 293 | } |
294 | init_RegExpMatch(&m); | ||
295 | if (matchString_RegExp(linkSplitTag, &bm->tags, &m)) { | ||
296 | appendChar_String(&item->meta, 0x25e7); | ||
297 | } | ||
293 | } | 298 | } |
294 | addItem_ListWidget(d->list, item); | 299 | addItem_ListWidget(d->list, item); |
295 | iRelease(item); | 300 | iRelease(item); |
@@ -828,11 +833,15 @@ iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *c | |||
828 | bm->icon = 0; | 833 | bm->icon = 0; |
829 | } | 834 | } |
830 | else { | 835 | else { |
831 | if (!hasTag_Bookmark(bm, userIcon_BookmarkTag)) { | 836 | addTagIfMissing_Bookmark(bm, userIcon_BookmarkTag); |
832 | addTag_Bookmark(bm, userIcon_BookmarkTag); | ||
833 | } | ||
834 | bm->icon = first_String(icon); | 837 | bm->icon = first_String(icon); |
835 | } | 838 | } |
839 | addOrRemoveTag_Bookmark(bm, homepage_BookmarkTag, | ||
840 | isSelected_Widget(findChild_Widget(editor, "bmed.tag.home"))); | ||
841 | addOrRemoveTag_Bookmark(bm, remoteSource_BookmarkTag, | ||
842 | isSelected_Widget(findChild_Widget(editor, "bmed.tag.remote"))); | ||
843 | addOrRemoveTag_Bookmark(bm, linkSplit_BookmarkTag, | ||
844 | isSelected_Widget(findChild_Widget(editor, "bmed.tag.linksplit"))); | ||
836 | postCommand_App("bookmarks.changed"); | 845 | postCommand_App("bookmarks.changed"); |
837 | } | 846 | } |
838 | setFlags_Widget(as_Widget(d), disabled_WidgetFlag, iFalse); | 847 | setFlags_Widget(as_Widget(d), disabled_WidgetFlag, iFalse); |
@@ -1012,6 +1021,15 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
1012 | setText_InputWidget(findChild_Widget(dlg, "bmed.icon"), | 1021 | setText_InputWidget(findChild_Widget(dlg, "bmed.icon"), |
1013 | collect_String(newUnicodeN_String(&bm->icon, 1))); | 1022 | collect_String(newUnicodeN_String(&bm->icon, 1))); |
1014 | } | 1023 | } |
1024 | setFlags_Widget(findChild_Widget(dlg, "bmed.tag.home"), | ||
1025 | selected_WidgetFlag, | ||
1026 | hasTag_Bookmark(bm, homepage_BookmarkTag)); | ||
1027 | setFlags_Widget(findChild_Widget(dlg, "bmed.tag.remote"), | ||
1028 | selected_WidgetFlag, | ||
1029 | hasTag_Bookmark(bm, remoteSource_BookmarkTag)); | ||
1030 | setFlags_Widget(findChild_Widget(dlg, "bmed.tag.linksplit"), | ||
1031 | selected_WidgetFlag, | ||
1032 | hasTag_Bookmark(bm, linkSplit_BookmarkTag)); | ||
1015 | setCommandHandler_Widget(dlg, handleBookmarkEditorCommands_SidebarWidget_); | 1033 | setCommandHandler_Widget(dlg, handleBookmarkEditorCommands_SidebarWidget_); |
1016 | setFocus_Widget(findChild_Widget(dlg, "bmed.title")); | 1034 | setFocus_Widget(findChild_Widget(dlg, "bmed.title")); |
1017 | } | 1035 | } |
diff --git a/src/ui/util.c b/src/ui/util.c index d2f27a8b..92cf85b7 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -2506,11 +2506,18 @@ static iBool handleBookmarkCreationCommands_SidebarWidget_(iWidget *editor, cons | |||
2506 | const iString *tags = text_InputWidget(findChild_Widget(editor, "bmed.tags")); | 2506 | const iString *tags = text_InputWidget(findChild_Widget(editor, "bmed.tags")); |
2507 | const iString *icon = collect_String(trimmed_String(text_InputWidget(findChild_Widget(editor, "bmed.icon")))); | 2507 | const iString *icon = collect_String(trimmed_String(text_InputWidget(findChild_Widget(editor, "bmed.icon")))); |
2508 | const uint32_t id = add_Bookmarks(bookmarks_App(), url, title, tags, first_String(icon)); | 2508 | const uint32_t id = add_Bookmarks(bookmarks_App(), url, title, tags, first_String(icon)); |
2509 | iBookmark * bm = get_Bookmarks(bookmarks_App(), id); | ||
2509 | if (!isEmpty_String(icon)) { | 2510 | if (!isEmpty_String(icon)) { |
2510 | iBookmark *bm = get_Bookmarks(bookmarks_App(), id); | 2511 | addTagIfMissing_Bookmark(bm, userIcon_BookmarkTag); |
2511 | if (!hasTag_Bookmark(bm, userIcon_BookmarkTag)) { | 2512 | } |
2512 | addTag_Bookmark(bm, userIcon_BookmarkTag); | 2513 | if (isSelected_Widget(findChild_Widget(editor, "bmed.tag.home"))) { |
2513 | } | 2514 | addTag_Bookmark(bm, homepage_BookmarkTag); |
2515 | } | ||
2516 | if (isSelected_Widget(findChild_Widget(editor, "bmed.tag.remote"))) { | ||
2517 | addTag_Bookmark(bm, remoteSource_BookmarkTag); | ||
2518 | } | ||
2519 | if (isSelected_Widget(findChild_Widget(editor, "bmed.tag.linksplit"))) { | ||
2520 | addTag_Bookmark(bm, linkSplit_BookmarkTag); | ||
2514 | } | 2521 | } |
2515 | postCommand_App("bookmarks.changed"); | 2522 | postCommand_App("bookmarks.changed"); |
2516 | } | 2523 | } |