]> git.neil.brown.name Git - edlib.git/commitdiff
menu: support detaching the doc from a menu.
authorNeilBrown <neil@brown.name>
Sun, 3 Sep 2023 11:56:16 +0000 (21:56 +1000)
committerNeilBrown <neil@brown.name>
Mon, 4 Sep 2023 23:07:53 +0000 (09:07 +1000)
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 <neil@brown.name>
data/modules.ini
lib-menu.c

index ec3b800a53d76550280a58ed17cc714effed9cd5..5bb1ab85bd524182157cb4b543a2d13f06a8ccd2 100644 (file)
@@ -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 =
index ab21cb46b69ca2c480ab6daacc6ced0a0eb3c747..f9202bc538ad2533648833a6afcb60ada425217a 100644 (file)
@@ -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><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", "");
-       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><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", "");
+               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");
 }