]> git.neil.brown.name Git - edlib.git/commitdiff
Add notifier to non-home panes on a doc.
authorNeilBrown <neil@brown.name>
Fri, 27 Nov 2015 04:21:01 +0000 (15:21 +1100)
committerNeilBrown <neil@brown.name>
Fri, 27 Nov 2015 04:34:44 +0000 (15:34 +1100)
Use this to clean up and install a new document when the old one dies.

Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core-mark.c
core.h

index 88ee45dca5e2388c134fc48ad8072da79d26df01..81309623ab4f71b0ef2688ac242a767a1f3c81f3 100644 (file)
@@ -351,18 +351,6 @@ DEF_CMD(doc_handle)
        struct doc_data *dd = ci->home->data;
        int ret;
 
-       /* This is a hack - I should use a watcher, but I don't have
-        * anywhere to store it.
-        * FIXME make this optional
-        */
-       if (strcmp(ci->key, "Refresh") == 0) {
-               struct pane *p = pane_child(ci->home);
-               if (p)
-                       return 0; /* use default handling */
-               p = editor_choose_doc(pane2ed(ci->home));
-               doc_attach_view(ci->home, p, NULL);
-               return 0;
-       }
        if (strcmp(ci->key, "Clone") == 0) {
                struct pane *p = doc_attach(ci->focus, dd->doc);
                struct pane *c = pane_child(ci->home);
@@ -374,9 +362,12 @@ DEF_CMD(doc_handle)
        }
 
        if (strcmp(ci->key, "Close") == 0) {
+               doc_del_view(ci->home, &dd->notify);
                if (ci->home->point)
                        mark_free(ci->home->point);
                ci->home->point = NULL;
+               free(dd);
+               ci->home->data = NULL;
                return 1;
        }
 
@@ -447,6 +438,35 @@ DEF_CMD(doc_handle)
        return ret;
 }
 
+DEF_CMD(doc_notify)
+{
+       if (strcmp(ci->key, "Release") == 0) {
+               /* This pane has to go away */
+               struct doc_data *dd = container_of(ci->comm, struct doc_data, notify);
+               struct pane *par = dd->pane, *p;
+
+               doc_del_view(ci->home, ci->comm);
+               /* Need another document to fill this pane. */
+               /* FIXME make this conditional */
+               p = pane_child(par);
+               if (p)
+                       pane_close(p);
+               p = editor_choose_doc(pane2ed(ci->home));
+               if (!p)
+                       return 1;
+               doc_attach_view(par, p, NULL);
+               p = pane_child(par);
+               if (p) {
+                       pane_subsume(p, par);
+                       dd = par->data;
+                       dd->pane = par;
+                       pane_close(p);
+               }
+               return 1;
+       }
+       return 0;
+}
+
 struct pane *doc_attach(struct pane *parent, struct doc *d)
 {
        struct pane *p;
@@ -457,6 +477,12 @@ struct pane *doc_attach(struct pane *parent, struct doc *d)
        p = pane_register(parent, 0, &doc_handle, dd, NULL);
        if (!d->home)
                d->home = p;
+       else {
+               /* non-home panes need to be notified so they can self-destruct */
+               dd->notify = doc_notify;
+               doc_add_view(p, &dd->notify, 0);
+       }
+       dd->pane = p;
        d->ed = pane2ed(parent);
        doc_promote(d);
        return p;
index 14398b1cacdccb4d3f1824c3ff78b56518a25a07..3601b679724f6c4a03450ab350b067e321cf3f07 100644 (file)
@@ -391,12 +391,13 @@ struct mark *doc_prev_mark_all(struct mark *m)
 struct mark *doc_new_mark(struct doc *d, int view)
 {
        struct mark *ret;
+       int size = sizeof(*ret);
 
        if (view == MARK_POINT || view >= d->nviews || d->views[view].notify == NULL)
                return NULL;
-       ret = malloc(sizeof(*ret));
-       ret->rpos = 0;
-       ret->attrs = NULL;
+       if (view > 0)
+               size += d->views[view].space;
+       ret = calloc(size, 1);
        ret->viewnum = view;
        __mark_reset(d, ret, 1, 0);
        return ret;
diff --git a/core.h b/core.h
index 97bae48f7e6778ae72f9c230c58ba26f0f5a9fce..2ef78ee2534bafb73a45c6f95911a1b693ce52f8 100644 (file)
--- a/core.h
+++ b/core.h
@@ -60,11 +60,17 @@ struct pane {
        struct attrset          *attrs;
 };
 
+struct command {
+       int     (*func)(struct cmd_info *ci);
+};
+
 /* this is ->data for a document pane.  Only core-doc and
  * individual document handlers can know about this.
  */
 struct doc_data {
        struct doc              *doc;
+       struct command          notify;
+       struct pane             *pane;
 };
 
 struct display {
@@ -235,9 +241,6 @@ void attr_free(struct attrset **setp);
 
 
 /* Commands */
-struct command {
-       int     (*func)(struct cmd_info *ci);
-};
 struct lookup_cmd {
        struct command  c;
        struct map      **m;