]> git.neil.brown.name Git - edlib.git/commitdiff
Change doc_destroy to take a pane.
authorNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 00:45:35 +0000 (11:45 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 02:54:09 +0000 (13:54 +1100)
This starts to reduce the number of doc_from_pane() callers.

Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core.h
doc-dir.c
lib-popup.c
mode-emacs.c

index 63c780d44389c035d401c461e80bbb058d0cdc06..1d54537621416c4f33177896b5c76373b350ff4c 100644 (file)
@@ -32,6 +32,8 @@ struct doc_ref {
 
 #include "core.h"
 
+static int do_doc_destroy(struct doc *d);
+
 static int do_doc_add_view(struct doc *d, struct command *c, int size)
 {
        struct docview *g;
@@ -446,6 +448,8 @@ DEF_CMD(doc_handle)
                return comm_call7(ci->comm2, "callback:vmark", ci->focus,
                                  0, m, NULL, 0, NULL, m2);
        }
+       if (strcmp(ci->key, "doc:destroy") == 0)
+               return do_doc_destroy(dd->doc);
 
        ret = key_lookup(dd->doc->map, ci);
        ret = ret ?: key_lookup(doc_default_cmd, ci);
@@ -593,7 +597,7 @@ struct pane *doc_from_text(struct pane *parent, char *name, char *text)
        doc_set_name(d, name);
        p = doc_attach_view(parent, d->home, NULL);
        if (!p) {
-               doc_destroy(d);
+               do_doc_destroy(d);
                return p;
        }
        doc_replace(p, NULL, text, &first);
@@ -847,9 +851,7 @@ DEF_CMD(docs_open)
 
 DEF_CMD(docs_bury)
 {
-       struct doc *d = doc_from_pane(ci->home);
-
-       doc_destroy(d);
+       doc_destroy(ci->home);
        return 1;
 }
 
@@ -926,12 +928,13 @@ void doc_promote(struct doc *d)
        docs_attach(d);
 }
 
-int  doc_destroy(struct doc *d)
+static int do_doc_destroy(struct doc *d)
 {
        /* If there are no views on the document, then unlink from
         * the documents list and destroy it.
         */
        int i;
+       struct cmd_info ci = {0};
 
        d->deleting = 1;
        if (d == d->ed->docs)
@@ -943,13 +946,16 @@ int  doc_destroy(struct doc *d)
        for (i = 0; i < d->nviews; i++)
                if (d->views[i].notify)
                        /* still in use */
-                       return 0;
+                       return -1;
        if (d == d->ed->docs)
-               return 0;
+               return -1;
 
        docs_release(d);
 
-       call3("doc:destroy", d->home, 0, 0);
+       ci.home = ci.focus = d->home;
+       ci.key = "doc:destroy";
+       key_lookup(d->map, &ci);
+
        pane_close(d->home);
 
        free(d->views);
@@ -966,3 +972,8 @@ int  doc_destroy(struct doc *d)
        free(d);
        return 1;
 }
+
+int doc_destroy(struct pane *p)
+{
+       return call3("doc:destroy", p, 0, 0);
+}
diff --git a/core.h b/core.h
index 382251cc002ae8254feb91a55a6dd8359523843c..d4ebf74db8c07905dd494ec66d8a6b9a0a4e872b 100644 (file)
--- a/core.h
+++ b/core.h
@@ -109,7 +109,7 @@ struct pane *doc_attach(struct pane *parent, struct doc *d);
 void doc_set_name(struct doc *d, char *name);
 struct pane *doc_find(struct editor *ed, char *name);
 void doc_promote(struct doc *d);
-int  doc_destroy(struct doc *d);
+int  doc_destroy(struct pane *p);
 
 struct pane *render_attach(char *name, struct pane *parent);
 
index 9bea6ec3f361434e39bfdef8b343e8d5e687d83d..a61ce86e387b96bfa19d1fa22ab60cacc24d14e3 100644 (file)
--- a/doc-dir.c
+++ b/doc-dir.c
@@ -549,9 +549,7 @@ DEF_CMD(dir_reread)
 
 DEF_CMD(dir_close)
 {
-       struct doc *d = doc_from_pane(ci->home);
-
-       doc_destroy(d);
+       doc_destroy(ci->home);
        return 1;
 }
 
index 83e85785bb64443bff9eb4560febf8ced7acb397..53914e65d7e325f6179395ab6116b54f9d6eb216 100644 (file)
@@ -63,8 +63,6 @@ DEF_CMD(popup_handle)
        struct popup_info *ppi = p->data;
 
        if (strcmp(ci->key, "Close") == 0) {
-               if (ppi->doc)
-                       doc_destroy(ppi->doc);
                free(ppi);
                return 1;
        }
@@ -76,6 +74,11 @@ DEF_CMD(popup_handle)
        if (strcmp(ci->key, "popup:Abort") == 0) {
                pane_focus(ppi->target);
                call3("Abort", ppi->target, 0, NULL);
+               if (ppi->doc) {
+                       /* FIXME make this doc auto-close */
+                       ppi->doc = NULL;
+                       doc_destroy(ci->focus);
+               }
                pane_close(ppi->popup);
                return 1;
        }
@@ -95,6 +98,11 @@ DEF_CMD(popup_handle)
                key_handle_focus(&ci2);
                if (ppi->doc)
                        free(ci2.str);
+               if (ppi->doc) {
+                       /* FIXME make this doc auto-close */
+                       ppi->doc = NULL;
+                       doc_destroy(ci->focus);
+               }
                pane_close(ppi->popup);
                return 1;
        }
index 1ff65581842597f0cea5065945796dc52e092f20..4479d48047ed6663187b3912f317e7ccf8287e19 100644 (file)
@@ -531,10 +531,7 @@ DEF_CMD(emacs_num)
 
 DEF_CMD(emacs_kill_doc)
 {
-       struct doc *d = doc_from_pane(ci->home);
-
-       if (d)
-               doc_destroy(d);
+       doc_destroy(ci->home);
        return 1;
 }