From c389843f276875aa21dfb5d878994dfaefbe95f0 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Thu, 26 Nov 2020 09:31:24 +0200 Subject: SidebarWidget: Update bookmark tag menu items --- src/ui/sidebarwidget.c | 26 ++++++++++++++++++++++++-- src/ui/util.c | 12 ++++++++++++ src/ui/util.h | 4 +++- 3 files changed, 39 insertions(+), 3 deletions(-) (limited to 'src') 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) { { "Copy URL", 0, 0, "bookmark.copy" }, { "---", 0, 0, NULL }, { "Subscribe to Feed", 0, 0, "bookmark.tag tag:subscribed" }, - { "Use as Homepage", 0, 0, "bookmark.tag tag:homepage" }, + { "", 0, 0, "bookmark.tag tag:homepage" }, { "---", 0, 0, NULL }, { uiTextCaution_ColorEscape "Delete Bookmark", 0, 0, "bookmark.delete" } }, 7); @@ -844,7 +844,29 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) if (constHoverItem_ListWidget(d->list) || isVisible_Widget(d->menu)) { d->menuItem = hoverItem_ListWidget(d->list); /* Update menu items. */ - if (d->mode == identities_SidebarMode) { + /* TODO: Some callback-based mechanism would be nice for updating menus right + before they open? */ + if (d->mode == bookmarks_SidebarMode && d->menuItem) { + const iBookmark *bm = get_Bookmarks(bookmarks_App(), d->menuItem->id); + if (bm) { + iLabelWidget *menuItem = findMenuItem_Widget(d->menu, + "bookmark.tag tag:homepage"); + if (menuItem) { + setTextCStr_LabelWidget(menuItem, + hasTag_Bookmark(bm, "homepage") + ? "Remove Homepage" + : "Use as Homepage"); + } + menuItem = findMenuItem_Widget(d->menu, "bookmark.tag tag:subscribed"); + if (menuItem) { + setTextCStr_LabelWidget(menuItem, + hasTag_Bookmark(bm, "subscribed") + ? "Unsubscribe from Feed" + : "Subscribe to Feed"); + } + } + } + else if (d->mode == identities_SidebarMode) { const iGmIdentity *ident = constHoverIdentity_SidebarWidget_(d); const iString * docUrl = url_DocumentWidget(document_App()); 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) { postCommand_Widget(d, "menu.closed"); } +iLabelWidget *findMenuItem_Widget(iWidget *menu, const char *command) { + iForEach(ObjectList, i, children_Widget(menu)) { + if (isInstance_Object(i.object, &Class_LabelWidget)) { + iLabelWidget *menuItem = i.object; + if (!cmp_String(command_LabelWidget(menuItem), command)) { + return menuItem; + } + } + } + return NULL; +} + int checkContextMenu_Widget(iWidget *menu, const SDL_Event *ev) { if (menu && ev->type == SDL_MOUSEBUTTONDOWN && ev->button.button == SDL_BUTTON_RIGHT) { 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 void openMenu_Widget (iWidget *, iInt2 coord); void closeMenu_Widget (iWidget *); -int checkContextMenu_Widget (iWidget *, const SDL_Event *ev); /* see macro below */ +iLabelWidget * findMenuItem_Widget (iWidget *menu, const char *command); + +int checkContextMenu_Widget (iWidget *, const SDL_Event *ev); /* see macro below */ #define processContextMenuEvent_Widget(menu, sdlEvent, stmtEaten) \ for (const int result = checkContextMenu_Widget((menu), (sdlEvent));;) { \ -- cgit v1.2.3