]> git.neil.brown.name Git - edlib.git/commitdiff
menu: support disabled menu entries.
authorNeilBrown <neil@brown.name>
Wed, 30 Aug 2023 23:18:57 +0000 (09:18 +1000)
committerNeilBrown <neil@brown.name>
Wed, 30 Aug 2023 23:37:25 +0000 (09:37 +1000)
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 <neil@brown.name>
lib-menu.c
python/module-notmuch.py

index 296286b8a8c9a9479aefbcd422f476dd18f53aed..201f3e4555ce30235688686b659a4faa21709d86 100644 (file)
@@ -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", "<action-activate:menu-select>%name</>");
+       attr_set_str(&docp->attrs, "line-format", "<%BG><action-activate:menu-select>%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)
index fc201fd8839bee472ab54861df1d59e4d3f52263..6832b1a8237f5373cb17d03201a11c415142694c 100644 (file)
@@ -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)