From 840c01b37cebedb438032aa51a870093ebf22f1b Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 3 Sep 2023 21:56:16 +1000 Subject: [PATCH] menu: support detaching the doc from a menu. It might be use to create a menu doc once, and re-use it. For this to work we need to be able to create a menu with an existing doc. A new mode for attach-menu allows this. It will also be useful to be able to edit the detached document so add global commands menu:add and menu:clear which do this. Signed-off-by: NeilBrown --- data/modules.ini | 6 ++++-- lib-menu.c | 48 ++++++++++++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/data/modules.ini b/data/modules.ini index ec3b800a..5bb1ab85 100644 --- a/data/modules.ini +++ b/data/modules.ini @@ -143,7 +143,10 @@ lib-keymap = attach-keymap lib-libevent = attach-libevent lib-linefilter = attach-linefilter lib-markup = attach-markup -lib-menu = attach-menu +lib-menu = + attach-menu + menu:add + menu:clear lib-messageline = attach-messageline lib-renderline = attach-renderline lib-rfc822header = attach-rfc822header @@ -154,7 +157,6 @@ lib-glibevents = attach-glibevents lib-shellcmd = attach-shellcmd lib-unicode-names = Unicode-names -lib-menu = attach-menu lib-askpass = AskPass lib-test-markup = diff --git a/lib-menu.c b/lib-menu.c index ab21cb46..f9202bc5 100644 --- a/lib-menu.c +++ b/lib-menu.c @@ -121,34 +121,42 @@ DEF_CMD(menu_attach) /* ->str gives the "mode" * D means per-display menu, not per-pane * V means show value in menu as well as name + * F means to use the focus as the doc, and its + * parent as the focus. */ struct pane *docp, *p, *p2; /* Multi-line temporary popup with x,y location provided. */ const char *mode = "Mtx"; const char *mmode = ci->str ?: ""; + struct pane *focus = ci->focus; if (strchr(mmode, 'D')) /* per-display, not per-pane */ mode = "DMtx"; - docp = call_ret(pane, "attach-doc-list", ci->focus); - if (!docp) - return Efail; - call("doc:set:autoclose", docp, 1); - attr_set_str(&docp->attrs, "render-simple", "format"); - attr_set_str(&docp->attrs, "heading", ""); - if (strchr(mmode, 'V')) - /* show the 'action' - 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", ""); - attr_set_str(&docp->attrs, "background", "color:white-80"); - p = call_ret(pane, "PopupTile", ci->focus, 0, NULL, mode, + if (strchr(mmode, 'F')) { + docp = focus; + focus = focus->parent; + } else { + docp = call_ret(pane, "attach-doc-list", ci->focus); + if (!docp) + return Efail; + call("doc:set:autoclose", docp, 1); + attr_set_str(&docp->attrs, "render-simple", "format"); + attr_set_str(&docp->attrs, "heading", ""); + if (strchr(mmode, 'V')) + /* show the 'action' - 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", ""); + attr_set_str(&docp->attrs, "background", "color:white-80"); + } + p = call_ret(pane, "PopupTile", focus, 0, NULL, mode, 0, NULL, NULL, ci->x, ci->y); if (!p) return Efail; @@ -186,4 +194,8 @@ void edlib_init(struct pane *ed safe) menu_init_map(); call_comm("global-set-command", ed, &menu_attach, 0, NULL, "attach-menu"); + call_comm("global-set-command", ed, &menu_add, + 0, NULL, "menu:add"); + call_comm("global-set-command", ed, &menu_clear, + 0, NULL, "menu:clear"); } -- 2.39.5