From: NeilBrown Date: Fri, 25 Aug 2023 05:04:28 +0000 (+1000) Subject: Introduce generic Display:set: X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=d694546eeb651499b2241e298fc669568a4ae9e9;p=edlib.git Introduce generic Display:set: Display:set: can be used to set any attribute on the display pane. The attr name can be in str2, or following Display:set: in the key. Signed-off-by: NeilBrown --- diff --git a/DOC/Calls b/DOC/Calls index 84c20e82..a9400513 100644 --- a/DOC/Calls +++ b/DOC/Calls @@ -152,12 +152,13 @@ display can be awkward. This is a request for the display to close - may be rejected if it is the only display left. -## Display:set:no-close +## Display:set:ATTR -This comes with a reason in str1. If a Display:close request arrives -when the most recent set-noclose request contained a non-empty string, -that string should be reported via a message, an the close should be -rejected. +Set any attribute on the display pane. + +The attribute "no-close" affects closing. If a Display:close request +arrives when "no-close" attribute is a non-empty string, that string +should be reported via a message, and the close should be rejected. ## Display:external-viewer diff --git a/display-ncurses.c b/display-ncurses.c index 167048cd..3178b355 100644 --- a/display-ncurses.c +++ b/display-ncurses.c @@ -463,9 +463,13 @@ DEF_CMD(nc_close_display) return 1; } -DEF_CMD(nc_set_noclose) +DEF_CMD(nc_set_attr) { - attr_set_str(&ci->home->attrs, "no-close", ci->str); + const char *attr = ci->str2; + + if (!attr) + attr = ksuffix(ci, "Display:set:"); + attr_set_str(&ci->home->attrs, attr, ci->str); return 1; } @@ -1818,7 +1822,7 @@ void edlib_init(struct pane *ed safe) nc_map = key_alloc(); key_add(nc_map, "Display:refresh", &force_redraw); key_add(nc_map, "Display:close", &nc_close_display); - key_add(nc_map, "Display:set:no-close", &nc_set_noclose); + key_add_prefix(nc_map, "Display:set:", &nc_set_attr); key_add(nc_map, "Display:external-viewer", &nc_external_viewer); key_add(nc_map, "Close", &nc_close); key_add(nc_map, "Draw:clear", &nc_clear); diff --git a/display-x11-xcb.c b/display-x11-xcb.c index 63c0e875..fe3fd377 100644 --- a/display-x11-xcb.c +++ b/display-x11-xcb.c @@ -463,9 +463,13 @@ DEF_CMD(xcb_close_display) return 1; } -DEF_CMD(xcb_set_noclose) +DEF_CMD(xcb_set_attr) { - attr_set_str(&ci->home->attrs, "no-close", ci->str); + const char *attr = ci->str2; + + if (!attr) + attr = ksuffix(ci, "Display:set:"); + attr_set_str(&ci->home->attrs, attr, ci->str); return 1; } @@ -2003,7 +2007,7 @@ void edlib_init(struct pane *ed safe) xcb_map = key_alloc(); key_add(xcb_map, "Display:close", &xcb_close_display); - key_add(xcb_map, "Display:set:no-close", &xcb_set_noclose); + key_add_prefix(xcb_map, "Display:set:", &xcb_set_attr); key_add(xcb_map, "Display:external-viewer", &xcb_external_viewer); key_add(xcb_map, "Display:fullscreen", &xcb_fullscreen); key_add(xcb_map, "Display:new", &xcb_new_display); diff --git a/python/display-pygtk.py b/python/display-pygtk.py index 7d2c9954..bb09ca96 100644 --- a/python/display-pygtk.py +++ b/python/display-pygtk.py @@ -85,9 +85,12 @@ class EdDisplay(edlib.Pane): focus.call("Message", "Cannot close only window.") return 1 - def handle_set_noclose(self, key, str1, **a): - "handle:Display:set:no-close" - self['no-close'] = str1 + def handle_set_noclose(self, key, str1, str2, **a): + "handle-prefix:Display:set:" + attr = str2 + if not attr: + attr = key[12:] + self[attr] = str1 return 1 def handle_fullscreen(self, key, num, **a):