From: NeilBrown Date: Thu, 10 Dec 2015 06:48:13 +0000 (+1100) Subject: Use new notifier to close all views on a document when destroyed. X-Git-Tag: lca2016~69 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=e6f589cb92ad280d8cafd4e64cfd2bd936aa5ec3;p=edlib.git Use new notifier to close all views on a document when destroyed. Signed-off-by: NeilBrown --- diff --git a/core-doc.c b/core-doc.c index 6ae51883..f75aa471 100644 --- a/core-doc.c +++ b/core-doc.c @@ -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++) diff --git a/core-pane.c b/core-pane.c index 9c762dcd..fddc7086 100644 --- a/core-pane.c +++ b/core-pane.c @@ -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 393343c6..87f4cc28 100644 --- 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);