]> git.neil.brown.name Git - edlib.git/commitdiff
Change Display:set-noclose to Display:set:no-close and store in attribute.
authorNeilBrown <neil@brown.name>
Fri, 25 Aug 2023 04:56:48 +0000 (14:56 +1000)
committerNeilBrown <neil@brown.name>
Fri, 25 Aug 2023 05:35:37 +0000 (15:35 +1000)
Using an attribute to store the no-close string simplifies code, and
using "Display:set:" is similar to "doc:set:" and will soon be used to
set any attribute at the display level.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/Calls
DOC/Developer/07-displays.md
display-ncurses.c
display-x11-xcb.c
edlib.c
python/display-pygtk.py
python/lib-server.py

index 1295ac8aefb32e9f11079721e7885c09cdc7d774..84c20e8262846f160e6e39415ed7874ef461dffd 100644 (file)
--- a/DOC/Calls
+++ b/DOC/Calls
@@ -152,7 +152,7 @@ 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-noclose
+## Display:set:no-close
 
 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,
index 77304a7026000187f833ed1f30b79a37047d28af..606eb0ac382d68f503fb24d8ba576fbcbd26d71b 100644 (file)
@@ -98,7 +98,7 @@ Draw:image
 ## Display management commands
 
 Display:close
-Display:set-noclose
+Display:set:no-close
 Display:external-viewer
 Display:fullscreen
 Display:new
index 1e854f42bcf0190595a49bad9f4f5cd7b5867d19..167048cd8c2fcd3c5a861b74b0ff8ff0975e06c9 100644 (file)
@@ -64,7 +64,6 @@ struct display_data {
        SCREEN                  *scr;
        FILE                    *scr_file;
        int                     is_xterm;
-       char                    *noclose;
        struct col_hash         *col_hash;
        int                     report_position;
        long                    last_event;
@@ -442,10 +441,10 @@ DEF_CMD(nc_close_display)
 {
        /* If this is only display, then refuse to close this one */
        struct call_return cr;
-       struct display_data *dd = &ci->home->data;
+       char *nc = attr_find(ci->home->attrs, "no-close");
 
-       if (dd->noclose) {
-               call("Message", ci->focus, 0, NULL, dd->noclose);
+       if (nc) {
+               call("Message", ci->focus, 0, NULL, nc);
                return 1;
        }
 
@@ -466,12 +465,7 @@ DEF_CMD(nc_close_display)
 
 DEF_CMD(nc_set_noclose)
 {
-       struct display_data *dd = &ci->home->data;
-
-       free(dd->noclose);
-       dd->noclose = NULL;
-       if (ci->str)
-               dd->noclose = strdup(ci->str);
+       attr_set_str(&ci->home->attrs, "no-close", ci->str);
        return 1;
 }
 
@@ -1824,7 +1818,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-noclose", &nc_set_noclose);
+       key_add(nc_map, "Display:set:no-close", &nc_set_noclose);
        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);
index b5bd7aa8991b923e6ac7dbb4c67779293d575b14..63c0e875dcdcc3bd08af72e47a084c8ddc927cc1 100644 (file)
@@ -195,7 +195,6 @@ struct xcb_data {
        cairo_t                 *cairo safe;
        cairo_surface_t         *surface safe;
        PangoFontDescription    *fd safe;
-       char                    *noclose;
        int                     charwidth, lineheight;
        cairo_region_t          *need_update;
 
@@ -447,10 +446,10 @@ DEF_CMD(xcb_close_display)
 {
        /* If this is only display, then refuse to close this one */
        struct call_return cr;
-       struct xcb_data *xd = &ci->home->data;
+       char *nc = attr_find(ci->home->attrs, "no-close");
 
-       if (xd->noclose) {
-               call("Message", ci->focus, 0, NULL, xd->noclose);
+       if (nc) {
+               call("Message", ci->focus, 0, NULL, nc);
                return 1;
        }
        cr.c = cnt_disp;
@@ -466,12 +465,7 @@ DEF_CMD(xcb_close_display)
 
 DEF_CMD(xcb_set_noclose)
 {
-       struct xcb_data *xd = &ci->home->data;
-
-       free(xd->noclose);
-       xd->noclose = NULL;
-       if (ci->str)
-               xd->noclose = strdup(ci->str);
+       attr_set_str(&ci->home->attrs, "no-close", ci->str);
        return 1;
 }
 
@@ -589,7 +583,6 @@ DEF_CMD(xcb_free)
        cairo_surface_destroy(xd->surface);
        free(xd->display);
        free(xd->disp_auth);
-       free(xd->noclose);
        xcb_disconnect(xd->conn);
        if (xd->need_update)
                cairo_region_destroy(xd->need_update);
@@ -2010,7 +2003,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-noclose", &xcb_set_noclose);
+       key_add(xcb_map, "Display:set:no-close", &xcb_set_noclose);
        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/edlib.c b/edlib.c
index c4e8d47c20270d46f2b0ebaf54438d3247395981..ee70bab536b2fcb04f432fbb117805c58a6e223c 100644 (file)
--- a/edlib.c
+++ b/edlib.c
@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
                             0, NULL, getenv("XAUTHORITY"));
                        if (!first_window)
                                first_window = p;
-                       call("Display:set-noclose", p, 1, NULL,
+                       call("Display:set:no-close", p, 1, NULL,
                             "Cannot close primary display");
                }
        }
index 6d2367b56344ce67160db0efa16ba4701684d6a0..7d2c9954f9f27f4be910f2e3b7d0bc2d24c2b18d 100644 (file)
@@ -58,7 +58,6 @@ class EdDisplay(edlib.Pane):
         self.w = int(self.charwidth * 80.0)
         self.h = int(self.lineheight * 24.0)
         self.call("editor:request:all-displays")
-        self.noclose = None
         self.last_event = 0
         self.win.show()
 
@@ -74,8 +73,9 @@ class EdDisplay(edlib.Pane):
 
     def handle_close_window(self, key, focus, **a):
         "handle:Display:close"
-        if self.noclose:
-            focus.call("Message", self.noclose)
+        nc = self['no-close']
+        if nc:
+            focus.call("Message", nc)
             return 1
         x = []
         focus.call("editor:notify:all-displays", lambda key,**a:x.append(1))
@@ -85,9 +85,9 @@ class EdDisplay(edlib.Pane):
             focus.call("Message", "Cannot close only window.")
         return 1
 
-    def handle_set_noclose(self, key, str, **a):
-        "handle:Display:set-noclose"
-        self.noclose = str
+    def handle_set_noclose(self, key, str1, **a):
+        "handle:Display:set:no-close"
+        self['no-close'] = str1
         return 1
 
     def handle_fullscreen(self, key, num, **a):
index 49714c292889301486a955c9dc8f1f6577579e36..c1f9294d770d466592745e417c59953af704bda3 100755 (executable)
@@ -123,7 +123,7 @@ if sys.argv[0] == "":
                     self.add_notify(d, "Notify:Close")
                     self.doc = d
                     if self.term:
-                        self.term.call("Display:set-noclose",
+                        self.term.call("Display:set:no-close",
                                        "Cannot close display until document done - use 'C-x #'")
                     self.sock.send(b"OK")
                     return 1
@@ -166,7 +166,7 @@ if sys.argv[0] == "":
                     return 1
                 if cmd == "close":
                     if self.disp:
-                        self.disp.call("Display:set-noclose")
+                        self.disp.call("Display:set:no-close")
                         self.disp.call("Display:close")
                         self.disp = None
                     self.call("event:free", self.read)
@@ -200,7 +200,7 @@ if sys.argv[0] == "":
                 # same as doc:done
                 self.doc = None
                 if self.term:
-                    self.term.call("Display:set-noclose")
+                    self.term.call("Display:set:no-close")
                     self.term.call("Display:close")
                 self.sock.send(b"Done")
             return 1
@@ -209,7 +209,7 @@ if sys.argv[0] == "":
             "handle:doc:done"
             if str != "test":
                 if self.term:
-                    self.term.call("Display:set-noclose")
+                    self.term.call("Display:set:no-close")
                     self.term.call("Display:close")
                 self.sock.send(b"Done")
             return 1