]> git.neil.brown.name Git - edlib.git/commitdiff
Use new notifier to close all views on a document when destroyed.
authorNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 06:48:13 +0000 (17:48 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 06:48:13 +0000 (17:48 +1100)
Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core-pane.c
core.h

index 6ae51883ac65cdb580c28342925214a9f014c65d..f75aa47112a319dd74ab2bad082f3dc937a8346b 100644 (file)
@@ -371,6 +371,29 @@ DEF_CMD(doc_handle)
        struct doc_data *dd = ci->home->data;
        int ret;
 
+       if (strcmp(ci->key, "Notify:Close") == 0) {
+               /* This pane has to go away */
+               struct doc_data *dd = ci->home->data;
+               struct pane *par = ci->home, *p;
+
+               /* 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;
+       }
        if (strcmp(ci->key, "Clone") == 0) {
                struct pane *p = doc_attach(ci->focus, dd->doc);
                struct pane *c = pane_child(ci->home);
@@ -384,7 +407,6 @@ DEF_CMD(doc_handle)
        }
 
        if (strcmp(ci->key, "Close") == 0) {
-               doc_del_view(ci->home, &dd->notify);
                if (dd->point)
                        mark_free(dd->point);
                free(dd);
@@ -471,35 +493,6 @@ 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;
@@ -512,8 +505,7 @@ struct pane *doc_attach(struct pane *parent, struct doc *d)
                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);
+               pane_add_notify(p, d->home, "Notify:Close");
        }
        dd->point = NULL;
        dd->pane = p;
@@ -956,6 +948,7 @@ static int do_doc_destroy(struct doc *d)
                d->deleting = 2; /* tell editor choose doc that this
                                  * is available if absolutely needed */
        doc_close_views(d);
+       pane_notify_close(d->home);
        d->deleting = 0;
 
        for (i = 0; i < d->nviews; i++)
index 9c762dcd811583d1037ec79a4852a23cda528c25..fddc7086a44036b6b183ce339f8127c286bf6375 100644 (file)
@@ -180,12 +180,12 @@ static void pane_drop_notifiers(struct pane *p)
        }
 }
 
-static void pane_notify_close(struct pane *p)
+void pane_notify_close(struct pane *p)
 {
        while (!list_empty(&p->notifiees)) {
-               struct notifier *n = list_first_entry(&p->notifiers,
+               struct notifier *n = list_first_entry(&p->notifiees,
                                                      struct notifier,
-                                                     notifiee_link);
+                                                     notifier_link);
                list_del_init(&n->notifiee_link);
                list_del_init(&n->notifier_link);
                if (strcmp(n->notification, "Notify:Close") == 0)
diff --git a/core.h b/core.h
index 393343c69a1c192d29021c16566a0a5f54090e70..87f4cc28443aa436abb7a7d331bd80eb2683e417 100644 (file)
--- a/core.h
+++ b/core.h
@@ -74,7 +74,6 @@ void pane_add_notify(struct pane *target, struct pane *source, char *msg);
  */
 struct doc_data {
        struct doc              *doc;
-       struct command          notify;
        struct pane             *pane;
        struct mark             *point;
 };
@@ -324,6 +323,7 @@ void pane_init(struct pane *p, struct pane *par, struct list_head *here);
 void pane_reparent(struct pane *p, struct pane *newparent);
 void pane_subsume(struct pane *p, struct pane *parent);
 void pane_close(struct pane *p);
+void pane_notify_close(struct pane *p);
 int pane_clone(struct pane *from, struct pane *parent);
 void pane_resize(struct pane *p, int x, int y, int w, int h);
 void pane_check_size(struct pane *p);