]> git.neil.brown.name Git - edlib.git/commitdiff
popup: replace the "quote" mechanism with something more direct.
authorNeilBrown <neil@brown.name>
Sun, 3 Apr 2016 10:02:09 +0000 (20:02 +1000)
committerNeilBrown <neil@brown.name>
Sun, 3 Apr 2016 10:40:51 +0000 (20:40 +1000)
Add a leaf pane that directly handles the commands that we need handled
at the leaf.

Signed-off-by: NeilBrown <neil@brown.name>
lib-popup.c
render-complete.c

index 9e2bca7437c7216245a35e14d6d2fdff0739b275..977746536daa20f33ac0e2149fb818472b849a73 100644 (file)
@@ -110,7 +110,20 @@ DEF_CMD(popup_handle)
                popup_resize(p, ppi->style);
                return 1;
        }
-       if (strcmp(ci->key, "popup:Abort") == 0) {
+       if (strcmp(ci->key, "popup:get-target") == 0)
+               return comm_call(ci->comm2, "callback:get-target",
+                                ppi->target, 0, NULL, NULL, 0);
+
+       return 0;
+}
+
+DEF_CMD(popup_leaf)
+{
+       struct pane *p = ci->home;
+       struct popup_info *ppi = p->data;
+       struct pane *d;
+
+       if (strcmp(ci->key, "Abort") == 0) {
                pane_focus(ppi->target);
                ppi->closing = 1;
                call3("Abort", ppi->target, 0, NULL);
@@ -121,7 +134,7 @@ DEF_CMD(popup_handle)
                pane_close(ppi->popup);
                return 1;
        }
-       if (strcmp(ci->key, "popup:Return") == 0) {
+       if (strcmp(ci->key, "Return") == 0) {
                struct cmd_info ci2 = {0};
 
                ppi->closing = 1;
@@ -145,28 +158,9 @@ DEF_CMD(popup_handle)
                pane_close(ppi->popup);
                return 1;
        }
-       if (strcmp(ci->key, "popup:get-target") == 0)
-               return comm_call(ci->comm2, "callback:get-target",
-                                ppi->target, 0, NULL, NULL, 0);
-
        return 0;
 }
 
-DEF_CMD(popup_quote)
-{
-       struct cmd_info ci2 = {0};
-
-       if (strcmp(ci->key, "Return") == 0)
-               ci2.key = "popup:Return";
-       else
-               ci2.key = "popup:Abort";
-       ci2.focus = ci->focus;
-       ci2.numeric = ci->numeric;
-       ci2.extra = ci->extra;
-       ci2.mark = ci->mark;
-       return key_handle(&ci2);
-}
-
 DEF_CMD(popup_attach)
 {
        /* attach a popup.  It can be attach to the view or the display,
@@ -183,7 +177,6 @@ DEF_CMD(popup_attach)
        struct popup_info *ppi = malloc(sizeof(*ppi));
        char *style = ci->str;
        char border[4];
-       struct cmd_info ci2={0};
        int i, j;
        int z = 1;
 
@@ -239,18 +232,9 @@ DEF_CMD(popup_attach)
                ppi->doc = d;
                p = doc_attach_view(ppi->popup, d, NULL);
        }
+       p = pane_register(pane_final_child(p), 0, &popup_leaf, ppi, NULL);
        pane_focus(p);
 
-       ci2.key = "local-set-key";
-       ci2.focus = p;
-       ci2.str = "popup:quote";
-       ci2.str2 = "Return";
-       key_handle(&ci2);
-       ci2.focus = pane_final_child(p);
-       ci2.home = NULL; ci2.comm = NULL;
-       ci2.str2 = "Abort";
-       key_handle(&ci2);
-
        return comm_call(ci->comm2, "callback:attach", ppi->popup, 0, NULL, NULL, 0);
 }
 
@@ -258,6 +242,4 @@ void edlib_init(struct pane *ed)
 {
        call_comm("global-set-command", ed, 0, NULL, "attach-popup",
                  0, &popup_attach);
-       call_comm("global-set-command", ed, 0, NULL, "popup:quote",
-                 0, &popup_quote);
 }
index 3334dac3e5a4fb568fa894a32f8da4213040832f..23133925e41f9a3045b07af7bbba86a078bc8ad7 100644 (file)
@@ -396,7 +396,7 @@ static void register_map(void)
        key_add_range(rc_map, "Move-", "Move-\377", &complete_nomove);
        key_add(rc_map, "Move-EOL", &complete_eol);
 
-       key_add(rc_map, "popup:Return", &complete_return);
+       key_add(rc_map, "Return", &complete_return);
 
        key_add(rc_map, "Complete:prefix", &complete_set_prefix);
 }