]> git.neil.brown.name Git - edlib.git/commitdiff
Discard DocLeaf - use new pane_leaf() instead.
authorNeilBrown <neil@brown.name>
Sat, 9 Sep 2023 03:55:48 +0000 (13:55 +1000)
committerNeilBrown <neil@brown.name>
Mon, 11 Sep 2023 02:16:50 +0000 (12:16 +1000)
pane_leaf() follows children of the pane as long as there is only one
with ->z==0.  Returns the final pane found.

Use this together with DocPane instead the hackish DocLeaf.

Possible some pane_focus() should be changed to pane_leaf().

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
core-pane.c
core.h
lang-python.c
lib-tile.c
python/lib-diff.py
python/lib-make.py

index 6fbb9ae77bcb1459cdf5b10a70da9b819680f572..7525cca16f4ed5362548ae0c266986f2a64d009b 100644 (file)
@@ -138,7 +138,7 @@ Core features
 - [ ] send warning message when recursive notification is prohibited.
        editor:notify:Message:broadcast
 - [ ] Make DEF_CB really different from DEF_CMD and ensure it is used properly.
-- [ ] is DocLeaf really a good idea?  Maybe panes should have 'leafward'
+- [X] is DocLeaf really a good idea?  Maybe panes should have 'leafward'
       pointer separate to 'focus'?  Maybe panes could have optional
       'child' method which returns main child - pane_focus() calls that.
       Maybe pane_focus() find a pane with z=0 and matching w,h ??
@@ -149,6 +149,7 @@ Core features
       messageline_msg which wants to allow fallthrough, but needs to acknowledge.
       How can I resolve this? Use Efallthrough as -1.
 - [ ] make a doc read-only if dir doesn't exist or isn't writable
+- [ ] change some pane_focus() to pane_leaf() where appropriate.
 - [ ] account all mem allocation types separately, and (optionally) report
       stats regularly
 - [ ] document the use of doc:replaced.  What are the two
index b1da57dc91d20b4858c29310dec4fa4bb901bd0f..4594c7ed0463720206352726a7389d0647efee8d 100644 (file)
@@ -893,6 +893,34 @@ struct pane *pane_my_child(struct pane *p, struct pane *c)
        return c;
 }
 
+struct pane * safe pane_leaf(struct pane *p safe)
+{
+       /* Find the only child with ->z of zero,
+        * and recurse on that.
+        * This ignores popups and stops when a pane
+        * splits.
+        */
+       struct pane *l = p;
+
+       while (l) {
+               struct pane *c;
+               p = l;
+               l = NULL;
+               list_for_each_entry(c, &p->children, siblings) {
+                       if (c->z)
+                               continue;
+                       if (!l) {
+                               l = c;
+                               continue;
+                       }
+                       /* Two candidates, so further leaf - stop here */
+                       l = NULL;
+                       break;
+               }
+       }
+       return p;
+}
+
 DEF_CB(take_simple)
 {
        struct call_return *cr = container_of(ci->comm, struct call_return, c);
diff --git a/core.h b/core.h
index c166973a99a874348b24fdfdd44e83c249206b44..af62ada03d6cf235fa2f1c654afb3ed49ee307a0 100644 (file)
--- a/core.h
+++ b/core.h
@@ -508,6 +508,7 @@ static inline int pane_attr_get_int(struct pane *p safe, const char *key safe,
        return rv;
 }
 void pane_free(struct pane *p safe);
+struct pane * safe pane_leaf(struct pane *p safe);
 
 /* Inlines */
 
index ecd746e511913e85248f18bae3c610fcba21bdea..2152dcd747cc4669030526976b9ed92b1531cea5 100644 (file)
@@ -1626,6 +1626,8 @@ static Pane *pane_getpane(Pane *p safe, char *which safe)
                new = pane_root(p->pane);
        if (*which == 'F')
                new = pane_focus(p->pane);
+       if (*which == 'L')
+               new = pane_leaf(p->pane);
        if (new == NULL) {
                Py_INCREF(Py_None);
                newpane = (Pane*)Py_None;
@@ -1713,7 +1715,10 @@ static const PyGetSetDef pane_getseters[] = {
         "Root pane", "r"},
        {"final_focus",
         (getter)pane_getpane, (setter)pane_nosetpane,
-        "Leaf pane", "F"},
+        "Final focus pane", "F"},
+       {"leaf",
+        (getter)pane_getpane, (setter)pane_nosetpane,
+        "Leaf pane", "L"},
        {NULL}  /* Sentinel */
 };
 
index b48f1466dd0a0278daf5c407a05952caf0852ef7..e5c85c7031a12b552db007f138c0cf77b6c7fbe8 100644 (file)
@@ -942,6 +942,8 @@ DEF_CMD(tile_doc)
        }
        /* Find where 'focus' is open */
        name = pane_attr_get(ci->focus, "doc-name");
+       if (!name)
+               return Efallthrough;
        if (!ti->leaf)
                ti = tile_first(ti);
        t = ti;
@@ -951,12 +953,11 @@ DEF_CMD(tile_doc)
                t = list_next_entry(t, tiles);
                f = t->content;
                if (f) {
-                       f = pane_focus(f);
+                       f = pane_leaf(f);
                        n = pane_attr_get(f, "doc-name");
-                       if (name && n && strcmp(n, name) == 0)
+                       if (n && strcmp(n, name) == 0)
                                return comm_call(ci->comm2, "callback:pane",
-                                                strcmp(ci->key, "DocLeaf") == 0
-                                                ? f : t->p,
+                                                t->p,
                                                 0, NULL, t->name);
                }
        } while (t != ti);
@@ -1052,7 +1053,6 @@ void edlib_init(struct pane *ed safe)
        key_add(tile_map, "OtherPane", &tile_other);
        key_add(tile_map, "ThisPane", &tile_this);
        key_add(tile_map, "DocPane", &tile_doc);
-       key_add(tile_map, "DocLeaf", &tile_doc);
        key_add(tile_map, "RootPane", &tile_root);
        key_add(tile_map, "Clone", &tile_clone);
        key_add(tile_map, "Child-Notify", &tile_child_notify);
index 08cb60dce6d7a69c0e0774ab8b9adea361ef4bbe..ff4276733367ff55cadd117d878416c24fffdd8f 100644 (file)
@@ -304,7 +304,9 @@ class DiffPane(edlib.Pane):
             focus.call("Message", "File %s not found" % fname)
             return edlib.Efail
 
-        par = focus.call("DocLeaf", d, ret='pane')
+        par = focus.call("DocPane", d, ret='pane')
+        if par:
+            par = par.leaf
         if not par:
             par = focus.call("OtherPane", d, ret='pane')
             if not par:
index ed9ea341543286dffdb6f4a7d7d3faa846475f5f..6725d3acb66e72734bcff5979f9db2c59d964af0 100644 (file)
@@ -466,9 +466,9 @@ class MakePane(edlib.Pane):
         else:
             in_popup = True
         if where in ['OtherPane', 'AnyPane']:
-            par = focus.call("DocLeaf", d, ret='pane')
+            par = focus.call("DocPane", d, ret='pane')
             if par:
-                pass
+                par = par.leaf
             elif where == 'OtherPane':
                 pane = focus.call(where, ret='pane')
             else: