]> git.neil.brown.name Git - edlib.git/commitdiff
menu: allow short-cut keys to be shown.
authorNeilBrown <neil@brown.name>
Wed, 30 Aug 2023 23:28:40 +0000 (09:28 +1000)
committerNeilBrown <neil@brown.name>
Wed, 30 Aug 2023 23:37:51 +0000 (09:37 +1000)
If menu it attached with are '1', the "value" passed to the action
command will be shown right-justified.  This can be used to display
hot keys.
If "value" starts with a space, it is assumed the action doesn't have a
shortcut, and the value is suppressed.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
lib-menu.c

index b8cc83c9618f3c3015278d714abfcbabb5a73878..b5a5faff7bd09e00c38ed8fc8fe9dd11dcc08b2c 100644 (file)
@@ -17,7 +17,7 @@ the file.
       from-* query
 - [X] Disable <hide> if cursor is in the hidden region.
 - [X] fill mode to handle all punctuation at start of this line
-- [ ] Enable lib-menu to show short-cut keys
+- [X] Enable lib-menu to show short-cut keys
 - [ ] Add menu-bar to lib-menu.  Pop it up on F10 with simple commands
 - [ ] attach an extensible menu to the selection
         copy, paste-in, QR, git-view
@@ -804,7 +804,7 @@ Module features
 
 ### lib-menu
 
-- [ ] Enable lib-menu to show short-cut keys
+- [X] Enable lib-menu to show short-cut keys
 - [ ] menu-bar to which we can add menus from which commands are sent
 - [ ] track movement so entry under cursor can be highlighted
 - [ ] support positioning above the target is no space below.
index 201f3e4555ce30235688686b659a4faa21709d86..b4bcfef16518a68f3e281e95e43b98f5a887ed45 100644 (file)
@@ -52,6 +52,16 @@ DEF_CMD(menu_attr)
                free(s);
                return 1;
        }
+       if (ci->str && strcmp(ci->str, "shortcut") == 0) {
+               char *s = call_ret(str, "doc:get-attr", ci->home,
+                                  0, ci->mark, "value");
+               /* a leading space on 'value' suppresses listing as a shortcut */
+               char *v = (s && *s != ' ') ? s : "";
+               comm_call(ci->comm2, "cb", ci->focus, 0, ci->mark,
+                         v, 0, NULL, ci->str);
+               free(s);
+               return 1;
+       }
        return Efallthrough;
 }
 
@@ -113,7 +123,11 @@ 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", "<%BG><action-activate:menu-select>%name</></>");
+       if (ci->num & 1)
+               /* show the 'value' - presumably a key name */
+               attr_set_str(&docp->attrs, "line-format", "<%BG><action-activate:menu-select>%name<rtab>%shortcut</></>");
+       else
+               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", "");