From 7aa1a5f63d296d4f6a1bedf4351753b0f9a7cc26 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 31 Aug 2023 09:28:40 +1000 Subject: [PATCH] menu: allow short-cut keys to be shown. 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 --- DOC/TODO.md | 4 ++-- lib-menu.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/DOC/TODO.md b/DOC/TODO.md index b8cc83c9..b5a5faff 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -17,7 +17,7 @@ the file. from-* query - [X] Disable 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. diff --git a/lib-menu.c b/lib-menu.c index 201f3e45..b4bcfef1 100644 --- a/lib-menu.c +++ b/lib-menu.c @@ -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>%name"); + if (ci->num & 1) + /* show the 'value' - presumably a key name */ + attr_set_str(&docp->attrs, "line-format", "<%BG>%name%shortcut"); + else + 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", ""); -- 2.39.5