From 5b86dfaedad364a6ccc427893e8aad9d00d78124 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 25 Jan 2016 13:42:13 +1100 Subject: [PATCH] doc: make it possible to delete a view by number As we are deprecating the 'notifier', don't depend on it for deletion. Signed-off-by: NeilBrown --- core-doc.c | 26 +++++++++++++++++++++++--- core.h | 12 +++++++++++- lib-line-count.c | 2 +- render-lines.c | 2 +- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/core-doc.c b/core-doc.c index 0148730a..3f0558e1 100644 --- a/core-doc.c +++ b/core-doc.c @@ -69,7 +69,7 @@ static int do_doc_add_view(struct doc *d, struct command *c) return ret; } -static void do_doc_del_view(struct doc *d, struct command *c) +static void do_doc_del_view_notifier(struct doc *d, struct command *c) { /* This view should only have points on the list, not typed * marks. Just delete everything and clear the 'notify' pointer @@ -90,6 +90,23 @@ static void do_doc_del_view(struct doc *d, struct command *c) } } +static void do_doc_del_view(struct doc *d, int i) +{ + /* This view should only have points on the list, not typed + * marks. Just delete everything and clear the 'notify' pointer + */ + if (i < 0 || i >= d->nviews) + return; + d->views[i].notify = NULL; + d->views[i].state = 0; + while (!tlist_empty(&d->views[i].head)) { + struct tlist_head *tl = d->views[i].head.next; + if (TLIST_TYPE(tl) != GRP_LIST) + abort(); + tlist_del_init(tl); + } +} + static int do_doc_find_view(struct doc *d, struct command *c) { int i; @@ -458,9 +475,12 @@ DEF_CMD(doc_handle) } if (strcmp(ci->key, "doc:del-view") == 0) { - if (!ci->comm2) + if (ci->numeric >= 0) + do_doc_del_view(dd->doc, ci->numeric); + else if (ci->comm2) + do_doc_del_view_notifier(dd->doc, ci->comm2); + else return -1; - do_doc_del_view(dd->doc, ci->comm2); return 1; } diff --git a/core.h b/core.h index e957b937..562717ce 100644 --- a/core.h +++ b/core.h @@ -461,11 +461,21 @@ static inline int doc_add_view(struct pane *p, struct command *c) return ret - 1; } -static inline void doc_del_view(struct pane *p, struct command *c) +static inline void doc_del_view(struct pane *p, int num) { struct cmd_info ci = {0}; ci.focus = p; ci.key = "doc:del-view"; + ci.numeric = num; + key_handle(&ci); +} + +static inline void doc_del_view_notifier(struct pane *p, struct command *c) +{ + struct cmd_info ci = {0}; + ci.focus = p; + ci.key = "doc:del-view"; + ci.numeric = -1; ci.comm2 = c; key_handle(&ci); } diff --git a/lib-line-count.c b/lib-line-count.c index a2c9654d..455f067a 100644 --- a/lib-line-count.c +++ b/lib-line-count.c @@ -96,7 +96,7 @@ DEF_CMD(count_notify) return 0; while ((m = vmark_first(ci->home, i)) != NULL) mark_free(m); - doc_del_view(ci->home, ci->comm); + doc_del_view_notifier(ci->home, ci->comm); } return 0; } diff --git a/render-lines.c b/render-lines.c index 78e2392c..a885500a 100644 --- a/render-lines.c +++ b/render-lines.c @@ -804,7 +804,7 @@ DEF_CMD(render_lines_close) } rl->pane = NULL; - doc_del_view(p, &rl->type); + doc_del_view(p, rl->typenum); p->data = NULL; p->handle = NULL; free(rl); -- 2.39.5