From 05ee79fec8133dd7ca8df8319d85167b3880a3be Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 31 Aug 2023 09:18:57 +1000 Subject: [PATCH] menu: support disabled menu entries. If menu-add is given number '1' (or at least the lsb set) then the menu item is greyed-out. The action isn't disabled - that is up to the caller. Signed-off-by: NeilBrown --- lib-menu.c | 20 +++++++++++++++++++- python/module-notmuch.py | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib-menu.c b/lib-menu.c index 296286b8..201f3e45 100644 --- a/lib-menu.c +++ b/lib-menu.c @@ -33,11 +33,28 @@ DEF_CMD(menu_add) ci->str2 ?: ci->str); call("doc:set-attr", ci->focus, 0, m, "value", 0, NULL, ci->str); + if (ci->num & 1) + call("doc:set-attr", ci->focus, 0, m, "disabled", + 0, NULL, "1"); mark_free(m); return 1; } +DEF_CMD(menu_attr) +{ + if (ci->str && strcmp(ci->str, "BG") == 0) { + char *s = call_ret(str, "doc:get-attr", ci->home, + 0, ci->mark, "disabled"); + char *v = (s && *s) ? "fg:white-40" : "fg:black"; + comm_call(ci->comm2, "cb", ci->focus, 0, ci->mark, + v, 0, NULL, ci->str); + free(s); + return 1; + } + return Efallthrough; +} + DEF_CMD(menu_reposition) { int lines = ci->num; @@ -96,7 +113,7 @@ DEF_CMD(menu_attach) attr_set_str(&docp->attrs, "render-simple", "format"); attr_set_int(&docp->attrs, "render-wrap", 0); attr_set_str(&docp->attrs, "heading", ""); - attr_set_str(&docp->attrs, "line-format", "%name"); + attr_set_str(&docp->attrs, "line-format", "<%BG>%name"); attr_set_str(&docp->attrs, "done-key", ci->str2 ?: "menu-done"); /* No borders, just a shaded background to make menu stand out */ attr_set_str(&docp->attrs, "borders", ""); @@ -128,6 +145,7 @@ static void menu_init_map(void) key_add(menu_map, "Cancel", &menu_abort); key_add(menu_map, "K:Enter", &menu_done); key_add(menu_map, "menu-select", &menu_done); + key_add(menu_map, "doc:get-attr", &menu_attr); } void edlib_init(struct pane *ed safe) diff --git a/python/module-notmuch.py b/python/module-notmuch.py index fc201fd8..6832b1a8 100644 --- a/python/module-notmuch.py +++ b/python/module-notmuch.py @@ -3580,7 +3580,7 @@ class notmuch_message_view(edlib.Pane): t = t[6:] qq = focus.call("doc:notmuch:get-query", t, ret='str') if qq and ("from:"+addr) in qq: - mp.call("menu-add", "-" + t, 'Already in "%s"' % t) + mp.call("menu-add", 1, "-" + t, 'Already in "%s"' % t) else: mp.call("menu-add", t, 'Add to "%s"' % t) mp.call("doc:file", -1) -- 2.39.5