]> git.neil.brown.name Git - edlib.git/commitdiff
Use callbacks to return pane from "doc-*"
authorNeilBrown <neil@brown.name>
Wed, 9 Dec 2015 23:41:39 +0000 (10:41 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 02:54:09 +0000 (13:54 +1100)
Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
doc-dir.c
doc-text.c

index cead79a8781ae71a1b9f8bd3847453c3271cb0a2..e4945f8b07f3e44e9feeef12e51f8c9d85b90814 100644 (file)
@@ -501,10 +501,18 @@ struct pane *doc_attach(struct pane *parent, struct doc *d)
        return p;
 }
 
+DEF_CMD(take_pane)
+{
+       struct call_return *cr = container_of(ci->comm, struct call_return, c);
+       cr->p = ci->focus;
+       return 1;
+}
+
 struct doc *doc_new(struct editor *ed, char *type)
 {
        char buf[100];
        struct cmd_info ci = {0};
+       struct call_return cr;
        struct doc_data *dd;
 
        init_doc_defaults();
@@ -512,12 +520,15 @@ struct doc *doc_new(struct editor *ed, char *type)
        sprintf(buf, "doc-%s", type);
        ci.key = buf;
        ci.focus = ci.home = &ed->root;
+       cr.c = take_pane;
+       cr.p = NULL;
+       ci.comm2 = &cr.c;
        if (!key_lookup(ed->commands, &ci)) {
                editor_load_module(ed, buf);
                if (!key_lookup(ed->commands, &ci))
                        return NULL;
        }
-       dd = ci.focus->data;
+       dd = cr.p->data;
        return dd->doc;
 }
 
index 25752a0c739456c30bbadd98f7a456cec9151c86..9bea6ec3f361434e39bfdef8b343e8d5e687d83d 100644 (file)
--- a/doc-dir.c
+++ b/doc-dir.c
@@ -119,13 +119,16 @@ DEF_CMD(dir_new)
 {
        struct directory *dr = malloc(sizeof(*dr));
        struct editor *ed = pane2ed(ci->focus);
+       struct pane *p;
 
        doc_init(&dr->doc);
        dr->doc.map = doc_map;
        INIT_LIST_HEAD(&dr->ents);
        dr->fname = NULL;
-       ci->focus = doc_attach(ed->root.focus, &dr->doc);
-       return 1;
+       p = doc_attach(ed->root.focus, &dr->doc);
+       if (p)
+               return comm_call(ci->comm2, "callback:doc", p, 0, NULL, NULL, 0);
+       return -1;
 }
 
 DEF_CMD(dir_load_file)
index 3b3db46f7aa7198b908731c4e0e71b490051f437..e9cf3c75556c15063fcfa3e7a40af9b7b697aeeb 100644 (file)
@@ -1054,6 +1054,7 @@ DEF_CMD(text_new)
 {
        struct text *t = malloc(sizeof(*t));
        struct editor *ed = pane2ed(ci->focus);
+       struct pane *p;
 
        t->alloc = NULL;
        INIT_LIST_HEAD(&t->text);
@@ -1062,8 +1063,10 @@ DEF_CMD(text_new)
        t->doc.map = text_map;
        t->fname = NULL;
        text_new_alloc(t, 0);
-       ci->focus = doc_attach(ed->root.focus, &t->doc);
-       return 1;
+       p = doc_attach(ed->root.focus, &t->doc);
+       if (p)
+               return comm_call(ci->comm2, "callback:doc", p, 0, NULL, NULL, 0);
+       return -1;
 }
 
 static int count_bytes(struct text *t, struct mark *from, struct mark *to)