diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-26 09:31:24 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-26 09:31:24 +0200 |
commit | c389843f276875aa21dfb5d878994dfaefbe95f0 (patch) | |
tree | 05cef9f627513ca39269559b0c96c78fcf7dcfbe /src/ui | |
parent | b60d380ad6e83cd1b155b8057528f25bb1494a38 (diff) |
SidebarWidget: Update bookmark tag menu items
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/sidebarwidget.c | 26 | ||||
-rw-r--r-- | src/ui/util.c | 12 | ||||
-rw-r--r-- | src/ui/util.h | 4 |
3 files changed, 39 insertions, 3 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index d6c74298..9946ac5a 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c | |||
@@ -214,7 +214,7 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { | |||
214 | { "Copy URL", 0, 0, "bookmark.copy" }, | 214 | { "Copy URL", 0, 0, "bookmark.copy" }, |
215 | { "---", 0, 0, NULL }, | 215 | { "---", 0, 0, NULL }, |
216 | { "Subscribe to Feed", 0, 0, "bookmark.tag tag:subscribed" }, | 216 | { "Subscribe to Feed", 0, 0, "bookmark.tag tag:subscribed" }, |
217 | { "Use as Homepage", 0, 0, "bookmark.tag tag:homepage" }, | 217 | { "", 0, 0, "bookmark.tag tag:homepage" }, |
218 | { "---", 0, 0, NULL }, | 218 | { "---", 0, 0, NULL }, |
219 | { uiTextCaution_ColorEscape "Delete Bookmark", 0, 0, "bookmark.delete" } }, | 219 | { uiTextCaution_ColorEscape "Delete Bookmark", 0, 0, "bookmark.delete" } }, |
220 | 7); | 220 | 7); |
@@ -844,7 +844,29 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
844 | if (constHoverItem_ListWidget(d->list) || isVisible_Widget(d->menu)) { | 844 | if (constHoverItem_ListWidget(d->list) || isVisible_Widget(d->menu)) { |
845 | d->menuItem = hoverItem_ListWidget(d->list); | 845 | d->menuItem = hoverItem_ListWidget(d->list); |
846 | /* Update menu items. */ | 846 | /* Update menu items. */ |
847 | if (d->mode == identities_SidebarMode) { | 847 | /* TODO: Some callback-based mechanism would be nice for updating menus right |
848 | before they open? */ | ||
849 | if (d->mode == bookmarks_SidebarMode && d->menuItem) { | ||
850 | const iBookmark *bm = get_Bookmarks(bookmarks_App(), d->menuItem->id); | ||
851 | if (bm) { | ||
852 | iLabelWidget *menuItem = findMenuItem_Widget(d->menu, | ||
853 | "bookmark.tag tag:homepage"); | ||
854 | if (menuItem) { | ||
855 | setTextCStr_LabelWidget(menuItem, | ||
856 | hasTag_Bookmark(bm, "homepage") | ||
857 | ? "Remove Homepage" | ||
858 | : "Use as Homepage"); | ||
859 | } | ||
860 | menuItem = findMenuItem_Widget(d->menu, "bookmark.tag tag:subscribed"); | ||
861 | if (menuItem) { | ||
862 | setTextCStr_LabelWidget(menuItem, | ||
863 | hasTag_Bookmark(bm, "subscribed") | ||
864 | ? "Unsubscribe from Feed" | ||
865 | : "Subscribe to Feed"); | ||
866 | } | ||
867 | } | ||
868 | } | ||
869 | else if (d->mode == identities_SidebarMode) { | ||
848 | const iGmIdentity *ident = constHoverIdentity_SidebarWidget_(d); | 870 | const iGmIdentity *ident = constHoverIdentity_SidebarWidget_(d); |
849 | const iString * docUrl = url_DocumentWidget(document_App()); | 871 | const iString * docUrl = url_DocumentWidget(document_App()); |
850 | iForEach(ObjectList, i, children_Widget(d->menu)) { | 872 | iForEach(ObjectList, i, children_Widget(d->menu)) { |
diff --git a/src/ui/util.c b/src/ui/util.c index ef88d989..04604662 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -467,6 +467,18 @@ void closeMenu_Widget(iWidget *d) { | |||
467 | postCommand_Widget(d, "menu.closed"); | 467 | postCommand_Widget(d, "menu.closed"); |
468 | } | 468 | } |
469 | 469 | ||
470 | iLabelWidget *findMenuItem_Widget(iWidget *menu, const char *command) { | ||
471 | iForEach(ObjectList, i, children_Widget(menu)) { | ||
472 | if (isInstance_Object(i.object, &Class_LabelWidget)) { | ||
473 | iLabelWidget *menuItem = i.object; | ||
474 | if (!cmp_String(command_LabelWidget(menuItem), command)) { | ||
475 | return menuItem; | ||
476 | } | ||
477 | } | ||
478 | } | ||
479 | return NULL; | ||
480 | } | ||
481 | |||
470 | int checkContextMenu_Widget(iWidget *menu, const SDL_Event *ev) { | 482 | int checkContextMenu_Widget(iWidget *menu, const SDL_Event *ev) { |
471 | if (menu && ev->type == SDL_MOUSEBUTTONDOWN && ev->button.button == SDL_BUTTON_RIGHT) { | 483 | if (menu && ev->type == SDL_MOUSEBUTTONDOWN && ev->button.button == SDL_BUTTON_RIGHT) { |
472 | if (isVisible_Widget(menu)) { | 484 | if (isVisible_Widget(menu)) { |
diff --git a/src/ui/util.h b/src/ui/util.h index f7a67f9a..062ae56a 100644 --- a/src/ui/util.h +++ b/src/ui/util.h | |||
@@ -157,7 +157,9 @@ iWidget * makeMenu_Widget (iWidget *parent, const iMenuItem *items, size_t | |||
157 | void openMenu_Widget (iWidget *, iInt2 coord); | 157 | void openMenu_Widget (iWidget *, iInt2 coord); |
158 | void closeMenu_Widget (iWidget *); | 158 | void closeMenu_Widget (iWidget *); |
159 | 159 | ||
160 | int checkContextMenu_Widget (iWidget *, const SDL_Event *ev); /* see macro below */ | 160 | iLabelWidget * findMenuItem_Widget (iWidget *menu, const char *command); |
161 | |||
162 | int checkContextMenu_Widget (iWidget *, const SDL_Event *ev); /* see macro below */ | ||
161 | 163 | ||
162 | #define processContextMenuEvent_Widget(menu, sdlEvent, stmtEaten) \ | 164 | #define processContextMenuEvent_Widget(menu, sdlEvent, stmtEaten) \ |
163 | for (const int result = checkContextMenu_Widget((menu), (sdlEvent));;) { \ | 165 | for (const int result = checkContextMenu_Widget((menu), (sdlEvent));;) { \ |