From 6b4a25a3d0b911a8c844aba0e5f6f6d2fe60573e Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 25 Nov 2015 18:21:27 +1100 Subject: [PATCH] Split a 'doc' pane aways from the 'view' panes. They really are different things. Signed-off-by: NeilBrown --- core-doc.c | 35 ++++++++++++++++++++++++++++++++++- core-pane.c | 16 ++++++++++++++++ lib-view.c | 48 ++++++++++++------------------------------------ 3 files changed, 62 insertions(+), 37 deletions(-) diff --git a/core-doc.c b/core-doc.c index 0a43746e..9fd74761 100644 --- a/core-doc.c +++ b/core-doc.c @@ -138,6 +138,33 @@ void doc_init(struct doc *d) DEF_CMD(doc_handle) { struct doc *d = ci->home->data; + + /* 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, d); + struct pane *c = pane_child(ci->home); + + if (c) + pane_clone(c, p); + return 1; + } + + if (strcmp(ci->key, "Close") == 0) { + if (ci->home->point) + point_free(ci->home->point); + return 1; + } return key_lookup(d->map, ci); } @@ -148,7 +175,10 @@ struct pane *doc_attach(struct pane *parent, struct doc *d) p = pane_register(parent, 0, &doc_handle, d, NULL); if (!d->home) d->home = p; + else + point_new(d, &p->point); d->ed = pane2ed(parent); + doc_promote(d); return p; } @@ -200,7 +230,10 @@ struct pane *doc_open(struct editor *ed, int fd, char *name) struct pane *doc_attach_view(struct pane *parent, struct pane *doc, char *render) { - struct pane *p = pane_attach(parent, "view", doc, NULL); + struct pane *p; + p = doc_attach(parent, doc->data); + if (p) + p = pane_attach(p, "view", doc, NULL); if (p) p = render_attach(render, p); return p; diff --git a/core-pane.c b/core-pane.c index 12716bab..469c6856 100644 --- a/core-pane.c +++ b/core-pane.c @@ -54,6 +54,21 @@ void pane_init(struct pane *p, struct pane *par, struct list_head *here) p->attrs = 0; } +static void __pane_check(struct pane *p) +{ + struct pane *c; + list_for_each_entry(c, &p->children, siblings) { + ASSERT(c->parent == p); + __pane_check(c); + } +} + +void pane_check(struct pane *p) +{ + while (p->parent) + p = p->parent; + __pane_check(p); +} /* * pane_damaged: mark a pane as being 'damaged', and make * sure all parents know about it. @@ -132,6 +147,7 @@ void pane_refresh(struct pane *p) void pane_close(struct pane *p) { struct pane *c; + pane_check(p); while (!list_empty(&p->children)) { c = list_first_entry(&p->children, struct pane, siblings); diff --git a/lib-view.c b/lib-view.c index fb5efabd..7f689fdd 100644 --- a/lib-view.c +++ b/lib-view.c @@ -36,7 +36,7 @@ enum { }; static struct map *view_map; -static struct pane *do_view_attach(struct pane *par, struct pane *dp, int border); +static struct pane *do_view_attach(struct pane *par, int border); static int view_refresh(struct cmd_info *ci) { @@ -131,11 +131,6 @@ DEF_CMD(view_handle) ret = key_lookup(view_map, ci); if (ret) return ret; - if (p->point->doc->map) { - ret = key_lookup(p->point->doc->map, ci); - if (ret) - return ret; - } if (vd->pane != p) vd->pane = p; /* FIXME having to do this is horrible */ @@ -143,16 +138,14 @@ DEF_CMD(view_handle) if (strcmp(ci->key, "Close") == 0) { pt = *ci->pointp; doc_del_view(pt->doc, &vd->ch_notify); - point_free(pt); free(vd); return 1; } if (strcmp(ci->key, "Clone") == 0) { struct pane *parent = ci->focus; struct pane *p2, *c; - if (!p->point) - return 0; - p2 = do_view_attach(parent, p->point->doc->home, vd->border); + + p2 = do_view_attach(parent, vd->border); c = pane_child(pane_child(p)); if (c) return pane_clone(c, pane_final_child(p2)); @@ -194,7 +187,7 @@ DEF_CMD(view_null) return 0; } -static struct pane *view_reattach(struct pane *p, struct pane *dp); +static struct pane *view_reattach(struct pane *p); DEF_CMD(view_notify) { @@ -205,46 +198,29 @@ DEF_CMD(view_notify) return 0; } if (strcmp(ci->key, "Release") == 0) { - /* release attached document and attach something else. - * there must always be another document somewhere. - */ - struct doc *d = vd->pane->point->doc; - struct editor *ed = d->ed; - struct pane *p, *c, *dp; - - doc_del_view(d, &vd->ch_notify); - c = pane_child(vd->pane); - if (c) - pane_close(c); - point_free(vd->pane->point); - dp = editor_choose_doc(ed); - p = view_reattach(vd->pane, dp); - render_attach(NULL, p); + pane_close(vd->pane); + return 1; } return 0; } -static struct pane *view_reattach(struct pane *par, struct pane *dp) +static struct pane *view_reattach(struct pane *par) { struct view_data *vd = par->data; struct pane *p; + struct point **ptp = pane_point(par); - - point_new(dp->data, &par->point); - vd->ch_notify_num = doc_add_view(dp->data, &vd->ch_notify); + vd->ch_notify_num = doc_add_view((*ptp)->doc, &vd->ch_notify); p = pane_register(par, 0, &view_null, vd, NULL); pane_damaged(p, DAMAGED_SIZE); return p; } -static struct pane *do_view_attach(struct pane *par, struct pane *dp, int border) +static struct pane *do_view_attach(struct pane *par, int border) { struct view_data *vd; struct pane *p; - struct doc *d = dp->data; - - doc_promote(d); vd = malloc(sizeof(*vd)); vd->border = border; @@ -253,7 +229,7 @@ static struct pane *do_view_attach(struct pane *par, struct pane *dp, int border vd->pane = p; pane_check_size(p); - view_reattach(p, dp); + view_reattach(p); return p; } @@ -268,7 +244,7 @@ DEF_CMD(view_attach) if (strchr(borderstr, 'L')) borders |= BORDER_LEFT; if (strchr(borderstr, 'R')) borders |= BORDER_RIGHT; - ci->focus = do_view_attach(ci->focus, ci->home, borders); + ci->focus = do_view_attach(ci->focus, borders); return ci->focus != NULL; } -- 2.39.5