2 * Copyright Neil Brown ©2015-2023 <neil@brown.name>
3 * May be distributed under terms of GPLv2 - see file:COPYING
5 * Keymap management panes for edlib.
7 * A keymap pane makes it easy to attach keymaps into a pane tree.
9 * is given a command which is used to as all incoming requests.
14 #define PANE_DATA_TYPE struct key_data
18 struct command *globalcmd;
20 #include "core-pane.h"
22 static struct pane *safe do_keymap_attach(struct pane *p safe);
24 DEF_CMD_CLOSED(keymap_handle)
26 struct key_data *kd = ci->home->data;
28 if (strcmp(ci->key, "Close") == 0) {
29 command_put(kd->globalcmd);
32 if (ci->home->damaged & DAMAGED_CLOSED)
35 if (strcmp(ci->key, "Clone") == 0) {
36 struct pane *p = do_keymap_attach(ci->focus);
37 struct key_data *kd_old = ci->home->data;
38 struct key_data *kd_new;
42 if (kd_old->globalcmd)
43 kd_new->globalcmd = command_get(kd_old->globalcmd);
45 pane_clone_children(ci->home, p);
51 ((struct cmd_info*)ci)->comm = kd->globalcmd;
52 ret = kd->globalcmd->func(ci);
56 if (strcmp(ci->key, "global-set-keymap") == 0) {
57 struct command *cm = ci->comm2;
60 command_put(kd->globalcmd);
61 kd->globalcmd = command_get(cm);
68 static struct pane *safe do_keymap_attach(struct pane *p safe)
70 return pane_register(p, 0, &keymap_handle);
73 DEF_CMD(keymap_attach)
75 struct pane *p = do_keymap_attach(ci->focus);
77 return comm_call(ci->comm2, "callback:attach", p);
81 void edlib_init(struct pane *ed safe)
83 call_comm("global-set-command", ed, &keymap_attach, 0, NULL,
84 "attach-global-keymap");